version.js
1.33 KB
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
const child_process = require("child_process");
// git 最后一次提交的 Head
const commit = child_process
.execSync("git show -s --format=%H")
.toString()
.trim();
// const commitUserName = child_process.execSync('git show -s --format=%cn').toString().trim()
// const commitUserMail = child_process.execSync('git show -s --format=%ce').toString().trim()
const commitDateObj = new Date(
child_process.execSync(`git show -s --format=%cd`).toString()
);
const commitDate = `${commitDateObj.getFullYear() +
"-" +
(commitDateObj.getMonth() + 1) +
"-" +
commitDateObj.getDate() +
" " +
commitDateObj.getHours() +
":" +
commitDateObj.getMinutes()}`;
// const buildUserName = child_process.execSync('git config user.name').toString().trim()
// const buildUserMail = child_process.execSync('git config user.email').toString().trim()
const info = child_process
.execSync("git show -s --format=%s")
.toString()
.trim();
const versionarr = child_process
.execSync("git tag -l")
.toString()
.trim()
.split("\n");
const version = versionarr[versionarr.length - 1];
const nowDate = new Date();
const buildDate = `${nowDate.getFullYear() +
"-" +
(nowDate.getMonth() + 1) +
"-" +
nowDate.getDate() +
" " +
nowDate.getHours() +
":" +
nowDate.getMinutes()}`;
module.exports = { commit, commitDate, buildDate, version, info };