1- import { cpus } from 'node:os' ;
2-
31import { Command , Option } from 'commander' ;
4- import { coerce } from 'semver' ;
52
6- import { NODE_CHANGELOG_URL , NODE_VERSION } from '../../src/constants.mjs' ;
73import { publicGenerators } from '../../src/generators/index.mjs' ;
84import createGenerator from '../../src/generators.mjs' ;
9- import logger from '../../src/logger/index.mjs' ;
10- import { parseTypeMap } from '../../src/parsers/json.mjs' ;
11- import { parseChangelog , parseIndex } from '../../src/parsers/markdown.mjs' ;
12- import { DEFAULT_TYPE_MAP } from '../../src/utils/parser/constants.mjs' ;
5+ import { setConfig } from '../../src/utils/configuration/index.mjs' ;
136import { errorWrap } from '../utils.mjs' ;
147
8+ const { runGenerators } = createGenerator ( ) ;
9+
10+ /**
11+ * @typedef {Object } CLIOptions
12+ * @property {string[] } input
13+ * @property {string[] } target
14+ * @property {string[] } ignore
15+ * @property {string } output
16+ * @property {number } threads
17+ * @property {number } chunkSize
18+ * @property {string } version
19+ * @property {string } changelog
20+ * @property {string } gitRef
21+ * @property {string } index
22+ * @property {boolean } minify
23+ * @property {string } typeMap
24+ */
25+
1526export default new Command ( 'generate' )
1627 . description ( 'Generate API docs' )
28+ . addOption ( new Option ( '--config-file <path>' , 'Config file' ) )
29+
30+ // Options that need to be converted into a configuration
1731 . addOption (
18- new Option (
19- '-i, --input <patterns...>' ,
20- 'Input file patterns (glob)'
21- ) . makeOptionMandatory ( )
32+ new Option ( '-i, --input <patterns...>' , 'Input file patterns (glob)' )
33+ )
34+ . addOption (
35+ new Option ( '-t, --target <generator...>' , 'Target generator(s)' ) . choices (
36+ Object . keys ( publicGenerators )
37+ )
2238 )
2339 . addOption (
2440 new Option ( '--ignore <patterns...>' , 'Ignore file patterns (glob)' )
@@ -29,63 +45,23 @@ export default new Command('generate')
2945 '-p, --threads <number>' ,
3046 'Number of threads to use (minimum: 1)'
3147 )
32- . default ( cpus ( ) . length )
33- . argParser ( parseInt )
3448 )
3549 . addOption (
3650 new Option (
3751 '--chunk-size <number>' ,
3852 'Number of items to process per worker thread (minimum: 1)'
3953 )
40- . default ( 10 )
41- . argParser ( parseInt )
42- )
43- . addOption (
44- new Option ( '-v, --version <semver>' , 'Target Node.js version' ) . default (
45- NODE_VERSION
46- )
47- )
48- . addOption (
49- new Option ( '-c, --changelog <url>' , 'Changelog URL or path' ) . default (
50- NODE_CHANGELOG_URL
51- )
52- )
53- . addOption (
54- new Option ( '--git-ref' , 'Git ref URL' ) . default (
55- 'https://github.com/nodejs/node/tree/HEAD'
56- )
57- )
58- . addOption (
59- new Option ( '-t, --target <generator...>' , 'Target generator(s)' )
60- . makeOptionMandatory ( )
61- . choices ( Object . keys ( publicGenerators ) )
6254 )
55+ . addOption ( new Option ( '-v, --version <semver>' , 'Target Node.js version' ) )
56+ . addOption ( new Option ( '-c, --changelog <url>' , 'Changelog URL or path' ) )
57+ . addOption ( new Option ( '--git-ref' , 'Git ref URL' ) )
6358 . addOption ( new Option ( '--index <url>' , 'index.md URL or path' ) )
64- . addOption (
65- new Option ( '--type-map <url>' , 'Type map URL or path' ) . default (
66- DEFAULT_TYPE_MAP
67- )
68- )
59+ . addOption ( new Option ( '--minify' , 'Minify?' ) )
60+ . addOption ( new Option ( '--type-map <url>' , 'Type map URL or path' ) )
61+
6962 . action (
7063 errorWrap ( async opts => {
71- logger . debug ( 'Starting doc-kit' , opts ) ;
72-
73- const { runGenerators } = createGenerator ( ) ;
74-
75- logger . debug ( 'Starting generation' , { targets : opts . target } ) ;
76-
77- await runGenerators ( {
78- generators : opts . target ,
79- input : opts . input ,
80- ignore : opts . ignore ,
81- output : opts . output ,
82- version : coerce ( opts . version ) ,
83- releases : await parseChangelog ( opts . changelog ) ,
84- gitRef : opts . gitRef ,
85- threads : Math . max ( opts . threads , 1 ) ,
86- chunkSize : Math . max ( opts . chunkSize , 1 ) ,
87- index : await parseIndex ( opts . index ) ,
88- typeMap : await parseTypeMap ( opts . typeMap ) ,
89- } ) ;
64+ const config = await setConfig ( opts ) ;
65+ await runGenerators ( config ) ;
9066 } )
9167 ) ;
0 commit comments