-
Notifications
You must be signed in to change notification settings - Fork 16
/
git.version.ts
43 lines (35 loc) · 1.29 KB
/
git.version.ts
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
import fs = require('fs');
import {combineLatest as observableCombineLatest, Observable } from 'rxjs';
const exec = require('child_process').exec;
const revision$ = new Observable<string>(s => {
exec('git rev-parse --short HEAD',
function(error: Error, stdout: Buffer, stderr: Buffer) {
if (error !== null) {
console.log('git error: ' + error + stderr);
}
s.next(stdout.toString().trim());
s.complete();
});
});
const tag$ = new Observable<string>(s => {
exec('git describe --tag',
function(error: Error, stdout: Buffer, stderr: Buffer) {
if (error !== null) {
console.log('git error: ' + error + stderr);
}
s.next(stdout.toString().trim());
s.complete();
});
});
observableCombineLatest(revision$, tag$)
.subscribe(([revision, tag]) => {
const webservice_version = process.env.npm_package_config_webservice_version;
console.log(`tag: '${tag}', version: '${webservice_version}', revision: '${revision}'`);
const content = '// this file is automatically generated by git.version.ts script\n' +
`export const versions = {tag: '${tag}', version: '${webservice_version}', revision: '${revision}'};\n`;
fs.writeFileSync(
'src/app/footer/versions.ts',
content,
{ encoding: 'utf8' }
);
});