// Build/version metadata for the МЕРА product — sourced from build-time // `NEXT_PUBLIC_*` env vars, baked in by `frontend/Dockerfile` via // `--build-arg` (see `.forgejo/workflows/deploy-tradein.yml`, build-frontend // job). Safe to import from BOTH server and client components: Next.js // inlines `NEXT_PUBLIC_*` references at build time into every bundle that // references them — there is no runtime env lookup in the browser. // // Fallback "dev" — a local `npm run dev` / `next build` without the // build-args set (i.e. every local run, and CI unless explicitly passed) // reads honestly as "not a tagged deploy" instead of leaking "undefined" // into the UI or crashing. export const APP_VERSION = process.env.NEXT_PUBLIC_APP_VERSION || "dev"; export const BUILD_SHA = process.env.NEXT_PUBLIC_BUILD_SHA || "dev"; export const BUILD_DATE = process.env.NEXT_PUBLIC_BUILD_DATE || ""; /** * ISO-8601 (`2026-08-10` or `2026-08-10T12:00:00Z`) → `10.08.2026`. * * Deliberately a plain regex, not `Date#toLocaleDateString("ru-RU")`: the * input is already a plain calendar date (no timezone conversion needed), * and a regex keeps formatting identical between server-render and * client-render without depending on locale data being present/consistent * in whichever runtime executes it. */ export function formatRuDate(iso: string | undefined | null): string { const match = iso ? /^(\d{4})-(\d{2})-(\d{2})/.exec(iso) : null; if (!match) return "dev"; const [, year, month, day] = match; return `${day}.${month}.${year}`; } /** "Мера v1.0.0 · a1b2c3d · 10.08.2026" (or "Мера dev · dev · dev" locally). */ export function formatVersionLabel(): string { const versionPart = APP_VERSION === "dev" ? "dev" : `v${APP_VERSION}`; return `Мера ${versionPart} · ${BUILD_SHA} · ${formatRuDate(BUILD_DATE)}`; }