Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ jobs:
-t ${{ matrix.target }} \
-i "${{ matrix.input }}" \
-o "out/${{ matrix.target }}" \
--index ./node/doc/api/index.md \
--skip-lint
--index ./node/doc/api/index.md

- name: Upload ${{ matrix.target }} artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
Expand Down
35 changes: 1 addition & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ $ npx doc-kit --help
```
Usage: @nodejs/doc-kit [options] [command]

CLI tool to generate and lint Node.js API documentation
CLI tool to generate the Node.js API documentation

Options:
-h, --help display help for command

Commands:
generate [options] Generate API docs
lint [options] Run linter independently
interactive Launch guided CLI wizard
list <types> List the given type
help [command] display help for command
```

Expand All @@ -67,23 +65,6 @@ Options:
-c, --changelog <url> Changelog URL or path (default: "https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md")
--git-ref <url> Git ref/commit URL (default: "https://github.com/nodejs/node/tree/HEAD")
-t, --target [modes...] Target generator modes (choices: "json-simple", "legacy-html", "legacy-html-all", "man-page", "legacy-json", "legacy-json-all", "addon-verify", "api-links", "orama-db", "llms-txt")
--no-lint Skip lint before generate
-h, --help display help for command
```

### `lint`

```
Usage: @nodejs/doc-kit lint [options]

Run linter independently

Options:
-i, --input <patterns...> Input file patterns (glob)
--ignore [patterns...] Ignore patterns (comma-separated)
--disable-rule [rules...] Disable linter rules (choices: "duplicate-stability-nodes", "invalid-change-version", "missing-introduced-in")
--dry-run Dry run mode (default: false)
-r, --reporter <reporter> Linter reporter to use
-h, --help display help for command
```

Expand All @@ -97,17 +78,3 @@ Launch guided CLI wizard
Options:
-h, --help display help for command
```

### `list`

```
Usage: @nodejs/doc-kit list [options] <types>

List the given type

Arguments:
types The type to list (choices: "generators", "rules", "reporters")

Options:
-h, --help display help for command
```
14 changes: 3 additions & 11 deletions bin/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import process from 'node:process';

import { Argument, Command, Option } from 'commander';
import { Command, Option } from 'commander';

import commands from './commands/index.mjs';
import interactive from './commands/interactive.mjs';
import list, { types } from './commands/list.mjs';
import { errorWrap } from './utils.mjs';

const program = new Command()
.name('@nodejs/doc-kit')
.description('CLI tool to generate and lint Node.js API documentation');
.description('CLI tool to generate the Node.js API documentation');

// Registering generate and lint commands
// Registering commands
commands.forEach(({ name, description, options, action }) => {
const cmd = program.command(name).description(description);

Expand Down Expand Up @@ -44,12 +43,5 @@ program
.description('Launch guided CLI wizard')
.action(errorWrap(interactive));

// Register the list command
program
.command('list')
.addArgument(new Argument('<types>', 'The type to list').choices(types))
.description('List the given type')
.action(errorWrap(list));

// Parse and execute command-line arguments
program.parse(process.argv);
25 changes: 1 addition & 24 deletions bin/commands/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
} from '../../src/constants.mjs';
import { publicGenerators } from '../../src/generators/index.mjs';
import createGenerator from '../../src/generators.mjs';
import createLinter from '../../src/linter/index.mjs';
import { getEnabledRules } from '../../src/linter/utils/rules.mjs';
import { parseChangelog, parseIndex } from '../../src/parsers/markdown.mjs';
import { loadAndParse } from '../utils.mjs';

Expand All @@ -25,7 +23,6 @@ const availableGenerators = Object.keys(publicGenerators);
* @property {string} changelog - Specifies the path to the Node.js CHANGELOG.md file.
* @property {string} [gitRef] - Git ref/commit URL.
* @property {number} [threads] - Number of threads to allow.
* @property {boolean} [skipLint] - Skip lint before generate.
*/

/**
Expand Down Expand Up @@ -115,34 +112,14 @@ export default {
type: 'text',
},
},
skipLint: {
flags: ['--skip-lint'],
desc: 'Skip lint before generate',
prompt: {
type: 'confirm',
message: 'Skip lint before generate?',
initialValue: false,
},
},
},
/**
* Handles the action for generating API docs
* @param {Options} opts - The options to generate API docs.
* @returns {Promise<void>}
*/
async action(opts) {
const rules = getEnabledRules(opts.disableRule);
const linter = opts.skipLint ? undefined : createLinter(rules);

const docs = await loadAndParse(opts.input, opts.ignore, linter);

linter?.report();

if (linter?.hasError()) {
console.error('Lint failed; aborting generation.');
process.exit(1);
}

const docs = await loadAndParse(opts.input, opts.ignore);
const releases = await parseChangelog(opts.changelog);
const index = opts.index && (await parseIndex(opts.index));

Expand Down
3 changes: 1 addition & 2 deletions bin/commands/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import generate from './generate.mjs';
import lint from './lint.mjs';

export default [generate, lint];
export default [generate];
96 changes: 0 additions & 96 deletions bin/commands/lint.mjs

This file was deleted.

27 changes: 0 additions & 27 deletions bin/commands/list.mjs

This file was deleted.

7 changes: 3 additions & 4 deletions bin/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ const parser = lazy(createMarkdownParser);
* Load and parse markdown API docs.
* @param {string[]} input - Glob patterns for input files.
* @param {string[]} [ignore] - Glob patterns to ignore.
* @param {import('../src/linter/types').Linter} [linter] - Linter instance
* @returns {Promise<Array<ParserOutput<import('mdast').Root>>>}
*/
export async function loadAndParse(input, ignore, linter) {
export async function loadAndParse(input, ignore) {
const files = await loader().loadFiles(input, ignore);
return parser(linter).parseApiDocs(files);
return parser().parseApiDocs(files);
}

/**
Expand All @@ -49,7 +48,7 @@ export const errorWrap =
};

/**
* Represents a command-line option for the linter CLI.
* Represents a command-line option for the CLI.
* @typedef {Object} Option
* @property {string[]} flags - Command-line flags, e.g., ['-i, --input <patterns...>'].
* @property {string} desc - Description of the option.
Expand Down
Loading
Loading