forked from CodeForBoulder/upswyng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.js
73 lines (59 loc) · 1.79 KB
/
clean.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Script to clean local environment. Usage:
* `yarn clean` to clean build artifacts
* `yarn clean --reset` to totally reset local environment by removing build artifacts, node modules, and .env files.
*/
const fs = require("fs");
const glob = require("glob");
const args = process.argv.slice(2);
const foldersToDelete = [
"./packages/types/dist",
"./packages/common/dist",
"./packages/server/__build__",
"./packages/web/build",
];
const globsToDelete = [
"./packages/**/tsconfig*.tsbuildinfo",
"./packages/web/.env",
];
const foldersToDeleteForFullReset = [
"./node_modules",
"./packages/types/node_modules",
"./packages/web/node_modules",
"./packages/server/node_modules",
"./packages/common/node_modules",
];
const globsToDeleteForFullReset = [
"./packages/web/.env",
"./packages/server/.env",
];
function deleteFolderRecursive(path) {
if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) {
fs.readdirSync(path).forEach(function(file) {
const curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});
console.log(` 🗑 Deleting "${path}"...`);
fs.rmdirSync(path);
}
}
function deleteGlob(globString) {
glob.sync(globString, { cwd: ".", nodir: true }).forEach(f => {
console.log(` 🗑 Deleting file "${f}"...`);
fs.lstatSync(f).isFile() && fs.unlinkSync(f);
});
}
console.log("🧹 Cleaning...");
foldersToDelete.forEach(deleteFolderRecursive);
globsToDelete.forEach(deleteGlob);
if (args[0] === "--reset") {
foldersToDeleteForFullReset.forEach(deleteFolderRecursive);
globsToDeleteForFullReset.forEach(deleteGlob);
}
console.log("🧼 Successfully cleaned.");