diff --git a/package.json b/package.json index 0cf7ab58..03e76381 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,6 @@ "devDependencies": { "@inquirer/prompts": "4.3.0", "chalk": "5.3.0", - "del-cli": "5.1.0", "editorconfig-checker": "5.1.5", "esbuild": "0.19.4", "fake-diff": "1.0.0", @@ -108,7 +107,7 @@ }, "scripts": { "build": "node scripts/build/package.js", - "clean": "del-cli index.js index.mjs index.d.ts sdk.js", + "clean": "node scripts/build/clean.js", "format": "prettier --cache --write .", "lint": "npm run ourlint && npm run jslint && npm run jsonlint && npm run svglint && npm run wslint", "ourlint": "node scripts/lint/ourlint.js", diff --git a/scripts/build/clean.js b/scripts/build/clean.js new file mode 100644 index 00000000..ff95c4b9 --- /dev/null +++ b/scripts/build/clean.js @@ -0,0 +1,29 @@ +/** + * @fileoverview + * Clean files built by the build process. + */ + +import fs from 'node:fs'; +import path from 'node:path'; +import { getDirnameFromImportMeta } from '../../sdk.mjs'; + +const __dirname = getDirnameFromImportMeta(import.meta.url); +const rootDirectory = path.resolve(__dirname, '..', '..'); +const files = ['index.js', 'index.mjs', 'index.d.ts', 'sdk.js']; + +const fileExists = (fpath) => + new Promise((r) => fs.access(fpath, fs.constants.F_OK, (e) => r(!e))); + +Promise.all( + files.map(async (file) => { + const filepath = path.join(rootDirectory, file); + if (!(await fileExists(filepath))) { + console.error(`File ${file} does not exist, skipping...`); + return; + } + return fs.promises.unlink(filepath); + }), +).catch((error) => { + console.error(`Error cleaning files: ${error.message}`); + process.exit(1); +});