@@ -3,38 +3,18 @@ import { resolve } from 'node:path';
33
44import { coerce } from 'semver' ;
55
6- import {
7- DOC_NODE_CHANGELOG_URL ,
8- DOC_NODE_VERSION ,
9- } from '../../src/constants.mjs' ;
6+ import { NODE_CHANGELOG_URL , NODE_VERSION } from '../../src/constants.mjs' ;
107import { publicGenerators } from '../../src/generators/index.mjs' ;
118import createGenerator from '../../src/generators.mjs' ;
9+ import logger from '../../src/logger/index.mjs' ;
10+ import { parseTypeMap } from '../../src/parsers/json.mjs' ;
1211import { parseChangelog , parseIndex } from '../../src/parsers/markdown.mjs' ;
1312import { DEFAULT_TYPE_MAP } from '../../src/utils/parser/constants.mjs' ;
14- import { loadFromURL } from '../../src/utils/parser.mjs' ;
15- import { loadAndParse } from '../utils.mjs' ;
1613
1714const availableGenerators = Object . keys ( publicGenerators ) ;
1815
19- // Half of available logical CPUs guarantees in general all physical CPUs are being used
20- // which in most scenarios is the best way to maximize performance
21- const optimalThreads = Math . floor ( cpus ( ) . length / 2 ) + 1 ;
22-
23- /**
24- * @typedef {Object } Options
25- * @property {Array<string>|string } input - Specifies the glob/path for input files.
26- * @property {Array<string>|string } [ignore] - Specifies the glob/path for ignoring files.
27- * @property {Array<keyof publicGenerators> } target - Specifies the generator target mode.
28- * @property {string } version - Specifies the target Node.js version.
29- * @property {string } changelog - Specifies the path to the Node.js CHANGELOG.md file.
30- * @property {string } typeMap - Specifies the path to the Node.js Type Map.
31- * @property {string } [gitRef] - Git ref/commit URL.
32- * @property {number } [threads] - Number of threads to allow.
33- * @property {number } [chunkSize] - Number of items to process per worker thread.
34- */
35-
3616/**
37- * @type {import('../utils.mjs ').Command }
17+ * @type {import('./types ').Command }
3818 */
3919export default {
4020 description : 'Generate API docs' ,
@@ -66,11 +46,11 @@ export default {
6646 } ,
6747 threads : {
6848 flags : [ '-p' , '--threads <number>' ] ,
69- desc : 'Number of worker threads to use' ,
49+ desc : 'Number of threads to use (minimum: 1) ' ,
7050 prompt : {
7151 type : 'text' ,
7252 message : 'How many threads to allow' ,
73- initialValue : String ( Math . max ( optimalThreads , 1 ) ) ,
53+ initialValue : String ( cpus ( ) . length ) ,
7454 } ,
7555 } ,
7656 chunkSize : {
@@ -88,7 +68,7 @@ export default {
8868 prompt : {
8969 type : 'text' ,
9070 message : 'Enter Node.js version' ,
91- initialValue : DOC_NODE_VERSION ,
71+ initialValue : NODE_VERSION ,
9272 } ,
9373 } ,
9474 changelog : {
@@ -97,7 +77,7 @@ export default {
9777 prompt : {
9878 type : 'text' ,
9979 message : 'Enter changelog URL' ,
100- initialValue : DOC_NODE_CHANGELOG_URL ,
80+ initialValue : NODE_CHANGELOG_URL ,
10181 } ,
10282 } ,
10383 gitRef : {
@@ -140,33 +120,42 @@ export default {
140120 } ,
141121 } ,
142122 } ,
123+
143124 /**
125+ * @typedef {Object } Options
126+ * @property {Array<string>|string } input - Specifies the glob/path for input files.
127+ * @property {Array<string>|string } [ignore] - Specifies the glob/path for ignoring files.
128+ * @property {Array<keyof AvailableGenerators> } target - Specifies the generator target mode.
129+ * @property {string } version - Specifies the target Node.js version.
130+ * @property {string } changelog - Specifies the path to the Node.js CHANGELOG.md file.
131+ * @property {string } typeMap - Specifies the path to the Node.js Type Map.
132+ * @property {string } index - Specifies the path to the index document.
133+ * @property {string } [gitRef] - Git ref/commit URL.
134+ * @property {number } [threads] - Number of threads to allow.
135+ * @property {number } [chunkSize] - Number of items to process per worker thread.
136+ *
144137 * Handles the action for generating API docs
145138 * @param {Options } opts - The options to generate API docs.
146139 * @returns {Promise<void> }
147140 */
148141 async action ( opts ) {
149- const docs = await loadAndParse ( opts . input , opts . ignore ) ;
150- const releases = await parseChangelog ( opts . changelog ) ;
151-
152- const rawTypeMap = await loadFromURL ( opts . typeMap ) ;
153- const typeMap = JSON . parse ( rawTypeMap ) ;
142+ logger . debug ( 'Starting doc-kit' , opts ) ;
154143
155- const index = opts . index && ( await parseIndex ( opts . index ) ) ;
144+ const { runGenerators } = createGenerator ( ) ;
156145
157- const { runGenerators } = createGenerator ( docs ) ;
146+ logger . debug ( 'Starting generation' , { targets : opts . target } ) ;
158147
159148 await runGenerators ( {
160149 generators : opts . target ,
161150 input : opts . input ,
162151 output : opts . output && resolve ( opts . output ) ,
163152 version : coerce ( opts . version ) ,
164- releases,
153+ releases : await parseChangelog ( opts . changelog ) ,
165154 gitRef : opts . gitRef ,
166- threads : parseInt ( opts . threads , 10 ) ,
167- chunkSize : parseInt ( opts . chunkSize , 10 ) ,
168- index,
169- typeMap,
155+ threads : Math . max ( parseInt ( opts . threads , 10 ) , 1 ) ,
156+ chunkSize : Math . max ( parseInt ( opts . chunkSize , 10 ) , 1 ) ,
157+ index : await parseIndex ( opts . index ) ,
158+ typeMap : await parseTypeMap ( opts . typeMap ) ,
170159 } ) ;
171160 } ,
172161} ;
0 commit comments