@@ -14,7 +14,7 @@ import { marked } from 'marked';
1414import { compilePublicTypes } from '../generate-types.js' ;
1515import schema from '../../schemas/public.schema.json' with { type : 'json' } ;
1616import { createAjv } from '../lib/ajv.js' ;
17- import { walk } from '../../utils/index.js' ;
17+ import { spawnAsync , walk } from '../../utils/index.js' ;
1818import bcd from '../../index.js' ;
1919
2020import mirrorSupport from './mirror.js' ;
@@ -395,21 +395,13 @@ const writeManifest = async () => {
395395 * Perform a build of BCD for publishing
396396 */
397397const main = async ( ) => {
398- // Remove existing files, if there are any
399- await fs
400- . rm ( targetdir , {
401- force : true ,
402- recursive : true ,
403- } )
404- . catch ( ( e ) => {
405- // Missing folder is not an issue since we wanted to delete it anyway
406- if ( e . code !== 'ENOENT' ) {
407- throw e ;
408- }
409- } ) ;
410-
411- // Crate a new directory
412- await fs . mkdir ( targetdir ) ;
398+ // Remove previous build outputs while preserving tracked files in build/
399+ // (.gitignore, .npmignore, tsconfig.json). -x is required because build
400+ // outputs are gitignored.
401+ await fs . mkdir ( targetdir , { recursive : true } ) ;
402+ await spawnAsync ( 'git' , [ 'clean' , '-fdx' , '.' ] , {
403+ cwd : fileURLToPath ( targetdir ) ,
404+ } ) ;
413405
414406 await Promise . all ( [
415407 writeManifest ( ) ,
0 commit comments