Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JkYTqsvYu6AYr9yQ3Q4Nt6
23 lines
1.2 KiB
JavaScript
23 lines
1.2 KiB
JavaScript
// The version of a Chrome extension: bin/jumphp chrome:bump <folder> [patch|minor|major|<x.y.z>]
|
|
// Only the "version" line of manifest.json changes (its formatting is kept).
|
|
'use strict';
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const root = path.resolve(process.argv[2] || '.');
|
|
const how = process.argv[3] || 'patch';
|
|
const file = path.join(root, 'manifest.json');
|
|
const text = fs.readFileSync(file, 'utf8');
|
|
const current = JSON.parse(text).version || '0.0.0';
|
|
const parts = current.split('.').map(Number);
|
|
while (parts.length < 3) parts.push(0);
|
|
let next;
|
|
if (/^\d+(\.\d+){0,3}$/.test(how)) next = how;
|
|
else if (how === 'major') next = `${parts[0] + 1}.0.0`;
|
|
else if (how === 'minor') next = `${parts[0]}.${parts[1] + 1}.0`;
|
|
else if (how === 'patch') next = `${parts[0]}.${parts[1]}.${parts[2] + 1}`;
|
|
else { console.error(`usage: chrome:bump <folder> [patch|minor|major|x.y.z] (not "${how}")`); process.exit(2); }
|
|
if (next.split('.').some((n) => Number(n) > 65535)) { console.error(`${next}: each number is 65535 at most`); process.exit(2); }
|
|
const updated = text.replace(/("version"\s*:\s*")[^"]*(")/, `$1${next}$2`);
|
|
fs.writeFileSync(file, updated);
|
|
console.log(`${current} -> ${next}`);
|