diff --git a/package.json b/package.json index 24ecaf5..ddf273a 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "test:unit": "jest --runInBand --verbose", "test:unit:watch": "jest --runInBand --watch --verbose", "build": "yarn build:esm && yarn build:cjs", + "build:clean": "node --experimental-modules scripts/clean-dist.mjs", "build:esm": "tsc --module es6 --target es2018 --outDir dist/esm", "build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs", "build:umd": "tsc --module umd --target es5 --outDir dist/umd", diff --git a/scripts/clean-dist.mjs b/scripts/clean-dist.mjs new file mode 100644 index 0000000..59c18e0 --- /dev/null +++ b/scripts/clean-dist.mjs @@ -0,0 +1,25 @@ +import { + existsSync, + readdirSync, + lstatSync, + unlinkSync, + rmdirSync, +} from 'fs'; +import { join } from 'path'; + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +const deleteFolderRecursive = (filePath) => { + if (existsSync(filePath)) { + readdirSync(filePath).forEach((file, _index) => { + const curPath = join(filePath, file); + if (lstatSync(curPath).isDirectory()) { // recurse + deleteFolderRecursive(curPath); + } else { // delete file + unlinkSync(curPath); + } + }); + rmdirSync(filePath); + } +}; + +deleteFolderRecursive('./dist');