Skip to content

Instantly share code, notes, and snippets.

@radu-matei
Created December 31, 2017 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radu-matei/8b3e981e533bde0595a5bcfd03e52235 to your computer and use it in GitHub Desktop.
Save radu-matei/8b3e981e533bde0595a5bcfd03e52235 to your computer and use it in GitHub Desktop.
import fs = require('fs');
import { Observable } from 'rxjs';
let exec = require('child_process').exec;
const git_commit = 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();
});
});
const sem_ver = new Observable<string>(s => {
exec('git tag | tail -n1',
function (error: Error, stdout: Buffer, stderr: Buffer) {
if (error !== null) {
console.log('git error: ' + error + stderr);
}
s.next(stdout.toString().trim());
s.complete();
});
});
Observable
.combineLatest(git_commit, sem_ver)
.subscribe(([revision, branch]) => {
console.log(`git commit: '${git_commit}', sem ver: '${sem_ver}'`);
const content = '// this file is automatically generated by git.version.ts script\n' +
`export const git_commit: '${git_commit}', sem_ver: '${sem_ver}'};`;
fs.writeFileSync(
'src/environments/versions.ts',
content,
{encoding: 'utf8'}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment