38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
|
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||
|
|
import { dirname, resolve } from "node:path";
|
||
|
|
|
||
|
|
import { E2E_API_URL, assertOfficialE2EEnvironment } from "./e2e-contract";
|
||
|
|
|
||
|
|
function readEnvironment(path: string): Record<string, string | undefined> {
|
||
|
|
return Object.fromEntries(
|
||
|
|
readFileSync(path, "utf8")
|
||
|
|
.split(/\r?\n/)
|
||
|
|
.filter((line) => line && !line.startsWith("#"))
|
||
|
|
.map((line) => {
|
||
|
|
const separatorIndex = line.indexOf("=");
|
||
|
|
|
||
|
|
return [line.slice(0, separatorIndex), line.slice(separatorIndex + 1)];
|
||
|
|
})
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
const env = process.env;
|
||
|
|
assertOfficialE2EEnvironment(env);
|
||
|
|
|
||
|
|
const webEnv = readEnvironment(resolve("apps/web/.env.e2e"));
|
||
|
|
if (webEnv.VITE_API_SERVER_URL !== E2E_API_URL) {
|
||
|
|
throw new Error(`Official E2E requires VITE_API_SERVER_URL=${E2E_API_URL} in apps/web/.env.e2e.`);
|
||
|
|
}
|
||
|
|
|
||
|
|
const certificatesPath = env.COMPANY_CERTIFICATES_PATH;
|
||
|
|
if (!certificatesPath) {
|
||
|
|
throw new Error("E2E requires COMPANY_CERTIFICATES_PATH in apps/server/.env.e2e.");
|
||
|
|
}
|
||
|
|
|
||
|
|
const certificatesFile = resolve("apps/server", certificatesPath);
|
||
|
|
mkdirSync(dirname(certificatesFile), { recursive: true });
|
||
|
|
|
||
|
|
if (!existsSync(certificatesFile)) {
|
||
|
|
writeFileSync(certificatesFile, "{}\n");
|
||
|
|
}
|