-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (19 loc) · 830 Bytes
/
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
const fs = require('fs');
const rimraf = require('rimraf');
const { getValueByParamName } = require('./utils/argsParser');
if(process.argv.length <= 2)
return console.log('You must specify a projects folder directory.\nCommand usage: modules-cleaner -path <path>')
try {
const startingPath = fs.realpathSync(getValueByParamName('-path', process.argv));
} catch (error) {
if(error.code === 'ENOENT')
return console.log('The provided directory is not valid.');
}
const projectFolders = fs.readdirSync(startingPath, { withFileTypes: true })
.filter(v => !v.isFile());
for(let folder of projectFolders) {
const folderFiles = fs.readdirSync(`${startingPath}/${folder.name}`);
if(folderFiles.indexOf('.cleaner-protected') != -1)
continue;
rimraf.sync(`${startingPath}/${folder.name}/node_modules`);
}