Created
December 31, 2017 09:58
-
-
Save radu-matei/8b3e981e533bde0595a5bcfd03e52235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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