2020-02-28 22:51:36 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2020-12-18 13:02:29 +01:00
|
|
|
const versionFile = path.join("build", "version.json");
|
|
|
|
const indexFile = path.join("build", "index.html");
|
2020-02-28 22:51:36 +01:00
|
|
|
|
2020-03-23 12:05:07 +01:00
|
|
|
const zero = (digit) => `0${digit}`.slice(-2);
|
2020-02-28 22:51:36 +01:00
|
|
|
|
2020-03-23 12:05:07 +01:00
|
|
|
const versionDate = (date) => {
|
2020-02-28 22:51:36 +01:00
|
|
|
const date_ = `${date.getFullYear()}-${zero(date.getMonth() + 1)}-${zero(
|
|
|
|
date.getDate(),
|
|
|
|
)}`;
|
|
|
|
const time = `${zero(date.getHours())}-${zero(date.getMinutes())}-${zero(
|
|
|
|
date.getSeconds(),
|
|
|
|
)}`;
|
|
|
|
return `${date_}-${time}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
const now = new Date();
|
|
|
|
|
|
|
|
const data = JSON.stringify(
|
|
|
|
{
|
|
|
|
version: versionDate(now),
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
2,
|
|
|
|
);
|
|
|
|
|
2020-12-18 13:02:29 +01:00
|
|
|
fs.writeFileSync(versionFile, data);
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/14181136/8418
|
|
|
|
fs.readFile(indexFile, "utf8", (error, data) => {
|
|
|
|
if (error) {
|
|
|
|
return console.error(error);
|
|
|
|
}
|
|
|
|
const result = data.replace(/{version}/g, versionDate(now));
|
|
|
|
|
|
|
|
fs.writeFile(indexFile, result, "utf8", (error) => {
|
|
|
|
if (error) {
|
|
|
|
return console.error(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|