-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathdeleteNodeModules.js
58 lines (45 loc) · 1.33 KB
/
deleteNodeModules.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
const fs = require('fs')
const path = require('path')
const util = require('util');
const readdir = util.promisify(fs.readdir);
const lstat = util.promisify(fs.lstat);
const unlink = util.promisify(fs.unlink);
const rmdir = util.promisify(fs.rmdir);
const afs = fs.promises;
const _root = __dirname;
const deleteNodeModules = async (_path) => {
if(fs.existsSync(_path)){
for (let file of await afs.readdir(_path)) {
// fs.readdirSync(_path).forEach( function(file, index){
let currPath = path.join(_path, file)
if ((await afs.lstat(currPath)).isDirectory()){
if(file === 'node_modules'){
console.log("deleteFolder: ", currPath)
await deleteFolder(currPath)
} else {
console.log("deleteNodeModules: ", currPath)
await deleteNodeModules(currPath)
}
}
//})
}
}
}
const deleteFolder = async (_path) => {
if(fs.existsSync(_path)){
for (let file of await afs.readdir(_path)) {
//fs.readdirSync(_path).forEach( function(file, index){
let currPath = path.join(_path, file)
if ((await afs.lstat(currPath)).isDirectory()){
await deleteFolder(currPath)
} else {
await afs.unlink(currPath)
}
//})
}
//typeof cb === 'function' && cb(_path)
//fs.rmdirSync(_path)
await afs.rmdir(_path);
}
}
deleteNodeModules(_root)