forked from water-fountains/proximap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.version.js
32 lines (25 loc) · 1.11 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
const writeFileSync = require('fs').writeFileSync;
const { dedent } = require('tslint/lib/utils');
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 = dedent`
// this file is automatically generated by git.version.ts script
export const versions = {
version: '${version}',
revision: '${revision}',
branch: '${branch}',
commit_time: '${commit_time}',
build_time: '${new Date()}'
};`;
writeFileSync(filename, content, {encoding: 'utf8'});
}
createVersionsFile('src/environments/versions.ts');