1- import { OVERRIDDEN_POSITIONS } from './constants.mjs' ;
21import { buildSideBarProps } from './utils/buildBarProps.mjs' ;
32import buildContent from './utils/buildContent.mjs' ;
4- import { groupNodesByModule } from '../../utils/generators.mjs' ;
3+ import {
4+ buildDocPages ,
5+ getSortedHeadNodes ,
6+ groupNodesByModule ,
7+ } from '../../utils/generators.mjs' ;
58import { getRemarkRecma } from '../../utils/remark.mjs' ;
69
710/**
@@ -10,78 +13,53 @@ import { getRemarkRecma } from '../../utils/remark.mjs';
1013 * @typedef {Array<ApiDocMetadataEntry> } Input
1114 * @type {GeneratorMetadata<Input, string> }
1215 */
13-
14- /**
15- * Sorts entries by OVERRIDDEN_POSITIONS and then heading name.
16- * @param {Array<ApiDocMetadataEntry> } entries
17- */
18- const getSortedHeadNodes = entries => {
19- return entries
20- . filter ( node => node . heading . depth === 1 )
21- . sort ( ( a , b ) => {
22- const ai = OVERRIDDEN_POSITIONS . indexOf ( a . api ) ;
23- const bi = OVERRIDDEN_POSITIONS . indexOf ( b . api ) ;
24-
25- if ( ai !== - 1 && bi !== - 1 ) {
26- return ai - bi ;
27- }
28-
29- if ( ai !== - 1 ) {
30- return - 1 ;
31- }
32-
33- if ( bi !== - 1 ) {
34- return 1 ;
35- }
36-
37- return a . heading . data . name . localeCompare ( b . heading . data . name ) ;
38- } ) ;
39- } ;
40-
4116export default {
4217 name : 'jsx-ast' ,
4318 version : '1.0.0' ,
4419 description : 'Generates JSX AST from the input MDAST' ,
4520 dependsOn : 'metadata' ,
4621
4722 /**
48- * Generates a JSX AST
49- *
50- * @param {Input } entries
23+ * Process a chunk of items in a worker thread.
24+ * @param { Input } fullInput
25+ * @param {number[] } itemIndices
5126 * @param {Partial<GeneratorOptions> } options
52- * @returns {Promise<Array<string>> } Array of generated content
5327 */
54- async generate ( entries , { index, releases, version } ) {
55- const remarkRecma = getRemarkRecma ( ) ;
56- const groupedModules = groupNodesByModule ( entries ) ;
57- const headNodes = getSortedHeadNodes ( entries ) ;
58-
59- // Generate table of contents
60- const docPages = index
61- ? index . map ( ( { section, api } ) => [ section , `${ api } .html` ] )
62- : headNodes . map ( node => [ node . heading . data . name , `${ node . api } .html` ] ) ;
28+ async processChunk ( fullInput , itemIndices , { index, releases, version } ) {
29+ const processor = getRemarkRecma ( ) ;
30+ const groupedModules = groupNodesByModule ( fullInput ) ;
31+ const headNodes = getSortedHeadNodes ( fullInput ) ;
32+ const docPages = buildDocPages ( headNodes , index ) ;
6333
64- // Process each head node and build content
65- const results = [ ] ;
34+ return Promise . all (
35+ itemIndices . map ( async idx => {
36+ const entry = headNodes [ idx ] ;
6637
67- for ( const entry of headNodes ) {
68- const sideBarProps = buildSideBarProps (
69- entry ,
70- releases ,
71- version ,
72- docPages
73- ) ;
38+ const sideBarProps = buildSideBarProps (
39+ entry ,
40+ releases ,
41+ version ,
42+ docPages
43+ ) ;
7444
75- results . push (
76- await buildContent (
45+ return buildContent (
7746 groupedModules . get ( entry . api ) ,
7847 entry ,
7948 sideBarProps ,
80- remarkRecma
81- )
82- ) ;
83- }
49+ processor
50+ ) ;
51+ } )
52+ ) ;
53+ } ,
54+
55+ /**
56+ * Generates a JSX AST
57+ * @param {Input } entries
58+ * @param {Partial<GeneratorOptions> } options
59+ */
60+ async generate ( entries , { index, releases, version, worker } ) {
61+ const headNodes = getSortedHeadNodes ( entries ) ;
8462
85- return results ;
63+ return worker . map ( headNodes , entries , { index , releases , version } ) ;
8664 } ,
8765} ;
0 commit comments