-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgit.version.ts
30 lines (24 loc) · 903 Bytes
/
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
import { writeFileSync } from 'fs'
import { dedent } from 'tslint/lib/utils'
const util = require('util')
const exec = util.promisify(require('child_process').exec)
async function createVersionsFile(filename: string) {
const revision = (await exec('git rev-parse --short HEAD')).stdout
.toString()
.trim()
const branch = (await exec('git rev-parse --abbrev-ref HEAD')).stdout
.toString()
.trim()
console.log(
`version: '${process.env.npm_package_version}', revision: '${revision}', branch: '${branch}'`
)
const content = dedent`
// this file is automatically generated by git.version.ts script
export const versions = {
version: '${process.env.npm_package_version}',
revision: '${revision}',
branch: '${branch}'
}`
writeFileSync(filename, content, { encoding: 'utf8' })
}
createVersionsFile('src/environments/versions.ts')