diff --git a/.easignore b/.easignore new file mode 100644 index 00000000..2dd3d4b2 --- /dev/null +++ b/.easignore @@ -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 diff --git a/.gitignore b/.gitignore index ffd3df35..94dbb839 100644 --- a/.gitignore +++ b/.gitignore @@ -12,10 +12,8 @@ web-build/ yarn-error.log /coverage -.env.development -.env.production -.env.staging -.env.qa +.env.* +!.env.sample /ios /android diff --git a/env.js b/env.js index 1e4c2524..f7c9215f 100644 --- a/env.js +++ b/env.js @@ -23,11 +23,17 @@ 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( @@ -35,7 +41,8 @@ const scriptIsEnvironmentDependant = ENVIRONMENT_DEPENDANT_SCRIPTS.some( ); // 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]; @@ -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.` diff --git a/package.json b/package.json index ed3c2877..09bcd7a1 100644 --- a/package.json +++ b/package.json @@ -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",