From 30a768b3a6a802bf2cc1cf3ef5f6e233a81058b1 Mon Sep 17 00:00:00 2001 From: flakey5 <73616808+flakey5@users.noreply.github.com> Date: Mon, 10 Mar 2025 14:36:54 -0700 Subject: [PATCH] feat: --ignore flag Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com> --- README.md | 1 + bin/cli.mjs | 9 ++++++++- src/loaders/markdown.mjs | 10 ++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 73b7afb0..9ad61e41 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ CLI tool to generate API documentation of a Node.js project. Options: -i, --input [patterns...] Specify input file patterns using glob syntax + --ignore [patterns...] Specify files to be ignored from the input using glob syntax -o, --output Specify the relative or absolute output directory -v, --version Specify the target version of Node.js, semver compliant (default: "v22.6.0") -c, --changelog Specify the path (file: or https://) to the CHANGELOG.md file (default: "https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md") diff --git a/bin/cli.mjs b/bin/cli.mjs index d5239df5..84a7a33d 100755 --- a/bin/cli.mjs +++ b/bin/cli.mjs @@ -29,6 +29,12 @@ program 'Specify input file patterns using glob syntax' ).makeOptionMandatory() ) + .addOption( + new Option( + '--ignore [patterns...]', + 'Specify which input files to ignore using glob syntax' + ) + ) .addOption( new Option( '-o, --output ', @@ -87,6 +93,7 @@ program */ const { input, + ignore, output, target = [], version, @@ -101,7 +108,7 @@ const linter = createLinter(lintDryRun, disableRule); const { loadFiles } = createMarkdownLoader(); const { parseApiDocs } = createMarkdownParser(); -const apiDocFiles = loadFiles(input); +const apiDocFiles = loadFiles(input, ignore); const parsedApiDocs = await parseApiDocs(apiDocFiles); diff --git a/src/loaders/markdown.mjs b/src/loaders/markdown.mjs index 12715e02..ba7df02d 100644 --- a/src/loaders/markdown.mjs +++ b/src/loaders/markdown.mjs @@ -16,14 +16,20 @@ const createLoader = () => { * Loads API Doc files and transforms it into VFiles * * @param {string} searchPath A glob/path for API docs to be loaded + * @param {string | undefined} ignorePath A glob/path of files to ignore * The input string can be a simple path (relative or absolute) * The input string can also be any allowed glob string * * @see https://code.visualstudio.com/docs/editor/glob-patterns */ - const loadFiles = searchPath => { + const loadFiles = (searchPath, ignorePath) => { + const ignoredFiles = ignorePath + ? globSync(ignorePath).filter(filePath => extname(filePath) === '.md') + : []; + const resolvedFiles = globSync(searchPath).filter( - filePath => extname(filePath) === '.md' + filePath => + extname(filePath) === '.md' && !ignoredFiles.includes(filePath) ); return resolvedFiles.map(async filePath => {