react/packages/react-devtools-extensions/utils.js

40 lines
940 B
JavaScript
Raw Normal View History

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