Something went wrong. Try again.
The IoT platform Cloudflare didn't build. Telemetry, realtime dashboards, and automations on Workers + D1 + R2 + Durable Objects — in your… nodrix.live
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061// Writes worker/src/version.gen.ts with the current build's identity.//// The output is gitignored — it's a build artifact, not source. It's// regenerated on `bun install` (root postinstall) and as the first build// step, so fresh clones and CI both produce a current file.//// Sources, in priority order:// - commit: WORKERS_CI_COMMIT_SHA (set by Cloudflare Workers Builds)// CF_PAGES_COMMIT_SHA (set on Pages-style builds, fallback)// git rev-parse HEAD (local builds)// 'unknown' (anything else)// - built_at: unix seconds at script execution time// - version: root package.json `version` field// - channel: NODRIX_DEPLOY_CHANNEL ('release' default | 'edge'), so the// runtime update checker compares against whatever was deployed
import { spawnSync } from 'node:child_process';import { readFileSync, writeFileSync } from 'node:fs';import { dirname, join } from 'node:path';import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));const repoRoot = join(__dirname, '..');const outPath = join(repoRoot, 'worker', 'src', 'version.gen.ts');
function readVersion(): string { const pkg = JSON.parse(readFileSync(join(repoRoot, 'package.json'), 'utf8')) as { version?: string; }; return pkg.version ?? '0.0.0';}
function readCommit(): string { const fromEnv = process.env['WORKERS_CI_COMMIT_SHA'] ?? process.env['CF_PAGES_COMMIT_SHA']; if (fromEnv) return fromEnv.trim(); const r = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: repoRoot, encoding: 'utf8' }); if (r.status === 0 && r.stdout.trim()) return r.stdout.trim(); return 'unknown';}
function readChannel(): 'release' | 'edge' { return process.env['NODRIX_DEPLOY_CHANNEL'] === 'edge' ? 'edge' : 'release';}
const version = readVersion();const commit = readCommit();const channel = readChannel();const builtAt = Math.floor(Date.now() / 1000);
const contents = `// AUTO-GENERATED by scripts/gen-version.ts. Do not edit; gitignored.// Regenerated on bun install (postinstall) and at the start of bun run build.
export const VERSION: string = ${JSON.stringify(version)};export const COMMIT: string = ${JSON.stringify(commit)};export const CHANNEL: 'release' | 'edge' = ${JSON.stringify(channel)};export const BUILT_AT: number = ${builtAt};`;
writeFileSync(outPath, contents, 'utf8');console.log(`wrote ${outPath}: ${version} @ ${commit.slice(0, 7)} (${channel})`);