11'use strict' ;
22
3- import { mkdir , writeFile } from 'node:fs/promises' ;
4- import { join } from 'node:path' ;
5-
6- import { visit } from 'unist-util-visit' ;
7-
8- import { EXTRACT_CODE_FILENAME_COMMENT } from './constants.mjs' ;
9- import { generateFileList } from './utils/generateFileList.mjs' ;
10- import {
11- generateSectionFolderName ,
12- isBuildableSection ,
13- normalizeSectionName ,
14- } from './utils/section.mjs' ;
15- import getConfig from '../../utils/configuration/index.mjs' ;
16-
173/**
184 * This generator generates a file list from code blocks extracted from
195 * `doc/api/addons.md` to facilitate C++ compilation and JavaScript runtime
@@ -30,68 +16,4 @@ export default {
3016 'Generates a file list from code blocks extracted from `doc/api/addons.md` to facilitate C++ compilation and JavaScript runtime validations' ,
3117
3218 dependsOn : 'metadata' ,
33-
34- /**
35- * Generates a file list from code blocks.
36- */
37- async generate ( input ) {
38- const config = getConfig ( 'addon-verify' ) ;
39-
40- const sectionsCodeBlocks = input . reduce ( ( addons , node ) => {
41- const sectionName = node . heading . data . name ;
42-
43- const content = node . content ;
44-
45- visit ( content , childNode => {
46- if ( childNode . type === 'code' ) {
47- const filename = childNode . value . match ( EXTRACT_CODE_FILENAME_COMMENT ) ;
48-
49- if ( filename === null ) {
50- return ;
51- }
52-
53- if ( ! addons [ sectionName ] ) {
54- addons [ sectionName ] = [ ] ;
55- }
56-
57- addons [ sectionName ] . push ( {
58- name : filename [ 1 ] ,
59- content : childNode . value ,
60- } ) ;
61- }
62- } ) ;
63-
64- return addons ;
65- } , { } ) ;
66-
67- const files = await Promise . all (
68- Object . entries ( sectionsCodeBlocks )
69- . filter ( ( [ , codeBlocks ] ) => isBuildableSection ( codeBlocks ) )
70- . flatMap ( async ( [ sectionName , codeBlocks ] , index ) => {
71- const files = generateFileList ( codeBlocks ) ;
72-
73- if ( config . output ) {
74- const normalizedSectionName = normalizeSectionName ( sectionName ) ;
75-
76- const folderName = generateSectionFolderName (
77- normalizedSectionName ,
78- index
79- ) ;
80-
81- await mkdir ( join ( config . output , folderName ) , { recursive : true } ) ;
82-
83- for ( const file of files ) {
84- await writeFile (
85- join ( config . output , folderName , file . name ) ,
86- file . content
87- ) ;
88- }
89- }
90-
91- return files ;
92- } )
93- ) ;
94-
95- return files ;
96- } ,
9719} ;
0 commit comments