Files
scrutiny/webapp/frontend/git.version.ts
T
Jason Kulatunga d93d24b52d using npm run commands for building angular application (supports pre steps).
Automatically embed the application version in the UI.
2022-05-26 22:37:45 -07:00

26 lines
963 B
TypeScript

import { writeFileSync } from 'fs';
import { dedent } from 'tslint/lib/utils';
import { promisify } from 'util';
import * as child from 'child_process';
const exec = promisify(child.exec);
async function createVersionsFile(filename: string) {
const tag = (await exec('git describe --tags')).stdout.toString().trim();
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: '${tag}',
revision: '${revision}',
branch: '${branch}'
};`;
writeFileSync(filename, content, {encoding: 'utf8'});
}
createVersionsFile('src/environments/versions.ts');