@samitouri / QOS-React / commits / 94810b2b5a

Add Git revision to extension manifests

Brian Vaughn committed Apr 11, 2019 at 19:06 UTC 94810b2b5acc6b860df4dfa2881b62030806d518
2 files changed +17 -5
shells/browser/shared/build.js
+9 -1
@@ -2,8 +2,10 @@
2
3 const AdmZip = require('adm-zip');
4 const { execSync } = require('child_process');
5 +const { readFileSync, writeFileSync } = require('fs');
6 const { copy, ensureDir, move, remove } = require('fs-extra');
7 const { join } = require('path');
8 +const { getGitCommit } = require('../../utils');
9
10 // These files are copied along with Webpack-bundled files
11 // to produce the final web extension
@@ -52,13 +54,19 @@ const build = async (tempPath, manifestPath) => {
54 // Make temp dir
55 await ensureDir(zipPath);
56
57 + const copiedManifestPath = join(zipPath, 'manifest.json');
58 +
59 // Copy unbuilt source files to zip dir to be packaged:
60 await copy(binPath, join(zipPath, 'build'));
57 - await copy(manifestPath, join(zipPath, 'manifest.json'));
61 + await copy(manifestPath, copiedManifestPath);
62 await Promise.all(
63 STATIC_FILES.map(file => copy(join(__dirname, file), join(zipPath, file)))
64 );
65
66 + let manifest = JSON.parse(readFileSync(copiedManifestPath).toString());
67 + manifest.description += `\n\nCreated from revision ${getGitCommit()}`;
68 + writeFileSync(copiedManifestPath, JSON.stringify(manifest, null, 2));
69 +
70 // Pack the extension
71 const zip = new AdmZip();
72 zip.addLocalFolder(zipPath);
shells/utils.js
+8 -4
@@ -2,6 +2,12 @@ const { execSync } = require('child_process');
2 const { readFileSync } = require('fs');
3 const { resolve } = require('path');
4
5 +function getGitCommit() {
6 + return execSync('git show -s --format=%h')
7 + .toString()
8 + .trim();
9 +}
10 +
11 function getGitHubURL() {
12 // TODO potentially replac this with an fb.me URL (if it can forward the query params)
13 return execSync('git remote get-url origin')
@@ -17,11 +23,9 @@ function getVersionString() {
23 readFileSync(resolve(__dirname, '../package.json'))
24 ).version;
25
20 - const commit = execSync('git show -s --format=%h')
21 - .toString()
22 - .trim();
26 + const commit = getGitCommit();
27
28 return `${packageVersion}-${commit}`;
29 }
30
27 -module.exports = { getGitHubURL, getVersionString };
31 +module.exports = { getGitCommit, getGitHubURL, getVersionString };