From dfdaa9cb8045e89a0c65339b24d55584a46a3f9d Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Thu, 19 Sep 2024 14:37:28 +0200 Subject: [PATCH 1/2] `dist` script: be more permissive with file extensions --- scripts/dist.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/dist.ts b/scripts/dist.ts index 2a01a0defed..2cfadbdde90 100644 --- a/scripts/dist.ts +++ b/scripts/dist.ts @@ -353,16 +353,35 @@ const tagsToFeatures: Map = (() => { return map; })(); +/** + * Check if a file is an authored definition or dist file. Throws on likely + * mistakes, such as `.yaml` files. + */ +function isDistOrDistable(path: string): boolean { + if (path.endsWith(".yaml.dist") || path.endsWith(".yaml")) { + throw new Error( + `YAML files must use .yml extension; ${path} has invalid extension`, + ); + } + if (path.endsWith(".yml.dist") || path.endsWith(".yml")) { + return true; + } + logger.debug(`${path} is not a likely YAML file, skipping`); + return false; +} + function main() { - const filePaths = argv.paths.flatMap((fileOrDirectory) => { + const filePaths: string[] = argv.paths.flatMap((fileOrDirectory) => { if (fs.statSync(fileOrDirectory).isDirectory()) { return new fdir() .withBasePath() - .filter((fp) => !(fp.endsWith(".md") || fp.endsWith(".DS_Store"))) + .filter(isDistOrDistable) .crawl(fileOrDirectory) .sync(); } - return fileOrDirectory; + if (isDistOrDistable(fileOrDirectory)) { + return fileOrDirectory; + } }); // Map from .yml to .yml.dist to filter out duplicates. From ff5cd6d1f6edcf272b1c4daef9e6977bb963114b Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Thu, 19 Sep 2024 14:54:22 +0200 Subject: [PATCH 2/2] Stop undefined values getting into the list of paths --- scripts/dist.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/dist.ts b/scripts/dist.ts index 2cfadbdde90..795b7811113 100644 --- a/scripts/dist.ts +++ b/scripts/dist.ts @@ -379,9 +379,7 @@ function main() { .crawl(fileOrDirectory) .sync(); } - if (isDistOrDistable(fileOrDirectory)) { - return fileOrDirectory; - } + return isDistOrDistable(fileOrDirectory) ? fileOrDirectory : []; }); // Map from .yml to .yml.dist to filter out duplicates.