mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
refactor: move client to sperate packages, rename cli to container
This commit is contained in:
1 parent
41a12c9aa8
commit
6ace18475b
15 files changed
+51
-28
No files matched your search
@@ -0,0 +1,38 @@
|
||||
const fs = require('fs').promises
|
||||
const path = require('path')
|
||||
|
||||
async function collectFilesInfo(directoryPath, level = 0) {
|
||||
const entries = await fs.readdir(directoryPath, { withFileTypes: true })
|
||||
|
||||
const promises = entries.map(async (entry) => {
|
||||
const filePath = path.join(directoryPath, entry.name)
|
||||
const isDirectory = entry.isDirectory()
|
||||
const discovered = level === 0 && !entry.name.startsWith('.')
|
||||
|
||||
const file = {
|
||||
path: filePath,
|
||||
name: entry.name,
|
||||
type: isDirectory ? 'folder' : 'file',
|
||||
discovered,
|
||||
}
|
||||
|
||||
if (isDirectory && level < 2) {
|
||||
// Get up to two levels deep
|
||||
const subFilesInfo = await collectFilesInfo(filePath, level + 1)
|
||||
return [file, ...subFilesInfo]
|
||||
}
|
||||
|
||||
return file
|
||||
})
|
||||
|
||||
const results = await Promise.all(promises)
|
||||
return results.flat()
|
||||
}
|
||||
|
||||
async function discoverFiles(name, args) {
|
||||
let targetPath = args[0] || '.'
|
||||
targetPath = path.resolve(process.cwd(), targetPath)
|
||||
return { discover: await collectFilesInfo(targetPath) }
|
||||
}
|
||||
|
||||
module.exports = discoverFiles
|
||||
Reference in new issue
Block a user