Skip to content

Commit 0d7ffaf

Browse files
committed
feat: use git only when requested
1 parent c6e8099 commit 0d7ffaf

File tree

15 files changed

+46
-23
lines changed

15 files changed

+46
-23
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ CLI tool to generate API documentation of a Node.js project.
3636

3737
Options:
3838
-i, --input [patterns...] Specify input file patterns using glob syntax
39-
--ignore [patterns...] Specify files to be ignored from the input using glob syntax
39+
--ignore [patterns...] Specify which input files to ignore using glob syntax
4040
-o, --output <path> Specify the relative or absolute output directory
41-
-v, --version <semver> Specify the target version of Node.js, semver compliant (default: "v22.6.0")
42-
-c, --changelog <url> Specify the path (file: or https://) to the CHANGELOG.md file (default: "https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md")
43-
-t, --target [mode...] Set the processing target modes (choices: "json-simple", "legacy-html", "legacy-html-all", "man-page", "legacy-json", "legacy-json-all", "addon-verify", "api-links", "orama-db")
41+
-v, --version <semver> Specify the target version of Node.js, semver compliant (default: "v22.11.0")
42+
-c, --changelog <url> Specify the path (file: or https://) to the CHANGELOG.md file (default:
43+
"https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md")
44+
-t, --target [mode...] Set the processing target modes (choices: "json-simple", "legacy-html", "legacy-html-all",
45+
"man-page", "legacy-json", "legacy-json-all", "addon-verify", "api-links", "orama-db")
46+
--disable-rule [rule...] Disable a specific linter rule (choices: "invalid-change-version",
47+
"missing-change-version", "missing-introduced-in", default: [])
48+
--lint-dry-run Run linter in dry-run mode (default: false)
49+
-r, --reporter [reporter] Specify the linter reporter (choices: "console", "github", default: "console")
4450
-h, --help display help for command
4551
```

bin/cli.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ program
6767
.addOption(
6868
new Option('--lint-dry-run', 'Run linter in dry-run mode').default(false)
6969
)
70+
.addOption(
71+
new Option('--use-git', 'Run git commands when needed').default(false)
72+
)
7073
.addOption(
7174
new Option('-r, --reporter [reporter]', 'Specify the linter reporter')
7275
.choices(Object.keys(reporters))
@@ -85,6 +88,7 @@ program
8588
* @property {string} changelog Specifies the path to the Node.js CHANGELOG.md file.
8689
* @property {string[]} disableRule Specifies the linter rules to disable.
8790
* @property {boolean} lintDryRun Specifies whether the linter should run in dry-run mode.
91+
* @property {boolean} useGit Specifies whether the parser should execute optional git commands. (Should only be used within a git repo)
8892
* @property {keyof reporters} reporter Specifies the linter reporter.
8993
*
9094
* @name ProgramOptions
@@ -100,6 +104,7 @@ const {
100104
changelog,
101105
disableRule,
102106
lintDryRun,
107+
useGit,
103108
reporter,
104109
} = program.opts();
105110

@@ -117,6 +122,7 @@ const { runGenerators } = createGenerator(parsedApiDocs);
117122
// Retrieves Node.js release metadata from a given Node.js version and CHANGELOG.md file
118123
const { getAllMajors } = createNodeReleases(changelog);
119124

125+
// Runs the Linter on the parsed API docs
120126
linter.lintAll(parsedApiDocs);
121127

122128
if (target && output) {
@@ -131,9 +137,13 @@ if (target && output) {
131137
version: coerce(version),
132138
// A list of all Node.js major versions with LTS status
133139
releases: await getAllMajors(),
140+
// If it should run git commands when needed
141+
// (should only be used within a git repo)
142+
useGit,
134143
});
135144
}
136145

146+
// Reports Lint Content
137147
linter.report(reporter);
138148

139149
exit(Number(linter.hasError()));

src/constants.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const DOC_NODE_VERSION = process.version;
77
export const DOC_NODE_CHANGELOG_URL =
88
'https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md';
99

10+
// The base URL for the Node.js runtime GitHub repository
11+
export const DOC_NODE_REPO_URL = 'https://github.com/nodejs/node';
12+
1013
// This is the Node.js Base URL for viewing a file within GitHub UI
1114
export const DOC_NODE_BLOB_BASE_URL =
1215
'https://github.com/nodejs/node/blob/HEAD/';

src/generators.mjs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const availableGenerators = {
1313
};
1414

1515
/**
16-
* @typedef {{ ast: import('./generators/types.d.ts').GeneratorMetadata<ApiDocMetadataEntry, ApiDocMetadataEntry>}} AstGenerator The AST "generator" is a facade for the AST tree and it isn't really a generator
17-
* @typedef {import('./generators/types.d.ts').AvailableGenerators & AstGenerator} AllGenerators A complete set of the available generators, including the AST one
16+
* @typedef {{ ast: GeneratorMetadata<ApiDocMetadataEntry, ApiDocMetadataEntry>}} AstGenerator The AST "generator" is a facade for the AST tree and it isn't really a generator
17+
* @typedef {AvailableGenerators & AstGenerator} AllGenerators A complete set of the available generators, including the AST one
1818
* @param markdownInput
1919
* @param jsInput
2020
*
@@ -41,14 +41,12 @@ const createGenerator = markdownInput => {
4141
*
4242
* @type {{ [K in keyof AllGenerators]: ReturnType<AllGenerators[K]['generate']> }}
4343
*/
44-
const cachedGenerators = {
45-
ast: Promise.resolve(markdownInput),
46-
};
44+
const cachedGenerators = { ast: Promise.resolve(markdownInput) };
4745

4846
/**
4947
* Runs the Generator engine with the provided top-level input and the given generator options
5048
*
51-
* @param {import('./generators/types.d.ts').GeneratorOptions} options The options for the generator runtime
49+
* @param {GeneratorOptions} options The options for the generator runtime
5250
*/
5351
const runGenerators = async ({ generators, ...extra }) => {
5452
// Note that this method is blocking, and will only execute one generator per-time

src/generators/addon-verify/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
*
2121
* @typedef {Array<ApiDocMetadataEntry>} Input
2222
*
23-
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
23+
* @type {GeneratorMetadata<Input, string>}
2424
*/
2525
export default {
2626
name: 'addon-verify',

src/generators/api-links/index.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { extractExports } from './utils/extractExports.mjs';
1010
import { findDefinitions } from './utils/findDefinitions.mjs';
1111
import { checkIndirectReferences } from './utils/checkIndirectReferences.mjs';
12+
import { DOC_NODE_REPO_URL } from '../../constants.mjs';
1213

1314
/**
1415
* This generator is responsible for mapping publicly accessible functions in
@@ -20,7 +21,7 @@ import { checkIndirectReferences } from './utils/checkIndirectReferences.mjs';
2021
*
2122
* @typedef {Array<JsProgram>} Input
2223
*
23-
* @type {import('../types.d.ts').GeneratorMetadata<Input, Record<string, string>>}
24+
* @type {GeneratorMetadata<Input, Record<string, string>>}
2425
*/
2526
export default {
2627
name: 'api-links',
@@ -40,7 +41,7 @@ export default {
4041
* @param {Input} input
4142
* @param {Partial<GeneratorOptions>} options
4243
*/
43-
async generate(input, { output }) {
44+
async generate(input, { output, useGit }) {
4445
/**
4546
* @type Record<string, string>
4647
*/
@@ -54,9 +55,11 @@ export default {
5455
if (input.length > 0) {
5556
const repositoryDirectory = dirname(input[0].path);
5657

57-
const repository = getBaseGitHubUrl(repositoryDirectory);
58+
const repository = useGit
59+
? getBaseGitHubUrl(repositoryDirectory)
60+
: DOC_NODE_REPO_URL;
5861

59-
const tag = getCurrentGitHash(repositoryDirectory);
62+
const tag = useGit ? getCurrentGitHash(repositoryDirectory) : 'HEAD';
6063

6164
baseGithubLink = `${repository}/blob/${tag}`;
6265
}

src/generators/ast-js/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import createJsParser from '../../parsers/javascript.mjs';
1111
*
1212
* @typedef {unknown} Input
1313
*
14-
* @type {import('../types.d.ts').GeneratorMetadata<Input, Array<JsProgram>>}
14+
* @type {GeneratorMetadata<Input, Array<JsProgram>>}
1515
*/
1616
export default {
1717
name: 'ast-js',

src/generators/json-simple/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getRemark } from '../../utils/remark.mjs';
1717
*
1818
* @typedef {Array<ApiDocMetadataEntry>} Input
1919
*
20-
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
20+
* @type {GeneratorMetadata<Input, string>}
2121
*/
2222
export default {
2323
name: 'json-simple',

src/generators/legacy-html-all/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { getRemarkRehype } from '../../utils/remark.mjs';
2929
*
3030
* @typedef {Array<TemplateValues>} Input
3131
*
32-
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
32+
* @type {GeneratorMetadata<Input, string>}
3333
*/
3434
export default {
3535
name: 'legacy-html-all',

src/generators/legacy-html/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { getRemarkRehype } from '../../utils/remark.mjs';
3131
*
3232
* @typedef {Array<ApiDocMetadataEntry>} Input
3333
*
34-
* @type {import('../types.d.ts').GeneratorMetadata<Input, Array<TemplateValues>>}
34+
* @type {GeneratorMetadata<Input, Array<TemplateValues>>}
3535
*/
3636
export default {
3737
name: 'legacy-html',

0 commit comments

Comments
 (0)