Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ 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
--ignore [patterns...] Specify which input files to ignore using glob syntax
-o, --output <path> Specify the relative or absolute output directory
-v, --version <semver> Specify the target version of Node.js, semver compliant (default: "v22.6.0")
-c, --changelog <url> Specify the path (file: or https://) to the CHANGELOG.md file (default: "https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md")
-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")
-v, --version <semver> Specify the target version of Node.js, semver compliant (default: "v22.11.0")
-c, --changelog <url> Specify the path (file: or https://) to the CHANGELOG.md file (default:
"https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md")
-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")
--disable-rule [rule...] Disable a specific linter rule (choices: "invalid-change-version",
"missing-change-version", "missing-introduced-in", default: [])
--lint-dry-run Run linter in dry-run mode (default: false)
--use-git Run git commands when needed (default: false)
-r, --reporter [reporter] Specify the linter reporter (choices: "console", "github", default: "console")
-h, --help display help for command
```
10 changes: 10 additions & 0 deletions bin/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ program
.addOption(
new Option('--lint-dry-run', 'Run linter in dry-run mode').default(false)
)
.addOption(
new Option('--use-git', 'Run git commands when needed').default(false)
)
.addOption(
new Option('-r, --reporter [reporter]', 'Specify the linter reporter')
.choices(Object.keys(reporters))
Expand All @@ -85,6 +88,7 @@ program
* @property {string} changelog Specifies the path to the Node.js CHANGELOG.md file.
* @property {string[]} disableRule Specifies the linter rules to disable.
* @property {boolean} lintDryRun Specifies whether the linter should run in dry-run mode.
* @property {boolean} useGit Specifies whether the parser should execute optional git commands. (Should only be used within a git repo)
* @property {keyof reporters} reporter Specifies the linter reporter.
*
* @name ProgramOptions
Expand All @@ -100,6 +104,7 @@ const {
changelog,
disableRule,
lintDryRun,
useGit,
reporter,
} = program.opts();

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

// Runs the Linter on the parsed API docs
linter.lintAll(parsedApiDocs);

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

// Reports Lint Content
linter.report(reporter);

exit(Number(linter.hasError()));
3 changes: 3 additions & 0 deletions src/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const DOC_NODE_VERSION = process.version;
export const DOC_NODE_CHANGELOG_URL =
'https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md';

// The base URL for the Node.js runtime GitHub repository
export const DOC_NODE_REPO_URL = 'https://github.com/nodejs/node';

// This is the Node.js Base URL for viewing a file within GitHub UI
export const DOC_NODE_BLOB_BASE_URL =
'https://github.com/nodejs/node/blob/HEAD/';
Expand Down
10 changes: 4 additions & 6 deletions src/generators.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const availableGenerators = {
};

/**
* @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
* @typedef {import('./generators/types.d.ts').AvailableGenerators & AstGenerator} AllGenerators A complete set of the available generators, including the AST one
* @typedef {{ ast: GeneratorMetadata<ApiDocMetadataEntry, ApiDocMetadataEntry>}} AstGenerator The AST "generator" is a facade for the AST tree and it isn't really a generator
* @typedef {AvailableGenerators & AstGenerator} AllGenerators A complete set of the available generators, including the AST one
* @param markdownInput
* @param jsInput
*
Expand All @@ -41,14 +41,12 @@ const createGenerator = markdownInput => {
*
* @type {{ [K in keyof AllGenerators]: ReturnType<AllGenerators[K]['generate']> }}
*/
const cachedGenerators = {
ast: Promise.resolve(markdownInput),
};
const cachedGenerators = { ast: Promise.resolve(markdownInput) };

/**
* Runs the Generator engine with the provided top-level input and the given generator options
*
* @param {import('./generators/types.d.ts').GeneratorOptions} options The options for the generator runtime
* @param {GeneratorOptions} options The options for the generator runtime
*/
const runGenerators = async ({ generators, ...extra }) => {
// Note that this method is blocking, and will only execute one generator per-time
Expand Down
2 changes: 1 addition & 1 deletion src/generators/addon-verify/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
*
* @typedef {Array<ApiDocMetadataEntry>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
* @type {GeneratorMetadata<Input, string>}
*/
export default {
name: 'addon-verify',
Expand Down
11 changes: 7 additions & 4 deletions src/generators/api-links/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { extractExports } from './utils/extractExports.mjs';
import { findDefinitions } from './utils/findDefinitions.mjs';
import { checkIndirectReferences } from './utils/checkIndirectReferences.mjs';
import { DOC_NODE_REPO_URL } from '../../constants.mjs';

/**
* This generator is responsible for mapping publicly accessible functions in
Expand All @@ -20,7 +21,7 @@ import { checkIndirectReferences } from './utils/checkIndirectReferences.mjs';
*
* @typedef {Array<JsProgram>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, Record<string, string>>}
* @type {GeneratorMetadata<Input, Record<string, string>>}
*/
export default {
name: 'api-links',
Expand All @@ -40,7 +41,7 @@ export default {
* @param {Input} input
* @param {Partial<GeneratorOptions>} options
*/
async generate(input, { output }) {
async generate(input, { output, useGit }) {
/**
* @type Record<string, string>
*/
Expand All @@ -54,9 +55,11 @@ export default {
if (input.length > 0) {
const repositoryDirectory = dirname(input[0].path);

const repository = getBaseGitHubUrl(repositoryDirectory);
const repository = useGit
? getBaseGitHubUrl(repositoryDirectory)
Comment thread
ovflowd marked this conversation as resolved.
Outdated
: DOC_NODE_REPO_URL;

const tag = getCurrentGitHash(repositoryDirectory);
const tag = useGit ? getCurrentGitHash(repositoryDirectory) : 'HEAD';

baseGithubLink = `${repository}/blob/${tag}`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/generators/ast-js/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import createJsParser from '../../parsers/javascript.mjs';
*
* @typedef {unknown} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, Array<JsProgram>>}
* @type {GeneratorMetadata<Input, Array<JsProgram>>}
*/
export default {
name: 'ast-js',
Expand Down
2 changes: 1 addition & 1 deletion src/generators/json-simple/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getRemark } from '../../utils/remark.mjs';
*
* @typedef {Array<ApiDocMetadataEntry>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
* @type {GeneratorMetadata<Input, string>}
*/
export default {
name: 'json-simple',
Expand Down
2 changes: 1 addition & 1 deletion src/generators/legacy-html-all/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { getRemarkRehype } from '../../utils/remark.mjs';
*
* @typedef {Array<TemplateValues>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
* @type {GeneratorMetadata<Input, string>}
*/
export default {
name: 'legacy-html-all',
Expand Down
2 changes: 1 addition & 1 deletion src/generators/legacy-html/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { getRemarkRehype } from '../../utils/remark.mjs';
*
* @typedef {Array<ApiDocMetadataEntry>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, Array<TemplateValues>>}
* @type {GeneratorMetadata<Input, Array<TemplateValues>>}
*/
export default {
name: 'legacy-html',
Expand Down
2 changes: 1 addition & 1 deletion src/generators/legacy-json-all/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { join } from 'node:path';
*
* @typedef {Array<import('../legacy-json/types.d.ts').Section>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, import('./types.d.ts').Output>}
* @type {GeneratorMetadata<Input, import('./types.d.ts').Output>}
*/
export default {
name: 'legacy-json-all',
Expand Down
2 changes: 1 addition & 1 deletion src/generators/legacy-json/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { createSectionBuilder } from './utils/buildSection.mjs';
*
* @typedef {Array<ApiDocMetadataEntry>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, import('./types.d.ts').Section[]>}
* @type {GeneratorMetadata<Input, import('./types.d.ts').Section[]>}
*/
export default {
name: 'legacy-json',
Expand Down
2 changes: 1 addition & 1 deletion src/generators/man-page/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { DOC_SLUG_ENVIRONMENT, DOC_SLUG_OPTIONS } from '../../constants.mjs';
*
* @typedef {Array<ApiDocMetadataEntry>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
* @type {GeneratorMetadata<Input, string>}
*/
export default {
name: 'man-page',
Expand Down
2 changes: 1 addition & 1 deletion src/generators/orama-db/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createSectionBuilder } from '../legacy-json/utils/buildSection.mjs';
*
* @typedef {Array<ApiDocMetadataEntry>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, import('./types.d.ts').OramaDb>}
* @type {GeneratorMetadata<Input, import('./types.d.ts').OramaDb>}
*/
export default {
name: 'orama-db',
Expand Down
3 changes: 3 additions & 0 deletions src/generators/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ declare global {

// A list of all Node.js major versions and their respective release information
releases: Array<ApiDocReleaseEntry>;

// Wether to use `git` commands while running the generator
useGit: boolean;
}

export interface GeneratorMetadata<I extends any, O extends any> {
Expand Down
Loading