#!/usr/bin/env node // Writes the version from package.json into src/version.ts (see the comment there). // Runs as the `version` script of package.json; by hand: node scripts/write-version.mjs import { readFileSync, writeFileSync } from 'node:fs' const root = new URL('../', import.meta.url) const { version } = JSON.parse(readFileSync(new URL('package.json', root), 'utf8')) const file = new URL('src/version.ts', root) const before = readFileSync(file, 'utf8') const after = before.replace(/export const PLUGIN_VERSION = '[^']*'/, `export const PLUGIN_VERSION = '${version}'`) if (after === before && !before.includes(`'${version}'`)) {throw new Error('src/version.ts: the PLUGIN_VERSION line was not found')} writeFileSync(file, after) console.log(`src/version.ts → ${version}`)