-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclean.js
75 lines (63 loc) · 2.15 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var fs = require('fs');
// Copy a directory
function copyDirectory(src, target, appendFl) {
// See if the target exists
if (fs.existsSync(target)) {
// Delete the target if we aren't appending files to it
appendFl != true ? deleteDirectory(target) : null;
}
// Create the directory
fs.mkdirSync(target);
// 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;
var targetPath = target + "/" + item;
// See if this is a directory
if (fs.lstatSync(srcPath).isDirectory()) {
// Create the directory
fs.mkdirSync(targetPath);
// Copy the folder recursively
copyDirectory(srcPath, targetPath);
} else {
// Ensure we don't overwrite files
if (appendFl != true || fs.existsSync(targetPath) == false) {
// 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 folders
deleteDirectory("./build");
deleteDirectory("./dist");
deleteDirectory("./docs");
deleteDirectory("./src/icons");
// Copy the icons
copyDirectory("./node_modules/gd-bs/src/icons", "./src/icons");
// Log
console.log("Successfully cleaned the library");