forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean-build.mjs
35 lines (31 loc) · 899 Bytes
/
clean-build.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import path from "path";
import fse from "fs-extra";
import chalk from "chalk";
const ROOT_DIR = process.cwd();
const BUILD_PATH = path.join(ROOT_DIR, "build");
const PACKAGES_PATH = path.join(ROOT_DIR, "packages");
cleanBuild();
async function cleanBuild() {
/** @type {Promise<void>[]} */
let deleteQueue = [removeDir(BUILD_PATH)];
for (let fileName of await fse.readdir(PACKAGES_PATH)) {
let buildPath = path.join(PACKAGES_PATH, fileName, "dist");
deleteQueue.push(removeDir(buildPath));
}
await Promise.all(deleteQueue);
console.log(chalk.green(" ✅ Successfully deleted build files!"));
}
/**
* @param {string} dir
*/
async function removeDir(dir) {
try {
if (!(await fse.stat(dir)).isDirectory()) {
return;
}
} catch (_) {
return;
}
console.log(chalk.yellow(` 🛠 Deleting ${path.relative(ROOT_DIR, dir)}`));
await fse.remove(dir);
}