From 9a0cf68a4d609a571d8840fada2e2e2d85a426bf Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 11 Apr 2019 18:44:44 -0700 Subject: [PATCH] Add Git revision to build version --- shells/browser/shared/build.js | 8 +++++-- shells/browser/shared/webpack.backend.js | 15 +++---------- shells/browser/shared/webpack.config.js | 15 +++---------- shells/dev/webpack.config.js | 17 +++------------ shells/utils.js | 27 ++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 40 deletions(-) create mode 100644 shells/utils.js diff --git a/shells/browser/shared/build.js b/shells/browser/shared/build.js index 846f739670..2a6929feeb 100644 --- a/shells/browser/shared/build.js +++ b/shells/browser/shared/build.js @@ -32,7 +32,9 @@ const build = async (tempPath, manifestPath) => { `${webpackPath} --config webpack.config.js --output-path ${binPath}`, { cwd: __dirname, - env: Object.assign({}, process.env, { NODE_ENV: 'production' }), + env: Object.assign({}, process.env, { + NODE_ENV: 'production', + }), stdio: 'inherit', } ); @@ -40,7 +42,9 @@ const build = async (tempPath, manifestPath) => { `${webpackPath} --config webpack.backend.js --output-path ${binPath}`, { cwd: __dirname, - env: Object.assign({}, process.env, { NODE_ENV: 'production' }), + env: Object.assign({}, process.env, { + NODE_ENV: 'production', + }), stdio: 'inherit', } ); diff --git a/shells/browser/shared/webpack.backend.js b/shells/browser/shared/webpack.backend.js index 08ffeaa92c..b5f6ef58c5 100644 --- a/shells/browser/shared/webpack.backend.js +++ b/shells/browser/shared/webpack.backend.js @@ -1,21 +1,12 @@ -const { execSync } = require('child_process'); const { readFileSync } = require('fs'); const { resolve } = require('path'); const { DefinePlugin } = require('webpack'); +const { getGitHubURL, getVersionString } = require('../../utils'); const __DEV__ = process.env.NODE_ENV !== 'production'; -// TODO potentially replac this with an fb.me URL (if it can forward the query params) -const GITHUB_URL = execSync('git remote get-url origin') - .toString() - .trim() - .replace(':', '/') - .replace('git@', 'https://') - .replace('.git', ''); - -const DEVTOOLS_VERSION = JSON.parse( - readFileSync(resolve(__dirname, '../../../package.json')) -).version; +const GITHUB_URL = getGitHubURL(); +const DEVTOOLS_VERSION = getVersionString(); module.exports = { mode: __DEV__ ? 'development' : 'production', diff --git a/shells/browser/shared/webpack.config.js b/shells/browser/shared/webpack.config.js index 2e59d3853c..9e510d4b5f 100644 --- a/shells/browser/shared/webpack.config.js +++ b/shells/browser/shared/webpack.config.js @@ -1,22 +1,13 @@ -const { execSync } = require('child_process'); const { readFileSync } = require('fs'); const { resolve } = require('path'); const { DefinePlugin } = require('webpack'); +const { getGitHubURL, getVersionString } = require('../../utils'); const NODE_ENV = process.env.NODE_ENV; const __DEV__ = NODE_ENV !== 'production'; -// TODO potentially replac this with an fb.me URL (if it can forward the query params) -const GITHUB_URL = execSync('git remote get-url origin') - .toString() - .trim() - .replace(':', '/') - .replace('git@', 'https://') - .replace('.git', ''); - -const DEVTOOLS_VERSION = JSON.parse( - readFileSync(resolve(__dirname, '../../../package.json')) -).version; +const GITHUB_URL = getGitHubURL(); +const DEVTOOLS_VERSION = getVersionString(); module.exports = { mode: __DEV__ ? 'development' : 'production', diff --git a/shells/dev/webpack.config.js b/shells/dev/webpack.config.js index 1b66e06880..e84144a08c 100644 --- a/shells/dev/webpack.config.js +++ b/shells/dev/webpack.config.js @@ -1,23 +1,12 @@ -const { execSync } = require('child_process'); const { readFileSync } = require('fs'); const { resolve } = require('path'); const { DefinePlugin } = require('webpack'); +const { getGitHubURL, getVersionString } = require('../utils'); const __DEV__ = process.env.NODE_ENV !== 'production'; -// TODO potentially replac this with an fb.me URL (if it can forward the query params) -const GITHUB_URL = execSync('git remote get-url origin') - .toString() - .trim() - .replace(':', '/') - .replace('git@', 'https://') - .replace('.git', ''); - -const DEVTOOLS_VERSION = JSON.parse( - readFileSync(resolve(__dirname, '../../package.json')) -).version; - -// TODO Share Webpack configs like alias +const GITHUB_URL = getGitHubURL(); +const DEVTOOLS_VERSION = getVersionString(); module.exports = { mode: 'development', diff --git a/shells/utils.js b/shells/utils.js new file mode 100644 index 0000000000..8f0d875d32 --- /dev/null +++ b/shells/utils.js @@ -0,0 +1,27 @@ +const { execSync } = require('child_process'); +const { readFileSync } = require('fs'); +const { resolve } = require('path'); + +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 = execSync('git show -s --format=%h') + .toString() + .trim(); + + return `${packageVersion}-${commit}`; +} + +module.exports = { getGitHubURL, getVersionString };