Skip to content

Instantly share code, notes, and snippets.

@Chris2011
Created September 5, 2019 07:14
Show Gist options
  • Save Chris2011/55e09b55339023270d54e93fc88b6e59 to your computer and use it in GitHub Desktop.
Save Chris2011/55e09b55339023270d54e93fc88b6e59 to your computer and use it in GitHub Desktop.
create version file.
const git = require('git-rev'),
package = require('./package.json'),
fs = require('fs');
console.log('\n------------------- create version.json file -------------------\n');
Promise.all([
new Promise((resolve, reject) => {
git.short(hash => {
if(hash) {
resolve(hash);
} else {
reject('git short hash could not be read');
}
});
}),
new Promise((resolve, reject) => {
git.long(hash => {
if(hash) {
resolve(`${package.version}_${hash}`);
} else {
reject('git long hash could not be read');
}
});
}),
new Promise((resolve, reject) => {
git.branch(branch => {
if(branch) {
resolve(branch);
} else {
reject('git branch could not be read');
}
});
}),
new Promise((resolve, reject) => {
git.tag(tag => {
if(tag) {
resolve(tag);
} else {
reject('git tag could not be read');
}
});
})
]).then(data => {
const [short, version, branch, tag] = data,
result = JSON.stringify({
application: package.name,
version,
short,
branch,
tag,
buildTime: new Date()
});
console.log(result);
fs.writeFile('./dist/version.json', result, 'utf-8', err => {
if(err) {
throw err;
}
console.log('\n------------------- version.json created -------------------\n');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment