#!/usr/bin/env node // Writes a release manifest; does not push, tag, deploy, or change anyone's installation. import fs from 'node:fs' import { fileURLToPath } from 'node:url' import { execFileSync } from 'node:child_process' import { createHash } from 'node:crypto' import { newerVersion, parseClientRelease, releaseUrl } from '../src/client-release.ts' const root = new URL('../', import.meta.url) process.chdir(fileURLToPath(root)) const [version, ref = 'origin/main', ...extra] = process.argv.slice(2) if (!version || extra.length) throw new Error('usage: node scripts/release-client.ts [pushed-commit]') const revision = execFileSync('git', ['rev-parse', '--verify', `${ref}^{commit}`], { encoding: 'utf8' }).trim() execFileSync('git', ['merge-base', '--is-ancestor', revision, 'origin/main']) parseClientRelease({ version, revision, sha256: '0'.repeat(64) }) const manifest = new URL('../client-release.json', import.meta.url) if (fs.existsSync(manifest)) { const old = parseClientRelease(JSON.parse(fs.readFileSync(manifest, 'utf8'))) if (!newerVersion(version, old.version)) throw new Error(`release version must be newer than ${old.version}; never rewrite a published version`) } const source = releaseUrl(process.env.LANGUID_SOURCE_URL ?? 'https://tangled.org/cameron.stream/languid') const url = `${source}/archive/${revision}` const response = await fetch(url, { signal: AbortSignal.timeout(60_000) }) if (!response.ok) throw new Error(`archive download failed: HTTP ${response.status}`) const archive = new Uint8Array(await response.arrayBuffer()) const sha256 = createHash('sha256').update(archive).digest('hex') const release = parseClientRelease({ version, revision, sha256 }) fs.writeFileSync(manifest, JSON.stringify(release, null, 2) + '\n') console.log(`Prepared client ${version} from ${revision}: ${sha256}\nReview and commit client-release.json, push main, then deploy the service to announce it. No clients were updated.`)