mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
allow passing entire directories as input
This commit is contained in:
@@ -183,31 +183,37 @@ function progressTracker(results) {
|
|||||||
return tracker;
|
return tracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkInputFilesValid(files) {
|
async function getInputFiles(paths) {
|
||||||
const validFiles = [];
|
const validFiles = [];
|
||||||
|
|
||||||
for (const file of files) {
|
for (const path of paths) {
|
||||||
try {
|
//allow paths ending in / of \ to get all files in that directory
|
||||||
await fsp.stat(file);
|
const files = path.endsWith('/') || path.endsWith('\\')
|
||||||
} catch (err) {
|
? await fs.readdir(paths)
|
||||||
if (err.code === 'ENOENT') {
|
: [path];
|
||||||
console.warn(
|
for (const file of files) {
|
||||||
`Warning: Input file does not exist: ${resolvePath(file)}`,
|
try {
|
||||||
);
|
await fsp.stat(file);
|
||||||
continue;
|
} catch (err) {
|
||||||
} else {
|
if (err.code === 'ENOENT') {
|
||||||
throw err;
|
console.warn(
|
||||||
|
`Warning: Input file does not exist: ${resolvePath(file)}`,
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
validFiles.push(file);
|
validFiles.push(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return validFiles;
|
return validFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processFiles(files) {
|
async function processFiles(files) {
|
||||||
files = await checkInputFilesValid(files);
|
files = await getInputFiles(files);
|
||||||
|
|
||||||
const parallelism = cpus().length;
|
const parallelism = cpus().length;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user