build: update scripts

This commit is contained in:
EnixCoda 2018-11-06 15:36:11 +08:00
parent b01c0529ca
commit 7fd7abb070
No known key found for this signature in database
GPG key ID: 6825847C88AA329A
2 changed files with 26 additions and 5 deletions

View file

@ -7,10 +7,11 @@
"license": "MIT",
"private": true,
"scripts": {
"postinstall": "node scripts/generate-octicons",
"start": "webpack --watch",
"stamp": "node scripts/version.js",
"postversion": "npm run stamp && git add src/manifest.json && git commit --amend --no-edit",
"prod": "npm run stamp && NODE_ENV=production webpack && cd dist && rm -f ./gitako.zip && zip gitako.zip -r *"
"postversion": "node scripts/version.js",
"build": "NODE_ENV=production webpack && npm run postbuild",
"postbuild": "cd dist && rm -f ./gitako.zip && zip gitako.zip -r *"
},
"dependencies": {
"ini": "^1.3.5",

View file

@ -1,10 +1,30 @@
/**
* copy version from package.json to manifest.json
* also remove old git tag for the version
*/
const fs = require('fs')
const path = require('path')
const cp = require('child_process')
const rootPath = path.resolve(__dirname, '../')
const packageJSON = require(path.resolve(rootPath, 'package.json'))
const packagePath = path.resolve(rootPath, 'package.json')
const manifestPath = path.resolve(rootPath, 'src/manifest.json')
const packageJSON = require(packagePath)
const manifest = require(manifestPath)
manifest.version = packageJSON.version
const version = packageJSON.version
manifest.version = version
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, ' '), 'utf-8')
const exec = command => new Promise((resolve, reject) => cp.exec(command, (error, stdout, stderr) =>
error ? reject(error) : resolve(stdout || stderr)
))
exec(`git tag -d v${version}`)
.then(() =>
exec(`git add src/manifest.json && git commit --amend --no-edit`)
).then(() =>
exec(`git tag v${version}`)
).catch(console.error)