add staging ios app build script
This commit is contained in:
@@ -33,9 +33,17 @@ esac
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
echo "==> Switching to .env.${ENV}"
|
||||
echo "==> Switching to env/${ENV} → .env"
|
||||
npm run use-env -- "$ENV"
|
||||
|
||||
# Release Archive 时 NODE_ENV=production,Expo 会加载根目录 .env.production 并覆盖 .env
|
||||
for legacy in .env.production .env.staging .env.development; do
|
||||
if [[ -f "$legacy" ]]; then
|
||||
echo "::error::Found legacy $legacy — it overrides use-env on Release builds. Use app-expo/env/ templates only." >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "==> expo prebuild --platform ios --clean"
|
||||
npx expo prebuild --platform ios --clean
|
||||
|
||||
|
||||
@@ -1,22 +1,39 @@
|
||||
/**
|
||||
* 将 app-expo/.env.<name> 复制为 .env,供 Metro/Expo 读取 EXPO_PUBLIC_*。
|
||||
* 将 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)。
|
||||
*
|
||||
* 参数 name → 源文件:
|
||||
* development → .env.development(仓库已提交;npm start / prestart 默认)
|
||||
* staging → .env.staging
|
||||
* production → .env.production
|
||||
* development → env/development
|
||||
* staging → env/staging
|
||||
* production → env/production
|
||||
*
|
||||
* CI:.github/workflows/app-expo-deploy.yml 按分支/tag 调用本脚本,与后端 env 策略对齐。
|
||||
* CI:.github/workflows/app-expo-deploy.yml 按分支/tag 调用本脚本。
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const env = process.argv[2] || 'development';
|
||||
const src = path.join(__dirname, '..', `.env.${env}`);
|
||||
const dest = path.join(__dirname, '..', '.env');
|
||||
if (fs.existsSync(src)) {
|
||||
fs.copyFileSync(src, dest);
|
||||
console.log(`Switched to .env.${env}`);
|
||||
} else {
|
||||
console.error(`Missing .env.${env}`);
|
||||
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})`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
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.',
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user