-
Notifications
You must be signed in to change notification settings - Fork 9
/
git.version.js
37 lines (30 loc) · 1.3 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
/*
* @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.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');