askrobots / dbbasic-browser
Public
A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.
danq9
toolbar: Back and Forward are greyed out when there's nowhere to go
cc08c7a
1 week, 2 days ago
History
version.mjs · 3.0 KB · 64 lines
| 1 | #!/usr/bin/env node |
| 2 | // The browser's version (see src/version.ts for the scheme). |
| 3 | // |
| 4 | // node apps/browser/scripts/version.mjs show it: 2026.11v1 (package.json: 2026.11.1) |
| 5 | // node apps/browser/scripts/version.mjs cut cut the next release in this UTC month |
| 6 | // node apps/browser/scripts/version.mjs cut 2026.11v1 or a given one (either spelling; -beta.N for a pre-release) |
| 7 | // |
| 8 | // A cut rewrites the version in apps/browser/package.json and the lockfile, and moves the changelog's Unreleased section |
| 9 | // under the new version with today's UTC date. It never commits, tags or pushes: it prints the commands for that. |
| 10 | import { readFileSync, writeFileSync } from "node:fs"; |
| 11 | import { dirname, join } from "node:path"; |
| 12 | import { fileURLToPath } from "node:url"; |
| 13 | import { parseVersion, nextVersion, shownVersion, semverVersion, compareVersions } from "../src/version.ts"; |
| 14 | |
| 15 | const app = join(dirname(fileURLToPath(import.meta.url)), ".."); |
| 16 | const repo = join(app, "..", ".."); |
| 17 | const pkgPath = join(app, "package.json"); |
| 18 | const lockPath = join(repo, "package-lock.json"); |
| 19 | const changelogPath = join(repo, "CHANGELOG.md"); |
| 20 | |
| 21 | const pkgText = readFileSync(pkgPath, "utf8"); |
| 22 | const current = JSON.parse(pkgText).version; |
| 23 | const cur = parseVersion(current); |
| 24 | const [cmd, arg] = process.argv.slice(2); |
| 25 | |
| 26 | if (!cmd) { |
| 27 | console.log(cur ? `${shownVersion(cur)} (package.json: ${current})` : `${current} (not a release version yet)`); |
| 28 | process.exit(0); |
| 29 | } |
| 30 | if (cmd !== "cut") { |
| 31 | console.error("usage: version.mjs [cut [version]]"); |
| 32 | process.exit(2); |
| 33 | } |
| 34 | |
| 35 | const next = arg ? parseVersion(arg) : nextVersion(current, new Date()); |
| 36 | if (!next) { |
| 37 | console.error(`"${arg}" is not a version like 2026.11v1 or 2026.11.1`); |
| 38 | process.exit(2); |
| 39 | } |
| 40 | if (cur && compareVersions(next, cur) <= 0) { |
| 41 | console.error(`${shownVersion(next)} is not after the current ${shownVersion(cur)}`); |
| 42 | process.exit(1); |
| 43 | } |
| 44 | const semver = semverVersion(next); |
| 45 | const shown = shownVersion(next); |
| 46 | |
| 47 | // package.json and the lockfile: replace only the version string, keeping the files' own formatting. |
| 48 | const versionLine = /("version":\s*")[^"]*(")/; |
| 49 | writeFileSync(pkgPath, pkgText.replace(versionLine, `$1${semver}$2`)); |
| 50 | const lock = readFileSync(lockPath, "utf8"); |
| 51 | const at = lock.indexOf('"apps/browser": {'); |
| 52 | if (at < 0) throw new Error("apps/browser is not in package-lock.json"); |
| 53 | const head = lock.slice(0, at); |
| 54 | const rest = lock.slice(at); |
| 55 | writeFileSync(lockPath, head + rest.replace(versionLine, `$1${semver}$2`)); |
| 56 | |
| 57 | // The changelog: what was Unreleased becomes this release; a fresh, empty Unreleased goes above it. |
| 58 | const date = new Date().toISOString().slice(0, 10); |
| 59 | const log = readFileSync(changelogPath, "utf8"); |
| 60 | if (!log.includes("\n## [Unreleased]\n")) throw new Error("CHANGELOG.md has no ## [Unreleased] heading"); |
| 61 | writeFileSync(changelogPath, log.replace("\n## [Unreleased]\n", `\n## [Unreleased]\n\n## [${shown}] - ${date}\n`)); |
| 62 | |
| 63 | console.log(`${cur ? shownVersion(cur) : current} → ${shown} (package.json: ${semver})`); |
| 64 | console.log(`next: git commit -am "${shown}" && git tag -a ${shown} -m "${shown}" (pushing the tag publishes it)`); |