-
Notifications
You must be signed in to change notification settings - Fork 0
/
bust.js
71 lines (59 loc) · 1.78 KB
/
bust.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
const fs = require("fs-extra");
// console.log("__dirname: ", __dirname);
let formatNum = function (num, len) {
let str = num.toString(10);
let sl = str.length;
if (sl < len) return "0".repeat(len - sl) + str;
return str;
};
var d = new Date();
var key =
formatNum(d.getFullYear(), 4) +
formatNum(d.getMonth() + 1, 2) +
formatNum(d.getDate(), 2) +
"-" +
formatNum(d.getHours(), 2) +
formatNum(d.getMinutes(), 2) +
formatNum(d.getSeconds(), 2);
console.log("Key: ", key);
var bundleName = "bundle-" + key;
fs.ensureDirSync(".\\public-busted");
fs.emptyDirSync(".\\public-busted");
fs.ensureDirSync(".\\public-busted\\build");
fs.readFile(".\\public\\index.html", "utf8")
.then((a) => {
return a
.replace(/bundle\.css/g, bundleName + ".css")
.replace(/bundle\.js/g, bundleName + ".js");
})
.then((a) => {
fs.writeFile(".\\public-busted\\index.html", a, "utf8");
});
fs.readFile(".\\public\\build\\bundle.css", "utf8")
.then((a) => {
return a.replace(/bundle\.css/g, bundleName + ".css");
})
.then((a) => {
fs.writeFile(".\\public-busted\\build\\" + bundleName + ".css", a, "utf8");
});
fs.readFile(".\\public\\build\\bundle.css.map", "utf8")
.then((a) => {
return a.replace(/bundle\.css/g, bundleName + ".css");
})
.then((a) => {
fs.writeFile(".\\public-busted\\build\\" + bundleName + ".css.map", a, "utf8");
});
fs.readFile(".\\public\\build\\bundle.js", "utf8")
.then((a) => {
return a.replace(/bundle\.js/g, bundleName + ".js");
})
.then((a) => {
fs.writeFile(".\\public-busted\\build\\" + bundleName + ".js", a, "utf8");
});
fs.readFile(".\\public\\build\\bundle.js.map", "utf8")
.then((a) => {
return a.replace(/bundle\.js/g, bundleName + ".js");
})
.then((a) => {
fs.writeFile(".\\public-busted\\build\\" + bundleName + ".js.map", a, "utf8");
});