Show the app version at the top of the page (Ver YYMMDDX)

Adds src/version.js, bump-version.js and a pre-commit hook that bumps the
version in commits that change the app.

Closes #15

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 19:01:33 -05:00
parent 1736548ef9
commit a2fcc65759
10 changed files with 193 additions and 3 deletions

25
src/version.js Normal file
View File

@@ -0,0 +1,25 @@
// The version of the app code, shown at the top of the page: "Ver YYMMDDX".
// YYMMDD is the date, X the iteration that day (A first, B second, ...).
// Bump with `npm run bump` (see bump-version.js). build.js strips `export`.
export const APP_VERSION = '261109A';
const VERSION_RE = /^(\d{6})([A-Z])$/;
export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v);
// YYMMDD for a Date, in local time.
export function versionDate(date) {
const p = (n) => String(n).padStart(2, '0');
return p(date.getFullYear() % 100) + p(date.getMonth() + 1) + p(date.getDate());
}
// The version that follows `current` when released on `date`: the next letter
// on the same day, or A on a new day.
export function nextVersion(current, date) {
if (!isVersion(current)) throw new Error('Not a version: ' + current);
const day = versionDate(date);
if (!current.startsWith(day)) return day + 'A';
const letter = current[6];
if (letter === 'Z') throw new Error('Already 26 versions on ' + day + '; wait until tomorrow.');
return day + String.fromCharCode(letter.charCodeAt(0) + 1);
}