gendesign/tradein-mvp/frontend/src/lib/buildInfo.ts
lekss361 8423af5dd5
All checks were successful
Deploy Trade-In / changes (push) Successful in 11s
Deploy Trade-In / build-browser (push) Successful in 36s
Deploy Trade-In / build-frontend (push) Successful in 2m23s
Deploy Trade-In / test (push) Successful in 3m14s
Deploy Trade-In / build-backend (push) Successful in 4m19s
Deploy Trade-In / deploy (push) Successful in 1m44s
feat(tradein): версионирование продукта — единый источник, подвал, PDF, /versions (#2824)
2026-08-10 16:00:54 +00:00

37 lines
1.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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)}`;
}