#!/usr/bin/env bash # Bump the version in package.json. Usage: # # bash scripts/bump.sh patch # 0.10.7 -> 0.10.8 # bash scripts/bump.sh minor # 0.10.7 -> 0.11.0 # bash scripts/bump.sh major # 0.10.7 -> 1.0.0 set -euo pipefail cd "$(dirname "$0")/.." KIND="${1:-}" case "$KIND" in patch|minor|major) ;; *) echo "Usage: $0 {patch|minor|major}" >&2 exit 1 ;; esac NEW_VERSION=$(node -e " const fs = require('fs'); const pkgPath = './package.json'; const verPath = './src/version.ts'; const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); const m = /^(\d+)\.(\d+)\.(\d+)\$/.exec(pkg.version); if (!m) { console.error('unparseable version:', pkg.version); process.exit(1); } let [_, a, b, c] = m.map((x, i) => i === 0 ? x : Number(x)); if (process.argv[1] === 'patch') c += 1; else if (process.argv[1] === 'minor') { b += 1; c = 0; } else if (process.argv[1] === 'major') { a += 1; b = 0; c = 0; } const next = a + '.' + b + '.' + c; pkg.version = next; fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); const ver = fs.readFileSync(verPath, 'utf8'); const updated = ver.replace( /(APP_VERSION\s*=\s*)(['\"])[^'\"]*\2/, (_m, lhs, q) => lhs + q + next + q, ); if (updated === ver) { console.error('APP_VERSION not found in', verPath); process.exit(1); } fs.writeFileSync(verPath, updated); process.stdout.write(next); " "$KIND") echo "Bumped to $NEW_VERSION"