-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit.version.ts
More file actions
41 lines (35 loc) · 1.29 KB
/
Copy pathgit.version.ts
File metadata and controls
41 lines (35 loc) · 1.29 KB
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
32
33
34
35
36
37
38
39
40
41
import {writeFileSync} from 'fs';
import {promisify} from 'util';
import * as child from 'child_process';
const exec = promisify(child.exec);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const moment = require('moment');
/**
* Creates App version file
*/
async function createVersionsFile(filename: string) {
let revision = process.env.HEROKU_SLUG_DESCRIPTION;
if (revision) {
revision = revision.replace('Deploy ', '');
}
let branch = process.env.NODE_ENV;
try {
revision = (await exec('git rev-parse --short HEAD')).stdout.toString().trim();
branch = (await exec('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();
} catch (e) {
console.error(e);
}
console.log(` 🚀 Version: '${process.env.npm_package_version}', revision: '${revision}', branch: '${branch}'`);
const content = `
/* tslint:disable */
// This file was auto-generated with git.version.ts script
export const versions = {
version: '${process.env.npm_package_version}',
revision: '${revision}',
branch: '${branch}',
buildDate: '${moment().format('YYYYMMDD')}',
buildNumber: '${moment().format('HHmm')}'
};`;
writeFileSync(filename, content, {encoding: 'utf8'});
}
createVersionsFile('src/versions.ts').then();