Add Git revision to extension manifests

This commit is contained in:
Brian Vaughn 2019-04-11 19:06:07 -07:00
parent 9a0cf68a4d
commit 94810b2b5a
2 changed files with 17 additions and 5 deletions

View File

@ -2,8 +2,10 @@
const AdmZip = require('adm-zip');
const { execSync } = require('child_process');
const { readFileSync, writeFileSync } = require('fs');
const { copy, ensureDir, move, remove } = require('fs-extra');
const { join } = require('path');
const { getGitCommit } = require('../../utils');
// These files are copied along with Webpack-bundled files
// to produce the final web extension
@ -52,13 +54,19 @@ const build = async (tempPath, manifestPath) => {
// Make temp dir
await ensureDir(zipPath);
const copiedManifestPath = join(zipPath, 'manifest.json');
// Copy unbuilt source files to zip dir to be packaged:
await copy(binPath, join(zipPath, 'build'));
await copy(manifestPath, join(zipPath, 'manifest.json'));
await copy(manifestPath, copiedManifestPath);
await Promise.all(
STATIC_FILES.map(file => copy(join(__dirname, file), join(zipPath, file)))
);
let manifest = JSON.parse(readFileSync(copiedManifestPath).toString());
manifest.description += `\n\nCreated from revision ${getGitCommit()}`;
writeFileSync(copiedManifestPath, JSON.stringify(manifest, null, 2));
// Pack the extension
const zip = new AdmZip();
zip.addLocalFolder(zipPath);

View File

@ -2,6 +2,12 @@ const { execSync } = require('child_process');
const { readFileSync } = require('fs');
const { resolve } = require('path');
function getGitCommit() {
return execSync('git show -s --format=%h')
.toString()
.trim();
}
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')
@ -17,11 +23,9 @@ function getVersionString() {
readFileSync(resolve(__dirname, '../package.json'))
).version;
const commit = execSync('git show -s --format=%h')
.toString()
.trim();
const commit = getGitCommit();
return `${packageVersion}-${commit}`;
}
module.exports = { getGitHubURL, getVersionString };
module.exports = { getGitCommit, getGitHubURL, getVersionString };