Created
September 5, 2019 07:14
-
-
Save Chris2011/55e09b55339023270d54e93fc88b6e59 to your computer and use it in GitHub Desktop.
create version file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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