11'use strict' ;
22
3- import { cp , readFile , rm , writeFile } from 'node:fs/promises' ;
3+ import { readFile , rm , writeFile , mkdir } from 'node:fs/promises' ;
44import { join } from 'node:path' ;
55
66import HTMLMinifier from '@minify-html/node' ;
77
88import buildContent from './utils/buildContent.mjs' ;
99import dropdowns from './utils/buildDropdowns.mjs' ;
10+ import { safeCopy } from './utils/safeCopy.mjs' ;
1011import tableOfContents from './utils/tableOfContents.mjs' ;
1112import { groupNodesByModule } from '../../utils/generators.mjs' ;
1213import { getRemarkRehype } from '../../utils/remark.mjs' ;
@@ -169,6 +170,9 @@ export default {
169170 }
170171
171172 if ( output ) {
173+ // Define the source folder for API docs assets
174+ const srcAssets = join ( baseDir , 'assets' ) ;
175+
172176 // Define the output folder for API docs assets
173177 const assetsFolder = join ( output , 'assets' ) ;
174178
@@ -177,13 +181,11 @@ export default {
177181 // If the path does not exists, it will simply ignore and continue
178182 await rm ( assetsFolder , { recursive : true , force : true , maxRetries : 10 } ) ;
179183
180- // We copy all the other assets to the output folder at the end of the process
181- // to ensure that all latest changes on the styles are applied to the output
182- // Note.: This is not meant to be used for DX/developer purposes.
183- await cp ( join ( baseDir , 'assets' ) , assetsFolder , {
184- recursive : true ,
185- force : true ,
186- } ) ;
184+ // Creates the assets folder if it does not exist
185+ await mkdir ( assetsFolder , { recursive : true } ) ;
186+
187+ // Copy all files from assets folder to output, skipping unchanged files
188+ await safeCopy ( srcAssets , assetsFolder ) ;
187189 }
188190
189191 return generatedValues ;
0 commit comments