/
prebuild.ts
27 lines (23 loc) · 932 Bytes
/
prebuild.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
import * as fs from 'fs';
import { Observable } from 'rxjs/';
const exec = require('child_process').exec;
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();
});
}).subscribe((revision: string) => {
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' }
);
});