-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.build-info.generate.js
48 lines (43 loc) · 1.06 KB
/
.build-info.generate.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
const dayjs = require('dayjs');
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() ?? dayjs().format('YYYY-MM-DD'),
version: `${getCommitHashShort() ?? 'No commit'} - ${dayjs().format()}`,
commit: getCommitHash() ?? 'No commit',
date: dayjs().format(),
};
};
const generateAppBuild = () => {
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();