limit cli only to jpgs/pngs (by default)

This commit is contained in:
Tomáš Mládek 2021-09-18 11:42:44 +02:00
parent eb455e2311
commit e9bc9f568d

View file

@ -20,13 +20,17 @@ const args = parse(Deno.args, {
}); });
const files: string[] = []; const files: string[] = [];
const includeExtensions = Array.from(
String(args["include"] || "*.png, *.jpg").matchAll(/\*\.([\w]+)/g),
).map(([_, group]) => group);
args["_"].forEach((arg) => { args["_"].forEach((arg) => {
arg = arg.toString(); arg = arg.toString();
if (Deno.statSync(arg).isDirectory) { if (Deno.statSync(arg).isDirectory) {
Array.from(Deno.readDirSync(arg)).forEach((entry) => Array.from(Deno.readDirSync(arg)).filter((entry) =>
files.push(`${arg}/${entry.name}`) includeExtensions.length == 0 ||
); includeExtensions.some((ext) => entry.name.endsWith(ext))
).forEach((entry) => files.push(`${arg}/${entry.name}`));
} else { } else {
files.push(arg); files.push(arg);
} }