chore(env): rename test environment to staging

This commit is contained in:
dahyeon committed 2026-06-07 01:01:13 -07:00
1 parent d0d578b2b0
commit eadae789c8
17 files changed
+160 -107

No files matched your search

+40 -38
View File
@@ -1,49 +1,51 @@
import { spawnSync } from 'node:child_process';
import { existsSync, readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { spawnSync } from "node:child_process";
import { existsSync, readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = resolve(__dirname, '..');
const webDir = resolve(repoRoot, 'apps/web');
const repoRoot = resolve(__dirname, "..");
const webDir = resolve(repoRoot, "apps/web");
const target = process.argv[2];
if (target !== 'test' && target !== 'prod') {
console.error('Usage: node scripts/deploy-cloudflare-pages.mjs <test|prod>');
if (target !== "staging" && target !== "prod") {
console.error(
"Usage: node scripts/deploy-cloudflare-pages.mjs <staging|prod>",
);
process.exit(1);
}
const viteMode = target === 'prod' ? 'production' : 'test';
const viteMode = target === "prod" ? "production" : "staging";
const projectName =
process.env.CF_PAGES_PROJECT_NAME ??
process.env.CLOUDFLARE_PAGES_PROJECT_NAME ??
'lolympus';
const testBranch = process.env.CF_PAGES_TEST_BRANCH ?? 'test';
"lolympus";
const stagingBranch = process.env.CF_PAGES_STAGING_BRANCH ?? "staging";
validateEnv(viteMode);
run('pnpm', ['--filter', 'web', 'run', `build:${target}`], repoRoot);
run("pnpm", ["--filter", "web", "run", `build:${target}`], repoRoot);
const deployArgs = [
'exec',
'wrangler',
'pages',
'deploy',
'dist',
'--project-name',
"exec",
"wrangler",
"pages",
"deploy",
"dist",
"--project-name",
projectName,
];
if (target === 'test') {
deployArgs.push('--branch', testBranch);
if (target === "staging") {
deployArgs.push("--branch", stagingBranch);
}
run('pnpm', deployArgs, webDir);
run("pnpm", deployArgs, webDir);
function run(command, args, cwd) {
const result = spawnSync(command, args, {
cwd,
stdio: 'inherit',
shell: process.platform === 'win32',
stdio: "inherit",
shell: process.platform === "win32",
});
if (result.status !== 0) {
process.exit(result.status ?? 1);
@@ -52,8 +54,8 @@ function run(command, args, cwd) {
function validateEnv(mode) {
const fileEnv = [
'.env',
'.env.local',
".env",
".env.local",
`.env.${mode}`,
`.env.${mode}.local`,
].reduce((acc, fileName) => {
@@ -62,39 +64,39 @@ function validateEnv(mode) {
return { ...acc, ...parseEnvFile(envFile) };
}, {});
const requiredKeys = [
'VITE_API_BASE_URL',
'VITE_DEFAULT_COMMUNITY_ID',
'VITE_MSAL_CLIENT_ID',
'VITE_MSAL_AUTHORITY',
'VITE_MSAL_API_SCOPE',
'VITE_MSAL_REDIRECT_URI',
"VITE_API_BASE_URL",
"VITE_DEFAULT_COMMUNITY_ID",
"VITE_MSAL_CLIENT_ID",
"VITE_MSAL_AUTHORITY",
"VITE_MSAL_API_SCOPE",
"VITE_MSAL_REDIRECT_URI",
];
const missing = requiredKeys.filter((key) => {
const value = process.env[key] ?? fileEnv[key];
return !value || value.includes('<');
return !value || value.includes("<");
});
if (missing.length === 0) return;
console.error(
[
`Missing Cloudflare Pages ${mode} build env: ${missing.join(', ')}`,
`Missing Cloudflare Pages ${mode} build env: ${missing.join(", ")}`,
`Create apps/web/.env.${mode}, apps/web/.env.${mode}.local, or export these variables before deploy.`,
`Use apps/web/.env.${mode}.example as a template.`,
].join('\n'),
].join("\n"),
);
process.exit(1);
}
function parseEnvFile(path) {
return Object.fromEntries(
readFileSync(path, 'utf8')
readFileSync(path, "utf8")
.split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => line && !line.startsWith('#'))
.filter((line) => line && !line.startsWith("#"))
.map((line) => {
const separatorIndex = line.indexOf('=');
if (separatorIndex === -1) return [line, ''];
const separatorIndex = line.indexOf("=");
if (separatorIndex === -1) return [line, ""];
const key = line.slice(0, separatorIndex).trim();
let value = line.slice(separatorIndex + 1).trim();
if (