forked from AiursoftWeb/Kahla.App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.ts
31 lines (27 loc) · 1.09 KB
/
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
import fs = require('fs');
import { Observable, combineLatest } from 'rxjs/';
const exec = require('child_process').exec;
const revision = new Observable<string>(s => {
exec('git rev-parse HEAD',
function (error: Error, stdout: Buffer, stderr: Buffer) {
if (error !== null) {
console.log('git error: ' + error + stderr);
}
s.next(stdout.toString().trim());
s.complete();
});
});
combineLatest(revision)
// tslint:disable-next-line:no-shadowed-variable
.subscribe(([revision]) => {
console.log(`version: '${process.env.npm_package_version}', revision: '${revision}'`);
const today = new Date().toISOString().slice(0, 10);
const content = '// this file is automatically generated by version.ts script\n' +
`export const versions = {version: '${process.env.npm_package_version}', revision: '${revision
}', buildTime: '${today}'};\n`;
fs.writeFileSync(
'src/environments/versions.ts',
content,
{ encoding: 'utf8' }
);
});