From d2316c9455482c7144db75dada53d3292b37be08 Mon Sep 17 00:00:00 2001 From: Yasuaki Uechi Date: Wed, 6 Feb 2019 23:15:16 +0900 Subject: [PATCH] add update script --- package.json | 1 + scripts/README.md | 10 +++++++++ scripts/update-version.js | 43 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 scripts/README.md create mode 100755 scripts/update-version.js diff --git a/package.json b/package.json index c390f69..3e8f1ad 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@babel/preset-env": "^7.3.1", "babel-core": "7.0.0-bridge.0", "babel-loader": "^8.0.5", + "plist": "^3.0.1", "webpack": "^4.16.4", "webpack-command": "^0.4.1" }, diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..a99c922 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,10 @@ +# scripts + +## update-version + +```bash +export TARGET_VERSION= +./scripts/update-version.js +git commit -am "release: v${TARGET_VERSION}" +git tag v${TARGET_VERSION} +``` diff --git a/scripts/update-version.js b/scripts/update-version.js new file mode 100755 index 0000000..cca28a0 --- /dev/null +++ b/scripts/update-version.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node + +const path = require('path') +const fs = require('fs') +const assert = require('assert') +const { execSync } = require('child_process') +const plist = require('plist') + +const targetVersion = process.env.TARGET_VERSION +assert(targetVersion, 'specify TARGET_VERSION envvar') + +// rewrite `docs/manifest.plist` +const manifestPath = path.resolve(__dirname, '../docs/manifest.plist') +console.log(`rewriting '${manifestPath}'`) +const manifest = plist.parse(fs.readFileSync(manifestPath, 'utf8')) +manifest['Extension Updates'][0]['CFBundleVersion'] = targetVersion +manifest['Extension Updates'][0]['CFBundleShortVersionString'] = targetVersion +manifest['Extension Updates'][0][ + 'URL' +] = `https://github.com/uetchy/Polyglot/releases/download/v${targetVersion}/Polyglot.safariextz` +fs.writeFileSync(manifestPath, plist.build(manifest)) + +// rewrite `Polyglot.safariextension/Info.plist` +const infoPath = path.resolve( + __dirname, + '../Polyglot.safariextension/Info.plist' +) +console.log(`rewriting '${infoPath}'`) +const info = plist.parse(fs.readFileSync(infoPath, 'utf8')) +info['CFBundleShortVersionString'] = targetVersion +info['CFBundleVersion'] = targetVersion +fs.writeFileSync(infoPath, plist.build(info)) + +// rewrite `package.json` +const packagePath = path.resolve(__dirname, '../package.json') +console.log(`rewriting '${packagePath}'`) +const package = require(packagePath) +package.version = targetVersion +fs.writeFileSync(packagePath, JSON.stringify(package, null, 2)) + +// postprocess +console.log(String(execSync('fixpack'))) +console.log(String(execSync('yarn')))