#!/usr/bin/env node const fs = require("fs"); const path = require("path"); /** * 환경별 빌드 설정 스크립트 * 개발/스테이징/프로덕션 환경에 따라 다른 설정을 적용합니다. */ const environments = { development: { appName: "Zellyy Finance (Dev)", appId: "com.zellyy.finance.dev", backgroundColor: "#FEF3C7", // 노란색 톤 scheme: "ZellyyFinanceDev", }, staging: { appName: "Zellyy Finance (Beta)", appId: "com.zellyy.finance.beta", backgroundColor: "#DBEAFE", // 파란색 톤 scheme: "ZellyyFinanceBeta", }, production: { appName: "Zellyy Finance", appId: "com.zellyy.finance", backgroundColor: "#F8FAFC", // 기본 색상 scheme: "ZellyyFinance", }, }; const env = process.argv[2] || "production"; if (!environments[env]) { console.error(`❌ Invalid environment: ${env}`); console.log("Available environments:", Object.keys(environments).join(", ")); process.exit(1); } const config = environments[env]; console.log(`🔧 Configuring for ${env} environment...`); // Capacitor 설정 업데이트 const capacitorConfigPath = path.join(__dirname, "..", "capacitor.config.ts"); if (fs.existsSync(capacitorConfigPath)) { console.log("⚡ Updating Capacitor config..."); let configContent = fs.readFileSync(capacitorConfigPath, "utf8"); // 앱 ID 업데이트 configContent = configContent.replace( /appId:\s*"[^"]*"/, `appId: "${config.appId}"` ); // 앱 이름 업데이트 configContent = configContent.replace( /appName:\s*"[^"]*"/, `appName: "${config.appName}"` ); // 스플래시 배경색 업데이트 configContent = configContent.replace( /backgroundColor:\s*"[^"]*"/, `backgroundColor: "${config.backgroundColor}"` ); // iOS 스킴 업데이트 configContent = configContent.replace( /scheme:\s*"[^"]*"/, `scheme: "${config.scheme}"` ); fs.writeFileSync(capacitorConfigPath, configContent); console.log(`✅ Capacitor config updated for ${env}`); } // Android strings.xml 업데이트 (앱 이름) const androidStringsPath = path.join( __dirname, "..", "android", "app", "src", "main", "res", "values", "strings.xml" ); if (fs.existsSync(androidStringsPath)) { console.log("📱 Updating Android strings.xml..."); let stringsContent = fs.readFileSync(androidStringsPath, "utf8"); stringsContent = stringsContent.replace( /[^<]*<\/string>/, `${config.appName}` ); fs.writeFileSync(androidStringsPath, stringsContent); console.log(`✅ Android app name updated: ${config.appName}`); } // iOS Info.plist 업데이트 (Bundle Display Name) const iosInfoPlistPath = path.join( __dirname, "..", "ios", "App", "App", "Info.plist" ); if (fs.existsSync(iosInfoPlistPath)) { console.log("🍎 Updating iOS Info.plist..."); try { const { execSync } = require("child_process"); // CFBundleDisplayName 업데이트 execSync( `/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName ${config.appName}" "${iosInfoPlistPath}"`, { stdio: "pipe", } ); console.log(`✅ iOS app name updated: ${config.appName}`); } catch (error) { console.log( "⚠️ Could not update iOS Info.plist (requires macOS), skipping..." ); } } // 환경별 .env 파일 복사 const envFilePath = path.join(__dirname, "..", `.env.${env}`); const targetEnvPath = path.join(__dirname, "..", ".env.local"); if (fs.existsSync(envFilePath)) { console.log(`📄 Copying .env.${env} to .env.local...`); fs.copyFileSync(envFilePath, targetEnvPath); console.log("✅ Environment variables updated"); } else { console.log(`⚠️ .env.${env} not found, using existing .env`); } console.log(""); console.log("🎉 Environment configuration completed!"); console.log(`📱 App Name: ${config.appName}`); console.log(`📦 App ID: ${config.appId}`); console.log(`🎨 Background: ${config.backgroundColor}`); console.log(`🍎 iOS Scheme: ${config.scheme}`); console.log(""); console.log("Next steps:"); console.log("1. Run: npm run mobile:sync"); console.log("2. Build: npm run android:build (or ios:build)"); console.log("3. Test on devices"); // 환경 정보를 JSON으로 저장 (CI/CD에서 사용 가능) const envInfoPath = path.join(__dirname, "..", "build-env.json"); fs.writeFileSync( envInfoPath, JSON.stringify( { environment: env, config: config, timestamp: new Date().toISOString(), }, null, 2 ) ); console.log(`📋 Environment info saved to build-env.json`);