diff --git a/bumpver.js b/bumpver.js new file mode 100644 index 0000000..c738464 --- /dev/null +++ b/bumpver.js @@ -0,0 +1,54 @@ + +const fs = require('fs'); +const util = require('util'); +const exec = util.promisify(require('child_process').exec); +const crypto = require('crypto'); + +const infoPath = './info.json'; +const scoopPath = './misc/excuse.json'; + +function makeScoop(data) { + let scoop = JSON.parse(fs.readFileSync(scoopPath)); + let version = data['version']; + scoop['version'] = version; + let file = fs.readFileSync('./bin/excuse.ps1'); + let hash = crypto.createHash('sha256').update(file, 'utf8').digest('hex'); + scoop['hash'] = hash; + let url = 'https://raw.githubusercontent.com/esphas/excuse/v' + version + '/bin/excuse.ps1'; + scoop['url'] = url; + fs.writeFileSync(scoopPath, JSON.stringify(scoop, null, 2)); +} + +async function gitTag() { + await exec('git add ' + infoPath); + await exec('git add ' + scoopPath); + await exec('git commit -m "bump version"'); + await exec('git tag v' + version); +} + +function main(type, extra) { + let info = JSON.parse(fs.readFileSync(infoPath)); + let version = info['version']; + let major, minor, patch; + [major, minor, patch] = version.split('-')[0].split('.'); + function succ(str) { + return (parseInt(str) + 1).toString(); + } + switch (type) { + case 'M': major = succ(major); break; + case 'm': minor = succ(minor); break; + case 'p': patch = succ(patch); break; + } + version = [major, minor, patch].join('.'); + if (extra != null) { + version += '-' + extra; + } + let data = { version }; + makeScoop(data); + fs.writeFileSync(infoPath, JSON.stringify(data, null, 2)); + gitTag(); +} + +let type = process.argv[2] || 'm'; +let extra = process.argv[3]; +main(type, extra); diff --git a/bumpver.ps1 b/bumpver.ps1 new file mode 100644 index 0000000..78e6942 --- /dev/null +++ b/bumpver.ps1 @@ -0,0 +1,2 @@ + +node ./bumpver.js $args diff --git a/bumpver.sh b/bumpver.sh new file mode 100644 index 0000000..98d1692 --- /dev/null +++ b/bumpver.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +node ./bumpver.js $@ diff --git a/info.json b/info.json new file mode 100644 index 0000000..6a3252e --- /dev/null +++ b/info.json @@ -0,0 +1,3 @@ +{ + "version": "0.1.0" +}