1
1
#!/usr/bin/env node
2
2
3
3
import { resolve } from 'node:path' ;
4
- import { argv } from 'node:process' ;
4
+ import { argv , exit } from 'node:process' ;
5
5
6
6
import { Command , Option } from 'commander' ;
7
7
@@ -12,6 +12,9 @@ import generators from '../src/generators/index.mjs';
12
12
import createMarkdownLoader from '../src/loaders/markdown.mjs' ;
13
13
import createMarkdownParser from '../src/parsers/markdown.mjs' ;
14
14
import createNodeReleases from '../src/releases.mjs' ;
15
+ import createLinter from '../src/linter/index.mjs' ;
16
+ import reporters from '../src/linter/reporters/index.mjs' ;
17
+ import rules from '../src/linter/rules/index.mjs' ;
15
18
16
19
const availableGenerators = Object . keys ( generators ) ;
17
20
@@ -50,6 +53,19 @@ program
50
53
'Set the processing target modes'
51
54
) . choices ( availableGenerators )
52
55
)
56
+ . addOption (
57
+ new Option ( '--disable-rule [rule...]' , 'Disable a specific linter rule' )
58
+ . choices ( Object . keys ( rules ) )
59
+ . default ( [ ] )
60
+ )
61
+ . addOption (
62
+ new Option ( '--lint-dry-run' , 'Run linter in dry-run mode' ) . default ( false )
63
+ )
64
+ . addOption (
65
+ new Option ( '-r, --reporter [reporter]' , 'Specify the linter reporter' )
66
+ . choices ( Object . keys ( reporters ) )
67
+ . default ( 'console' )
68
+ )
53
69
. parse ( argv ) ;
54
70
55
71
/**
@@ -60,13 +76,27 @@ program
60
76
* @property {string } output Specifies the directory where output files will be saved.
61
77
* @property {Target[] } target Specifies the generator target mode.
62
78
* @property {string } version Specifies the target Node.js version.
63
- * @property {string } changelog Specifies the path to the Node.js CHANGELOG.md file
79
+ * @property {string } changelog Specifies the path to the Node.js CHANGELOG.md file.
80
+ * @property {string[] } disableRule Specifies the linter rules to disable.
81
+ * @property {boolean } lintDryRun Specifies whether the linter should run in dry-run mode.
82
+ * @property {keyof reporters } reporter Specifies the linter reporter.
64
83
*
65
84
* @name ProgramOptions
66
85
* @type {Options }
67
86
* @description The return type for values sent to the program from the CLI.
68
87
*/
69
- const { input, output, target = [ ] , version, changelog } = program . opts ( ) ;
88
+ const {
89
+ input,
90
+ output,
91
+ target = [ ] ,
92
+ version,
93
+ changelog,
94
+ disableRule,
95
+ lintDryRun,
96
+ reporter,
97
+ } = program . opts ( ) ;
98
+
99
+ const linter = createLinter ( lintDryRun , disableRule ) ;
70
100
71
101
const { loadFiles } = createMarkdownLoader ( ) ;
72
102
const { parseApiDocs } = createMarkdownParser ( ) ;
@@ -80,6 +110,8 @@ const { runGenerators } = createGenerator(parsedApiDocs);
80
110
// Retrieves Node.js release metadata from a given Node.js version and CHANGELOG.md file
81
111
const { getAllMajors } = createNodeReleases ( changelog ) ;
82
112
113
+ linter . lintAll ( parsedApiDocs ) ;
114
+
83
115
await runGenerators ( {
84
116
// A list of target modes for the API docs parser
85
117
generators : target ,
@@ -92,3 +124,7 @@ await runGenerators({
92
124
// A list of all Node.js major versions with LTS status
93
125
releases : await getAllMajors ( ) ,
94
126
} ) ;
127
+
128
+ linter . report ( reporter ) ;
129
+
130
+ exit ( Number ( linter . hasError ( ) ) ) ;
0 commit comments