-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathonBuild.js
36 lines (31 loc) · 878 Bytes
/
onBuild.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
const fs = require("fs");
const util = require("util");
const md5 = require("md5");
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
let hashJs;
const readJsFile = () => {
return readFile("public/index.js", (err, data) => {
if (err) console.log(err);
});
};
readJsFile()
.then((data) => {
hashJs = md5(data).slice(0, 16);
console.log(hashJs);
})
.then(() => {
const versionObject = {
js: hashJs,
};
writeFile("src/_data/version.json", JSON.stringify(versionObject), (err) => {
if (err) throw err;
console.log("The file has been saved!");
});
})
.then(() => {
fs.rename("public/index.js", `public/index${hashJs}.js`, function (err) {
if (err) return console.log("ERROR: " + err);
console.log(`public/index.js > public/index${hashJs}.js`);
});
});