From 8ab3e5f54e8219e7e67dd8db28c9e0a776dbbb2c Mon Sep 17 00:00:00 2001 From: Geovanni Pacheco Date: Wed, 28 Feb 2024 18:18:30 -0300 Subject: [PATCH] Improve file validation --- scripts/validate.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/validate.ts b/scripts/validate.ts index 3267f21..c10f0c5 100644 --- a/scripts/validate.ts +++ b/scripts/validate.ts @@ -8,7 +8,7 @@ import { parse } from "@jupiterone/query-language-parser"; const logger = new Logger(); const validateExports = () => { - const files = readdirSync(resolve(cwd(), "rule-packs")); + const indexFiles = readdirSync(resolve(cwd(), "rule-packs")); const indexPath = resolve(cwd(), "rule-packs", "index.js"); @@ -18,11 +18,18 @@ const validateExports = () => { f.fileName.replace("./", "") ); - for (const file of files) { - if (file === "index.js" || importedFiles.includes(file)) { + for (const indexFile of indexFiles) { + if (indexFile === "index.js" || importedFiles.includes(indexFile)) { + continue; + } + throw new Error(`File ${indexFile} is not imported in index.js.`); + } + + for (const importedFile of importedFiles) { + if (indexFiles.includes(importedFile)) { continue; } - throw new Error(`File ${file} is not imported in index.js.`); + throw new Error(`File ${importedFile} does not exist`); } };