-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.build-info.ts
47 lines (43 loc) · 1.03 KB
/
.build-info.ts
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
const fs = require("fs");
const getContent = () => {
const getCommitHashShort = () => {
try {
return require("child_process")
.execSync("git rev-parse --short HEAD")
.toString()
.trim();
} catch (error) {
return null;
}
};
const getCommitHash = () => {
try {
return require("child_process")
.execSync("git rev-parse HEAD")
.toString()
.trim();
} catch (error) {
return null;
}
};
return {
display: getCommitHashShort() ?? new Date(),
version: `${getCommitHashShort() ?? "No commit"} - ${new Date()}`,
commit: getCommitHash() ?? "No commit",
date: new Date(),
};
};
const generateAppBuild = () => {
console.log("building...\n");
try {
fs.writeFileSync(
"./.build-info.json",
JSON.stringify(getContent(), null, 2)
);
console.log("✅ Generate `.build-info.json`");
} catch (error) {
console.error(error);
throw new Error("❌ Failed to generate `.build-info.json`");
}
};
generateAppBuild();