-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (58 loc) · 1.4 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
var fs = require('fs');
var path = require('path');
exports.checkDirExists = function (dir) {
var st;
try {
st = fs.statSync(dir);
} catch (e) {
if (e.code && e.code === 'ENOENT') {
return false;
}
throw e;
}
if (st.isDirectory()) {
return true;
}
throw new Error('Inconsistency concerned with ' + dir);
};
exports.mkdirSync = function (fPath) {
try {
fs.mkdirSync(fPath);
} catch (e) {}
};
exports.rmDir = function (dir, removeSelf) {
var files;
try {
files = fs.readdirSync(dir);
} catch (e) {
return;
}
if (files.length > 0) {
for (var i = 0; i < files.length; i++) {
var filePath = path.join(dir, files[i]);
var fData = fs.lstatSync(filePath);
//try {
if (fData.isSymbolicLink()) {
fs.unlinkSync(filePath);
}
if (fData.isFile()) {
fs.unlinkSync(filePath);
}
//} catch (e) {
//
//}
if (fData.isDirectory()) {
exports.rmDir(filePath, true);
}
}
}
if (removeSelf) {
fs.rmdirSync(dir);
}
};
exports.rmDirs = function (dirs, removeSelf) {
for (var i = 0, len = dirs.length; i < len; i++) {
exports.rmDir(dirs[i], removeSelf);
}
};