11'use strict' ;
22
3- import { writeFile } from 'node:fs/promises' ;
43import { join } from 'node:path' ;
54
65import { createSectionBuilder } from './utils/buildSection.mjs' ;
76import getConfig from '../../utils/configuration/index.mjs' ;
7+ import { writeFile , withExt } from '../../utils/file.mjs' ;
88import { groupNodesByModule , legacyToJSON } from '../../utils/generators.mjs' ;
99
1010const buildSection = createSectionBuilder ( ) ;
@@ -42,6 +42,10 @@ export async function* generate(input, worker) {
4242
4343 const headNodes = input . filter ( node => node . heading . depth === 1 ) ;
4444
45+ // Map each section's `api` slug back to its source path so the output keeps
46+ // the input directory structure instead of flattening into the root.
47+ const pathByApi = new Map ( headNodes . map ( ( { api, path } ) => [ api , path ] ) ) ;
48+
4549 // Create sliced input: each item contains head + its module's entries
4650 // This avoids sending all 4900+ entries to every worker
4751 const entries = headNodes . map ( head => ( {
@@ -52,7 +56,10 @@ export async function* generate(input, worker) {
5256 for await ( const chunkResult of worker . stream ( entries ) ) {
5357 if ( config . output ) {
5458 for ( const section of chunkResult ) {
55- const out = join ( config . output , `${ section . api } .json` ) ;
59+ const out = join (
60+ config . output ,
61+ withExt ( pathByApi . get ( section . api ) , 'json' )
62+ ) ;
5663
5764 await writeFile (
5865 out ,
0 commit comments