Skip to content

Commit

Permalink
add update script
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed Feb 6, 2019
1 parent f13dd9a commit d2316c9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 10 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# scripts

## update-version

```bash
export TARGET_VERSION=<version>
./scripts/update-version.js
git commit -am "release: v${TARGET_VERSION}"
git tag v${TARGET_VERSION}
```
43 changes: 43 additions & 0 deletions scripts/update-version.js
Original file line number Diff line number Diff line change
@@ -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')))

0 comments on commit d2316c9

Please sign in to comment.