| #!/usr/bin/env node
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| import fs from "node:fs";
|
| import path from "node:path";
|
| import { execFileSync } from "node:child_process";
|
| import { fileURLToPath } from "node:url";
|
| import { dirname } from "node:path";
|
|
|
| const __dirname = dirname(fileURLToPath(import.meta.url));
|
| const ROOT = path.resolve(__dirname, "..", "..");
|
|
|
|
|
|
|
| function resolveBuildSha() {
|
| if (process.env.OMNIROUTE_BUILD_SHA) {
|
| return process.env.OMNIROUTE_BUILD_SHA.trim();
|
| }
|
| try {
|
| return execFileSync("git", ["rev-parse", "--short", "HEAD"], {
|
| cwd: ROOT,
|
| encoding: "utf8",
|
| }).trim();
|
| } catch (err) {
|
| console.error("[write-build-sha] Could not determine build SHA:", err.message);
|
| process.exit(1);
|
| }
|
| }
|
|
|
| const sha = resolveBuildSha();
|
| const NEXT_DIST = process.env.NEXT_DIST_DIR || ".build/next";
|
| const standaloneDir = path.join(ROOT, NEXT_DIST, "standalone");
|
| const distDir = path.join(ROOT, "dist");
|
|
|
|
|
| if (!fs.existsSync(standaloneDir)) {
|
| console.error(
|
| `[write-build-sha] FATAL: standalone dir not found: ${standaloneDir}\n` +
|
| ` Run \`npm run build\` before \`npm run build:release\`.`
|
| );
|
| process.exit(1);
|
| }
|
|
|
|
|
| const standaloneSentinel = path.join(standaloneDir, "BUILD_SHA");
|
| fs.writeFileSync(standaloneSentinel, sha + "\n");
|
| console.log(`[write-build-sha] Written ${sha} -> ${path.relative(ROOT, standaloneSentinel)}`);
|
|
|
|
|
| if (fs.existsSync(distDir)) {
|
| const distSentinel = path.join(distDir, "BUILD_SHA");
|
| fs.writeFileSync(distSentinel, sha + "\n");
|
| console.log(`[write-build-sha] Written ${sha} -> ${path.relative(ROOT, distSentinel)}`);
|
| }
|
|
|
| console.log(`[write-build-sha] Build SHA: ${sha}`);
|
|
|