Skip to content

Instantly share code, notes, and snippets.

@rigelk
Created October 3, 2018 12:16
Show Gist options
  • Save rigelk/5fb764856a56dfce96925f797943ff3d to your computer and use it in GitHub Desktop.
Save rigelk/5fb764856a56dfce96925f797943ff3d to your computer and use it in GitHub Desktop.
getVersion
async function getVersion () {
const tag = await require('child_process')
.exec('[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', { stdio: [0,1,2] })
if (tag) return tag.replace(/^v/, '')
const version = await require('child_process')
.exec('[ ! -d .git ] || git rev-parse --short HEAD')
if (version) return version.toString().trim()
return require('../../../package.json').version
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment