2026-03-23 13:21:07 +08:00
|
|
|
|
/**
|
2026-05-20 10:27:40 +08:00
|
|
|
|
* 将 app-expo/env/<name> 复制为 .env,供 Metro/Expo 读取 EXPO_PUBLIC_*。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 环境模板放在 env/ 子目录,而非 .env.staging / .env.production:
|
|
|
|
|
|
* Release 构建时 Expo 会按 NODE_ENV=production 自动加载根目录 .env.production,
|
|
|
|
|
|
* 若与 use-env 写入的 .env 并存,production 会覆盖 staging(见 @expo/env getEnvFiles)。
|
2026-03-23 13:21:07 +08:00
|
|
|
|
*
|
|
|
|
|
|
* 参数 name → 源文件:
|
2026-05-20 10:27:40 +08:00
|
|
|
|
* development → env/development
|
|
|
|
|
|
* staging → env/staging
|
|
|
|
|
|
* production → env/production
|
2026-03-23 13:21:07 +08:00
|
|
|
|
*
|
2026-05-20 10:27:40 +08:00
|
|
|
|
* CI:.github/workflows/app-expo-deploy.yml 按分支/tag 调用本脚本。
|
2026-03-23 13:21:07 +08:00
|
|
|
|
*/
|
2026-03-20 15:15:35 +08:00
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
const path = require('path');
|
2026-05-20 10:27:40 +08:00
|
|
|
|
|
2026-03-20 15:15:35 +08:00
|
|
|
|
const env = process.argv[2] || 'development';
|
2026-05-20 10:27:40 +08:00
|
|
|
|
const root = path.join(__dirname, '..');
|
|
|
|
|
|
const src = path.join(root, 'env', env);
|
|
|
|
|
|
const dest = path.join(root, '.env');
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 旧路径;若仍存在会在 Release 构建中覆盖 .env */
|
|
|
|
|
|
const legacyEnvFile = path.join(root, `.env.${env}`);
|
|
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(src)) {
|
|
|
|
|
|
console.error(`Missing env/${env} (expected ${src})`);
|
2026-03-20 15:15:35 +08:00
|
|
|
|
process.exit(1);
|
|
|
|
|
|
}
|
2026-05-20 10:27:40 +08:00
|
|
|
|
|
|
|
|
|
|
fs.copyFileSync(src, dest);
|
|
|
|
|
|
console.log(`Switched to env/${env} → .env`);
|
|
|
|
|
|
|
|
|
|
|
|
if (fs.existsSync(legacyEnvFile)) {
|
|
|
|
|
|
console.warn(
|
|
|
|
|
|
`Warning: legacy ${path.basename(legacyEnvFile)} still exists. ` +
|
|
|
|
|
|
'Remove it or Release builds may load production values over .env.',
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|