61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
/**
|
|
* Escribe src/shared/version.json con la fecha de release.
|
|
* Default: hoy. Override: RELEASE_DATE=DD/MM/YYYY (env o .env.minio).
|
|
*
|
|
* Debe ejecutarse ANTES de vite build: la UI inyecta esta fecha en compile-time.
|
|
*/
|
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const root = join(__dirname, "..");
|
|
|
|
function loadEnvFile(filePath) {
|
|
if (!existsSync(filePath)) return;
|
|
const text = readFileSync(filePath, "utf8");
|
|
for (const line of text.split(/\r?\n/)) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
const eq = trimmed.indexOf("=");
|
|
if (eq <= 0) continue;
|
|
const key = trimmed.slice(0, eq).trim();
|
|
let value = trimmed.slice(eq + 1).trim();
|
|
if (
|
|
(value.startsWith('"') && value.endsWith('"')) ||
|
|
(value.startsWith("'") && value.endsWith("'"))
|
|
) {
|
|
value = value.slice(1, -1);
|
|
}
|
|
if (!(key in process.env) || process.env[key] === "") {
|
|
process.env[key] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
loadEnvFile(join(root, ".env.minio"));
|
|
loadEnvFile(join(root, ".env"));
|
|
|
|
function todayIso() {
|
|
const d = new Date();
|
|
const dd = String(d.getDate()).padStart(2, "0");
|
|
const mm = String(d.getMonth() + 1).padStart(2, "0");
|
|
const yyyy = d.getFullYear();
|
|
return `${yyyy}-${mm}-${dd}`;
|
|
}
|
|
|
|
function isoFromDisplay(display) {
|
|
const m = String(display).trim().match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
|
|
if (!m) return null;
|
|
const [, dd, mm, yyyy] = m;
|
|
return `${yyyy}-${mm.padStart(2, "0")}-${dd.padStart(2, "0")}`;
|
|
}
|
|
|
|
const releaseDateIso = process.env.RELEASE_DATE
|
|
? isoFromDisplay(process.env.RELEASE_DATE) || todayIso()
|
|
: todayIso();
|
|
|
|
const outPath = join(root, "src/shared/version.json");
|
|
writeFileSync(outPath, `${JSON.stringify({ releaseDate: releaseDateIso }, null, 2)}\n`, "utf8");
|
|
console.log(`releaseDate → ${releaseDateIso} (${outPath})`);
|