-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (24 loc) · 756 Bytes
/
index.js
File metadata and controls
29 lines (24 loc) · 756 Bytes
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
/**
* Created by axetroy on 17-3-10.
*/
const process = require('process');
const path = require('path');
const co = require('co');
const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs-extra'));
function existDir(dir) {
return fs.readdirAsync(dir).then(() => Promise.resolve(true), () => Promise.resolve(false));
}
function clearNodeModule(done) {
const cwd = process.cwd();
const NODE_MODULES = path.join(cwd, 'node_modules');
co(function *() {
const existNodeModules = yield existDir(NODE_MODULES);
if (existNodeModules == true) {
yield fs.emptyDirAsync(NODE_MODULES);
yield fs.removeAsync(NODE_MODULES);
}
done();
}).catch((err) => done(err));
}
exports.foreach = clearNodeModule;