|
|
|
@ -5,18 +5,22 @@ 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();
|
|
|
|
|
let versionInfo = ''
|
|
|
|
|
if(process.env.GIT_VERSION){
|
|
|
|
|
versionInfo = process.env.GIT_VERSION
|
|
|
|
|
} else {
|
|
|
|
|
const tag = (await exec('git describe --tags')).stdout.toString().trim();
|
|
|
|
|
const branch = (await exec('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();
|
|
|
|
|
|
|
|
|
|
versionInfo = (branch === 'master' ? tag : branch + '#' + tag)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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}'
|
|
|
|
|
export const versionInfo = {
|
|
|
|
|
version: '${versionInfo}',
|
|
|
|
|
};`;
|
|
|
|
|
|
|
|
|
|
writeFileSync(filename, content, {encoding: 'utf8'});
|
|
|
|
|