26 lines
690 B
Java
26 lines
690 B
Java
const {spawnSync} = require('child_process');
|
|
|
|
const resolveVersion = () => {
|
|
const exec = (cmd, ...args) => {
|
|
const pr = spawnSync(cmd, args, {
|
|
timeout: 6000
|
|
});
|
|
|
|
return pr.error ? null : pr.stdout.toString('utf-8').trim();
|
|
};
|
|
|
|
const totalCommits = exec('git', 'rev-list', '--count', 'HEAD');
|
|
const lastTag = exec('git', 'describe', '--tags', '--abbrev=0');
|
|
|
|
if (lastTag) {
|
|
const commitsFromTag = exec('git', 'rev-list', '--count', lastTag);
|
|
return `${lastTag}.${totalCommits - commitsFromTag}`;
|
|
} else {
|
|
|
|
// No tags so far
|
|
return `0.0.0.${totalCommits}`;
|
|
}
|
|
};
|
|
|
|
console.log(resolveVersion());
|