|
@@ -5,23 +5,40 @@ const path = require("path");
|
5
|
5
|
const versionFile = path.join("build", "version.json");
|
6
|
6
|
const indexFile = path.join("build", "index.html");
|
7
|
7
|
|
8
|
|
-const zero = (digit) => `0${digit}`.slice(-2);
|
9
|
|
-
|
10
|
|
-const versionDate = (date) => {
|
11
|
|
- const date_ = `${date.getFullYear()}-${zero(date.getMonth() + 1)}-${zero(
|
12
|
|
- date.getDate(),
|
13
|
|
- )}`;
|
14
|
|
- const time = `${zero(date.getHours())}-${zero(date.getMinutes())}-${zero(
|
15
|
|
- date.getSeconds(),
|
16
|
|
- )}`;
|
17
|
|
- return `${date_}-${time}`;
|
|
8
|
+const versionDate = (date) => date.toISOString().replace(".000", "");
|
|
9
|
+
|
|
10
|
+const commitHash = () => {
|
|
11
|
+ try {
|
|
12
|
+ return require("child_process")
|
|
13
|
+ .execSync("git rev-parse --short HEAD")
|
|
14
|
+ .toString()
|
|
15
|
+ .trim();
|
|
16
|
+ } catch {
|
|
17
|
+ return "none";
|
|
18
|
+ }
|
18
|
19
|
};
|
19
|
20
|
|
20
|
|
-const now = new Date();
|
|
21
|
+const commitDate = (hash) => {
|
|
22
|
+ try {
|
|
23
|
+ const unix = require("child_process")
|
|
24
|
+ .execSync(`git show -s --format=%ct ${hash}`)
|
|
25
|
+ .toString()
|
|
26
|
+ .trim();
|
|
27
|
+ const date = new Date(parseInt(unix) * 1000);
|
|
28
|
+ return versionDate(date);
|
|
29
|
+ } catch {
|
|
30
|
+ return versionDate(new Date());
|
|
31
|
+ }
|
|
32
|
+};
|
|
33
|
+
|
|
34
|
+const getFullVersion = () => {
|
|
35
|
+ const hash = commitHash();
|
|
36
|
+ return `${commitDate(hash)}-${hash}`;
|
|
37
|
+};
|
21
|
38
|
|
22
|
39
|
const data = JSON.stringify(
|
23
|
40
|
{
|
24
|
|
- version: versionDate(now),
|
|
41
|
+ version: getFullVersion(),
|
25
|
42
|
},
|
26
|
43
|
undefined,
|
27
|
44
|
2,
|
|
@@ -34,7 +51,7 @@ fs.readFile(indexFile, "utf8", (error, data) => {
|
34
|
51
|
if (error) {
|
35
|
52
|
return console.error(error);
|
36
|
53
|
}
|
37
|
|
- const result = data.replace(/{version}/g, versionDate(now));
|
|
54
|
+ const result = data.replace(/{version}/g, getFullVersion());
|
38
|
55
|
|
39
|
56
|
fs.writeFile(indexFile, result, "utf8", (error) => {
|
40
|
57
|
if (error) {
|