forked from water-fountains/datablue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.version.js
40 lines (33 loc) · 1.34 KB
/
git.version.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
/*
* @license
* (c) Copyright 2019 | MY-D Foundation | Created by Matthew Moy de Vitry
* Use of this code is governed by the GNU Affero General Public License (https://www.gnu.org/licenses/agpl-3.0)
* and the profit contribution agreement available at https://www.my-d.org/ProfitContributionAgreement
*/
const writeFileSync = require('fs').writeFileSync;
const util = require('util');
const exec = util.promisify(require('child_process').exec);
async function createVersionsFile(filename) {
const revision = (await exec('git rev-parse --short HEAD')).stdout.toString().trim();
const branch = (await exec('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();
const version = (await exec('git tag -l HEAD')).stdout.toString().trim();
const commit_time = (await exec('git log --format="%ai" -n1 HEAD')).stdout.toString().trim();
console.log(
`version: '${version}',
revision: '${revision}',
branch: '${branch}',
time: '${commit_time}'`
);
const content = `// this file is automatically generated by git.version.js script
const buildInfo = {
version: '${version}',
revision: '${revision}',
branch: '${branch}',
commit_time: '${commit_time}',
build_time: '${new Date()}',
};
export default buildInfo;
`;
writeFileSync(filename, content, { encoding: 'utf8' });
}
createVersionsFile('server/common/build.info.ts');