@codenoobforreal/clitools
Version:
CLI tool for video processing (H.265/HEVC encoding & QuickTime compatibility) using FFmpeg, and batch lossless image compression with format preservation
34 lines • 1.16 kB
JavaScript
import { isPathDirectory } from "../libs/file-type.js";
import { collectFilesFromDirectory } from "./file-collector.js";
export async function getFilePathsFromPath(path, options) {
const isDirectory = await isPathDirectory(path);
const paths = [];
if (!isDirectory) {
paths.push(path);
}
else {
const filesInDirectory = await collectFilesFromDirectory(path, {
pattern: generateFilePattern(options.extensions),
validator: createFileValidator(options.validateFn),
});
paths.push(...filesInDirectory);
}
return paths;
}
function generateFilePattern(supportedExt) {
const extensions = supportedExt.flatMap((ext) => [ext, ext.toUpperCase()]);
return `**/*.{${extensions.join(",")}}`;
}
export function createFileValidator(validateFn) {
return async (filePath) => {
try {
const isValid = await validateFn(filePath);
return isValid ? filePath : "";
}
catch (error) {
console.error(`Failed to validate file: ${filePath}`, error);
return "";
}
};
}
//# sourceMappingURL=path-scaner.js.map