internetarchive / wayback-machine-firefox

Reduce annoying 404 pages by automatically checking for an archived copy in the Wayback Machine. Learn more about this Test Pilot experiment at https://testpilot.firefox.com/
GNU Affero General Public License v3.0
53 stars 17 forks source link

Consolidate VERSION strings? #34

Open pdehaan opened 8 years ago

pdehaan commented 8 years ago

Currently it looks like we have 3 places where we store a VERSION string:

LOCATION STRING
/package.json:4 "version": "1.5.3"
/src/manifest.json:5 "version": "1.5.3"
/src/scripts/background.js:5 var VERSION = "1.5.3";

Not a huge deal, but may be easy to overlook a string when bumping versions. I don't know if there's an easier way to specify a definitive version string in one place.

It may be easiest to just keep specify the definitive version number in /package.json, then have some basic script which copies the /package.json version property into /src/manifest.json (we could automate that as a prebuild_unsigned and presign npm script hook), and then do something like chrome.runtime.getManifest().version in the /src/scripts/background.js to grab it from the /src/manifest.json file instead of hard coding it.

http://stackoverflow.com/questions/7573191/can-i-access-a-property-from-my-manifest-json-in-my-extensions-javascript-files

pdehaan commented 8 years ago

Here was my crappy attempt at keeping package.json's version in sync with src/manifest.json's version field:

const manifestPath = require.resolve("../src/manifest.json");
const packageVersion = require("../package.json").version;
const manifestJson = require(manifestPath);

const fs = require("fs");

var manifestStr;

if (packageVersion !== manifestJson.version) {
  manifestJson.version = packageVersion;
  manifestStr = JSON.stringify(manifestJson, null, 2) + "\n";
  fs.writeFileSync(manifestPath, manifestStr, "utf-8");
}

Then we can probably trigger this bin/set-manifest-version.js file using npm pre* hooks for build_unsigned and sign scripts:

  "scripts": {
    "build_unsigned": "mkdir -p build_unsigned && web-ext build --source-dir=src --artifacts-dir=build_unsigned",
    "dev": "web-ext run -s=src --pre-install",
    "lint": "eslint .",
    "prebuild_unsigned": "npm run set_manifest_version",
    "presign": "npm run set_manifest_version",
    "set_manifest_version": "node bin/set-manifest-version",
    "sign": "rm ./build/* || true && (export $(cat CREDENTIALS | xargs) && web-ext sign --verbose -s=src -a=build  --api-key=$JWT_ISSUER --api-secret=$JWT_SECRET) && git add *.xpi",
    "test": "npm run lint"
  }

This way, we'll automatically update src/manifest.json [if necessary] before making any signed/unsigned builds.

shrug