Skip to content

Instantly share code, notes, and snippets.

@amcdnl
Created February 13, 2018 16:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amcdnl/facf888edd18b9baa552735129d4c23d to your computer and use it in GitHub Desktop.
Save amcdnl/facf888edd18b9baa552735129d4c23d to your computer and use it in GitHub Desktop.
const { gitDescribeSync } = require('git-describe');
const { version } = require('../package.json');
const { resolve, relative } = require('path');
const { writeFileSync } = require('fs-extra');
const gitInfo = gitDescribeSync({
dirtyMark: false,
dirtySemver: false
});
gitInfo.version = version;
const file = resolve(__dirname, '..', 'src', 'environments', 'version.ts');
writeFileSync(file,
`// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
/* tslint:disable */
export const VERSION = ${JSON.stringify(gitInfo, null, 4)};
/* tslint:enable */
`, { encoding: 'utf-8' });
console.log(`Wrote version info ${gitInfo.raw} to ${relative(resolve(__dirname, '..'), file)}`);
@mackelito
Copy link

mackelito commented Sep 26, 2018

Love this! :)
But just encountered a problem when trying to deploy using docker image "alexsuch/angular-cli"
The git-describe relays on git in system path's so we're getting but will try a similar approach using some other like last-commit (https://github.com/seymen/git-last-commit) or other..

$ node version.js
/builds/fodi/fodi-market/node_modules/git-describe/lib/git-describe.js:70
            stderr.toString().trim();
                   ^

TypeError: Cannot read property 'toString' of null

@mackelito
Copy link

Oh by the way... perhaps you should add a link to the article as well? to make it easier to find :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment