Yaltopia-FIFA/scripts/link-ipv4.mjs
Kirubel-Kibru-Yaltopia 89440985f1
Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
x
2026-05-24 21:46:10 +03:00

55 lines
1.5 KiB
JavaScript

import { spawnSync } from "child_process";
import { readFileSync, existsSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const projectRef = "vcxpcyafnlyiyqmapyyy";
function loadEnvLocal() {
const path = join(root, ".env.local");
if (!existsSync(path)) return {};
const env = {};
for (const line of readFileSync(path, "utf8").split(/\r?\n/)) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) continue;
const eq = trimmed.indexOf("=");
if (eq === -1) continue;
const key = trimmed.slice(0, eq).trim();
let val = trimmed.slice(eq + 1).trim();
if (
(val.startsWith('"') && val.endsWith('"')) ||
(val.startsWith("'") && val.endsWith("'"))
) {
val = val.slice(1, -1);
}
env[key] = val;
}
return env;
}
const env = loadEnvLocal();
const args = ["supabase", "link", "--project-ref", projectRef];
if (env.SUPABASE_DB_PASSWORD) {
console.log(`Linking project ${projectRef} (password from .env.local)...`);
args.push("--password", env.SUPABASE_DB_PASSWORD);
} else {
console.log(`Linking project ${projectRef}...`);
console.log(
"Enter your database password when prompted (Dashboard -> Settings -> Database)."
);
}
const result = spawnSync("npx", args, {
cwd: root,
stdio: "inherit",
shell: true,
});
if (result.status === 0) {
console.log("\nDone. Run: npm run db:push");
}
process.exit(result.status ?? 1);