From 733b470f1f3bf7d1ab8b86316f5b05e53603e692 Mon Sep 17 00:00:00 2001 From: DetachHead Date: Sat, 26 Dec 2020 22:56:23 +1000 Subject: [PATCH] allow passing entire directories as input --- cli/src/index.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/cli/src/index.js b/cli/src/index.js index d7c97eda..ba1107ee 100644 --- a/cli/src/index.js +++ b/cli/src/index.js @@ -183,31 +183,37 @@ function progressTracker(results) { return tracker; } -async function checkInputFilesValid(files) { +async function getInputFiles(paths) { const validFiles = []; - for (const file of files) { - try { - await fsp.stat(file); - } catch (err) { - if (err.code === 'ENOENT') { - console.warn( - `Warning: Input file does not exist: ${resolvePath(file)}`, - ); - continue; - } else { - throw err; + for (const path of paths) { + //allow paths ending in / of \ to get all files in that directory + const files = path.endsWith('/') || path.endsWith('\\') + ? await fs.readdir(paths) + : [path]; + for (const file of files) { + try { + await fsp.stat(file); + } catch (err) { + if (err.code === 'ENOENT') { + console.warn( + `Warning: Input file does not exist: ${resolvePath(file)}`, + ); + continue; + } else { + throw err; + } } - } - validFiles.push(file); + validFiles.push(file); + } } return validFiles; } async function processFiles(files) { - files = await checkInputFilesValid(files); + files = await getInputFiles(files); const parallelism = cpus().length;