react/shells/utils.js

32 lines
784 B
JavaScript
Raw Normal View History

2019-04-12 09:44:44 +08:00
const { execSync } = require('child_process');
const { readFileSync } = require('fs');
const { resolve } = require('path');
function getGitCommit() {
return execSync('git show -s --format=%h')
.toString()
.trim();
}
2019-04-12 09:44:44 +08:00
function getGitHubURL() {
// TODO potentially replac this with an fb.me URL (if it can forward the query params)
return execSync('git remote get-url origin')
.toString()
.trim()
.replace(':', '/')
.replace('git@', 'https://')
.replace('.git', '');
}
function getVersionString() {
const packageVersion = JSON.parse(
readFileSync(resolve(__dirname, '../package.json'))
).version;
const commit = getGitCommit();
2019-04-12 09:44:44 +08:00
return `${packageVersion}-${commit}`;
}
module.exports = { getGitCommit, getGitHubURL, getVersionString };