UNPKG

@onereach/get-version-data

Version:
33 lines (27 loc) 861 B
'use strict'; const shell = require('shelljs'); module.exports = { async getBranch () { return await this._exec('git rev-parse --abbrev-ref HEAD'); }, async getCommitHash () { return await this._exec('git rev-parse HEAD'); }, async getAllBundleTags () { await this._exec('git fetch --tags --force'); const tags = await this._exec('git tag -l --points-at HEAD'); const tagsArr = tags.split('\n'); return tagsArr.filter(tag => tag.startsWith('bundle')); }, async getIsDirty () { return await this._exec(`git diff --quiet && echo 'true' || echo 'false'`) !== 'true'; }, async _exec(command) { return new Promise((resolve, reject) => { shell.exec(command, {silent: true}, (code, stdout, stderr) => { if (code === 0) resolve(stdout.trim()); else reject(stderr); }); }) } }