diff --git a/package.json b/package.json index 0a9de86..3b8adb4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/version.js b/scripts/version.js index 3aa7456..470e218 100644 --- a/scripts/version.js +++ b/scripts/version.js @@ -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)