-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (34 loc) · 1.22 KB
/
index.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
#! /usr/bin/env node
const fs = require("fs")
const cp = require("child_process");
const target = process.argv[2]
cp.execSync(`cd ${target}`)
const cwd = process.cwd()
function getFilesListInDirent(target) {
return fs.readdirSync(target, { withFileTypes: true });
}
getFilesListInDirent(target).forEach(file => {
let filePath = `${cwd}/${target}/${file.name}`
// console.log(filePath, file.isDirectory() ? "directory" : "file")
if (file.isDirectory()) {
process.chdir(filePath)
filePath = process.cwd()
const folderFiles = getFilesListInDirent(filePath).map(dir => dir.name)
if (folderFiles.includes("node_modules")) {
console.log(`Removing ${filePath}/node_modules`)
const removalTask = cp.spawn("rm", ["-rf", `${filePath}/node_modules`])
removalTask.stdout.on("data", data => {
console.log(`stdout: ${data}`);
});
removalTask.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
removalTask.on('error', (error) => {
console.log(`error: ${error.message}`);
});
removalTask.on("close", code => {
console.log(`Cleaning of ${filePath}/node_modules exited with code ${code}`);
});
}
}
});