diff --git a/scripts/generate-landing-release-links.mjs b/scripts/generate-landing-release-links.mjs index a9b894f8..328bd59e 100644 --- a/scripts/generate-landing-release-links.mjs +++ b/scripts/generate-landing-release-links.mjs @@ -1,27 +1,12 @@ -import { readdir, readFile, writeFile } from "node:fs/promises"; +import { readdir, writeFile } from "node:fs/promises"; import { existsSync } from "node:fs"; import { join } from "node:path"; +import { loadEnvFile } from "./release/lib/dotenv.mjs"; const rootDir = process.cwd(); const localReleaseDir = join(rootDir, "local-release"); const outputPath = join(rootDir, "landing", "components", "release-links.generated.ts"); -async function loadEnvFile(filePath) { - if (!existsSync(filePath)) return; - const content = await readFile(filePath, "utf8"); - for (const rawLine of content.split(/\r?\n/)) { - const line = rawLine.trim(); - if (!line || line.startsWith("#")) continue; - const separatorIndex = line.indexOf("="); - if (separatorIndex <= 0) continue; - const key = line.slice(0, separatorIndex).trim(); - if (!key || process.env[key]) continue; - const rawValue = line.slice(separatorIndex + 1).trim(); - if (!rawValue) continue; - process.env[key] = rawValue.replace(/^['"]|['"]$/g, ""); - } -} - function normalizeBaseUrl(url) { return url.replace(/\/+$/, ""); } diff --git a/scripts/release-local.mjs b/scripts/release-local.mjs index ebf1d261..4ee97cb5 100644 --- a/scripts/release-local.mjs +++ b/scripts/release-local.mjs @@ -1,10 +1,10 @@ import { spawn } from "node:child_process"; -import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises"; -import { existsSync } from "node:fs"; +import { cp, mkdir, rm, writeFile } from "node:fs/promises"; import os from "node:os"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { prepareR2ReleaseHost, uploadReleaseFiles } from "./release-local/r2.mjs"; +import { loadEnvFile } from "./release/lib/dotenv.mjs"; const __dirname = dirname(fileURLToPath(import.meta.url)); const rootDir = join(__dirname, ".."); @@ -60,22 +60,6 @@ Environment loading: `); } -async function loadEnvFile(filePath) { - if (!existsSync(filePath)) return; - const content = await readFile(filePath, "utf8"); - for (const rawLine of content.split(/\r?\n/)) { - const line = rawLine.trim(); - if (!line || line.startsWith("#")) continue; - const separatorIndex = line.indexOf("="); - if (separatorIndex <= 0) continue; - const key = line.slice(0, separatorIndex).trim(); - if (!key || process.env[key]) continue; - const rawValue = line.slice(separatorIndex + 1).trim(); - if (!rawValue) continue; - process.env[key] = rawValue.replace(/^['"]|['"]$/g, ""); - } -} - function hasDocker() { return spawnSyncSuccess("docker", ["--version"]); }