Skip to content

Commit

Permalink
Merge pull request #40 from rootstrap/build/expo_refactor_local_build…
Browse files Browse the repository at this point in the history
…_script

build(expo): refactor local build script
  • Loading branch information
asdolo authored Aug 30, 2024
2 parents c7abd7e + 006ba11 commit eb82215
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
29 changes: 29 additions & 0 deletions .easignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
node_modules/
.expo/
dist/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/
yarn-error.log
/coverage

# Allow local environment files to be copied to the build directory
!.env.*

/ios
/android

# macOS
.DS_Store
*.apk
*.ipa

expo-env.d.ts

# cli
cli/README.md
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ web-build/
yarn-error.log
/coverage

.env.development
.env.production
.env.staging
.env.qa
.env.*
!.env.sample

/ios
/android
Expand Down
16 changes: 14 additions & 2 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,26 @@ const APP_ENV =

const isEASBuild = process.env.EAS_BUILD === 'true';

const LOCAL_BUILD_SCRIPT_PATTERNS = ['--local', 'eas-cli-local-build-plugin'];
const isLocalBuild = LOCAL_BUILD_SCRIPT_PATTERNS.some((pattern) =>
process.env.npm_lifecycle_script?.includes(pattern)
);

const ENVIRONMENT_DEPENDANT_SCRIPTS = [
'expo start',
'expo prebuild',
'eas build',
'expo run',
'eas-cli-local-build-plugin',
];

const scriptIsEnvironmentDependant = ENVIRONMENT_DEPENDANT_SCRIPTS.some(
(script) => process.env.npm_lifecycle_script?.includes(script)
);

// Check if the environment file has to be validated for the current running script and build method
const shouldValidateEnv = isEASBuild && scriptIsEnvironmentDependant;
const shouldValidateEnv =
(isEASBuild || isLocalBuild) && scriptIsEnvironmentDependant;

const easEnvironmentFileVariable = `ENVIRONMENT_FILE_${APP_ENV.toUpperCase()}`;
const easEnvironmentFilePath = process.env[easEnvironmentFileVariable];
Expand Down Expand Up @@ -181,9 +188,14 @@ if (shouldValidateEnv) {
parsedWholeEnv.error.flatten().fieldErrors,

`\n❌ Missing variables in \x1b[1m\x1b[4m\x1b[31m${envFile}\x1b[0m file. Make sure all required variables are defined in the \x1b[1m\x1b[4m\x1b[31m${envFile}\x1b[0m file.`,
`\n💡 Tip: If you recently updated the \x1b[1m\x1b[4m\x1b[31m${envFile}\x1b[0m file and the error still persists, try restarting the server with the -cc flag to clear the cache.`,
];

if (isLocalBuild) {
messages.push(
`\n💡 Tip: If you recently updated the \x1b[1m\x1b[4m\x1b[31m${envFile}\x1b[0m file and the error still persists, try restarting the server with the -cc flag to clear the cache.`
);
}

if (isEASBuild) {
messages.push(
`\n☁️ For \x1b[1m\x1b[32mEAS Build\x1b[0m deployments, ensure the secret\x1b[1m\x1b[4m\x1b[31m${easEnvironmentFileVariable} \x1b[0m is defined in Project Secrets and has the proper environment file attached.`
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"build:development:android": "cross-env APP_ENV=development EXPO_NO_DOTENV=1 eas build --profile development --platform android ",
"build:staging:ios": "cross-env APP_ENV=staging EXPO_NO_DOTENV=1 eas build --profile staging --platform ios",
"build:staging:android": "cross-env APP_ENV=staging EXPO_NO_DOTENV=1 eas build --profile staging --platform android ",
"build:staging:ios:local": "cross-env APP_ENV=staging sh -c './scripts/set-env.sh EXPO_NO_DOTENV=1 eas build --profile staging --platform ios --local'",
"build:staging:android:local": "cross-env APP_ENV=staging sh -c './scripts/set-env.sh EXPO_NO_DOTENV=1 eas build --profile staging --platform android --local'",
"build:production:ios": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform ios",
"build:production:android": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform android ",
"postinstall": "husky install",
Expand Down

0 comments on commit eb82215

Please sign in to comment.