Add Git revision to build version
Brian Vaughn committed
Apr 11, 2019 at 18:44 UTC
9a0cf68a4d609a571d8840fada2e2e2d85a426bf
5 files changed
+42
-40
shells/browser/shared/build.js
+6
-2
@@ -32,7 +32,9 @@ const build = async (tempPath, manifestPath) => {
32
`${webpackPath} --config webpack.config.js --output-path ${binPath}`,
33
{
34
cwd: __dirname,
35
- env: Object.assign({}, process.env, { NODE_ENV: 'production' }),
35
+ env: Object.assign({}, process.env, {
36
+ NODE_ENV: 'production',
37
+ }),
38
stdio: 'inherit',
39
}
40
);
@@ -40,7 +42,9 @@ const build = async (tempPath, manifestPath) => {
42
`${webpackPath} --config webpack.backend.js --output-path ${binPath}`,
43
{
44
cwd: __dirname,
43
- env: Object.assign({}, process.env, { NODE_ENV: 'production' }),
45
+ env: Object.assign({}, process.env, {
46
+ NODE_ENV: 'production',
47
+ }),
48
stdio: 'inherit',
49
}
50
);
shells/browser/shared/webpack.backend.js
+3
-12
@@ -1,21 +1,12 @@
1
-const { execSync } = require('child_process');
1
const { readFileSync } = require('fs');
2
const { resolve } = require('path');
3
const { DefinePlugin } = require('webpack');
4
+const { getGitHubURL, getVersionString } = require('../../utils');
5
6
const __DEV__ = process.env.NODE_ENV !== 'production';
7
8
-// TODO potentially replac this with an fb.me URL (if it can forward the query params)
9
-const GITHUB_URL = execSync('git remote get-url origin')
10
- .toString()
11
- .trim()
12
- .replace(':', '/')
13
- .replace('git@', 'https://')
14
- .replace('.git', '');
15
-
16
-const DEVTOOLS_VERSION = JSON.parse(
17
- readFileSync(resolve(__dirname, '../../../package.json'))
18
-).version;
8
+const GITHUB_URL = getGitHubURL();
9
+const DEVTOOLS_VERSION = getVersionString();
10
11
module.exports = {
12
mode: __DEV__ ? 'development' : 'production',
shells/browser/shared/webpack.config.js
+3
-12
@@ -1,22 +1,13 @@
1
-const { execSync } = require('child_process');
1
const { readFileSync } = require('fs');
2
const { resolve } = require('path');
3
const { DefinePlugin } = require('webpack');
4
+const { getGitHubURL, getVersionString } = require('../../utils');
5
6
const NODE_ENV = process.env.NODE_ENV;
7
const __DEV__ = NODE_ENV !== 'production';
8
9
-// TODO potentially replac this with an fb.me URL (if it can forward the query params)
10
-const GITHUB_URL = execSync('git remote get-url origin')
11
- .toString()
12
- .trim()
13
- .replace(':', '/')
14
- .replace('git@', 'https://')
15
- .replace('.git', '');
16
-
17
-const DEVTOOLS_VERSION = JSON.parse(
18
- readFileSync(resolve(__dirname, '../../../package.json'))
19
-).version;
9
+const GITHUB_URL = getGitHubURL();
10
+const DEVTOOLS_VERSION = getVersionString();
11
12
module.exports = {
13
mode: __DEV__ ? 'development' : 'production',
shells/dev/webpack.config.js
+3
-14
@@ -1,23 +1,12 @@
1
-const { execSync } = require('child_process');
1
const { readFileSync } = require('fs');
2
const { resolve } = require('path');
3
const { DefinePlugin } = require('webpack');
4
+const { getGitHubURL, getVersionString } = require('../utils');
5
6
const __DEV__ = process.env.NODE_ENV !== 'production';
7
8
-// TODO potentially replac this with an fb.me URL (if it can forward the query params)
9
-const GITHUB_URL = execSync('git remote get-url origin')
10
- .toString()
11
- .trim()
12
- .replace(':', '/')
13
- .replace('git@', 'https://')
14
- .replace('.git', '');
15
-
16
-const DEVTOOLS_VERSION = JSON.parse(
17
- readFileSync(resolve(__dirname, '../../package.json'))
18
-).version;
19
-
20
-// TODO Share Webpack configs like alias
8
+const GITHUB_URL = getGitHubURL();
9
+const DEVTOOLS_VERSION = getVersionString();
10
11
module.exports = {
12
mode: 'development',
shells/utils.js
new
+27
@@ -0,0 +1,27 @@
1
+const { execSync } = require('child_process');
2
+const { readFileSync } = require('fs');
3
+const { resolve } = require('path');
4
+
5
+function getGitHubURL() {
6
+ // TODO potentially replac this with an fb.me URL (if it can forward the query params)
7
+ return execSync('git remote get-url origin')
8
+ .toString()
9
+ .trim()
10
+ .replace(':', '/')
11
+ .replace('git@', 'https://')
12
+ .replace('.git', '');
13
+}
14
+
15
+function getVersionString() {
16
+ const packageVersion = JSON.parse(
17
+ readFileSync(resolve(__dirname, '../package.json'))
18
+ ).version;
19
+
20
+ const commit = execSync('git show -s --format=%h')
21
+ .toString()
22
+ .trim();
23
+
24
+ return `${packageVersion}-${commit}`;
25
+}
26
+
27
+module.exports = { getGitHubURL, getVersionString };