forked from gunjandatta/sprest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.js
60 lines (50 loc) · 1.62 KB
/
clean.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
var fs = require('fs');
// Copy a directory
function copyDirectory(src, target) {
// Delete the target
deleteDirectory(target);
// Ensure the directory exists
if (fs.existsSync(src) && fs.lstatSync(src).isDirectory()) {
// Create the directory
fs.mkdirSync(target);
// Get each item in the directory
fs.readdirSync(src).forEach(function (item) {
var srcPath = src + "/" + item;
var targetPath = target + "/" + item;
// See if this is a directory
if (fs.lstatSync(srcPath).isDirectory()) {
// Copy the folder recursively
copyDirectory(srcPath, targetPath);
} else {
// Copy the file
fs.copyFileSync(srcPath, targetPath);
}
});
}
}
// Deletes a directory
function deleteDirectory(src) {
// Ensure the directory exists
if (fs.existsSync(src) && fs.lstatSync(src).isDirectory()) {
// Get each item in the directory
fs.readdirSync(src).forEach(function (item) {
var srcPath = src + "/" + item;
// See if this is a directory
if (fs.lstatSync(srcPath).isDirectory()) {
// Delete the folder recursively
deleteDirectory(srcPath);
} else {
// Delete the file
fs.unlinkSync(srcPath);
}
});
// Delete the directory
fs.rmdirSync(src);
}
};
// Log
console.log("Cleaning the files...");
// Delete the folder
deleteDirectory("./build");
// Log
console.log("Successfully cleaned the library");