Skip to content

Commit 4e14e18

Browse files
committed
fix(scripts/build): reset build dir, do not delete
1 parent 8ab3662 commit 4e14e18

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

scripts/build/index.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { marked } from 'marked';
1414
import { compilePublicTypes } from '../generate-types.js';
1515
import schema from '../../schemas/public.schema.json' with { type: 'json' };
1616
import { createAjv } from '../lib/ajv.js';
17-
import { walk } from '../../utils/index.js';
17+
import { spawnAsync, walk } from '../../utils/index.js';
1818
import bcd from '../../index.js';
1919

2020
import mirrorSupport from './mirror.js';
@@ -395,21 +395,13 @@ const writeManifest = async () => {
395395
* Perform a build of BCD for publishing
396396
*/
397397
const 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

Comments
 (0)