mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
fix: limit 2 level to only 5 children
This commit is contained in:
1 parent
34d5ace664
commit
f43fa1b5ef
3 files changed
+24
-22
No files matched your search
@@ -19,7 +19,6 @@ const commandListeners = {
|
|||||||
|
|
||||||
async function handleCommand(command) {
|
async function handleCommand(command) {
|
||||||
const argv = minimist(command.split(' '))
|
const argv = minimist(command.split(' '))
|
||||||
console.log(argv)
|
|
||||||
const name = argv._[0]
|
const name = argv._[0]
|
||||||
const listeners = commandListeners[name]
|
const listeners = commandListeners[name]
|
||||||
if (!listeners) return {}
|
if (!listeners) return {}
|
||||||
|
|||||||
@@ -5,30 +5,35 @@ async function collectFilesInfo(inputPath, level = 0) {
|
|||||||
const stats = await fs.stat(inputPath)
|
const stats = await fs.stat(inputPath)
|
||||||
const discovered = level === 0
|
const discovered = level === 0
|
||||||
const name = path.basename(inputPath)
|
const name = path.basename(inputPath)
|
||||||
const file = {
|
const files = [
|
||||||
path: inputPath,
|
{
|
||||||
name,
|
path: inputPath,
|
||||||
type: stats.isDirectory() ? 'folder' : 'file',
|
name,
|
||||||
discovered,
|
type: stats.isDirectory() ? 'folder' : 'file',
|
||||||
}
|
discovered,
|
||||||
if (stats.isFile()) {
|
},
|
||||||
return [file]
|
]
|
||||||
}
|
if (stats.isDirectory() && level < 2) {
|
||||||
if (stats.isDirectory()) {
|
try {
|
||||||
const entries = await fs.readdir(inputPath)
|
let entries = await fs.readdir(inputPath)
|
||||||
const result = await Promise.all(
|
if (level > 0) {
|
||||||
entries.map((entry) =>
|
entries = entries.slice(0, 5)
|
||||||
collectFilesInfo(path.join(inputPath, entry), level + 1)
|
}
|
||||||
|
const result = await Promise.all(
|
||||||
|
entries.map((entry) =>
|
||||||
|
collectFilesInfo(path.join(inputPath, entry), level + 1)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
files.push(...result.flat())
|
||||||
return [file, ...result.flat()]
|
} catch (err) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return []
|
return files
|
||||||
}
|
}
|
||||||
|
|
||||||
async function discoverFiles(argv) {
|
async function discoverFiles(argv) {
|
||||||
const targetPath = argv._.length < 2 ? ['.'] : argv._.slice(1)
|
const targetPath = argv._.length < 2 ? ['.'] : argv._.slice(1)
|
||||||
console.log(targetPath)
|
|
||||||
const result = await Promise.all(
|
const result = await Promise.all(
|
||||||
targetPath.map((p) => path.resolve(process.cwd(), p)).map(collectFilesInfo)
|
targetPath.map((p) => path.resolve(process.cwd(), p)).map(collectFilesInfo)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ precmd() {
|
|||||||
export CMD_ERROR_FILE=/tmp/cmd.error
|
export CMD_ERROR_FILE=/tmp/cmd.error
|
||||||
|
|
||||||
# Now run your Node.js script with the result as an argument
|
# Now run your Node.js script with the result as an argument
|
||||||
node /usr/local/lib/container/cli.js
|
node /usr/local/lib/container/cli.js; rm /tmp/cmd.out /tmp/cmd.error 2>/dev/null
|
||||||
|
|
||||||
rm /tmp/cmd.out /tmp/cmd.error 2>/dev/null # cleanup
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user