This script was initially created to manage the environment configuration and secrets of any file-based project.
It allows the developer to exclude sensitive files from git version control and help keep every environment folder organized with relative paths, similar to the root project.
The script conditionally includes special treatment for development with React Native and Expo, but can be easily adjusted to ignore this part.
The EAS Build process uses the contents of .gitignore file to determine which files to include in the created JS bundle. If however the files are excluded from git version control, they are not included in the bundle unless they are explicitly included via the .easignore file.
If Expo is detected, the .easignore file will be automatically updated and the environment files entries will be included in the EAS Build process and still kept outside git version control.
chmod +x ./update-env.sh
./update-env.sh production
- Copy the
update-env.sh
script to the root of the project - The script checks for the existence of the
.environment
folder in the root of the project - If the
.environment
folder exists, it checks for the existence of theproduction
subfolder - It makes sure all files that need to be included in git version control are included, and all files that are not, are excluded.
- It overrides the project files with the ones found in the
production
subfolder - To make sure everything is copied correctly, the
production
subfolder needs uses the same folder structure as the root project directory. - Once copied, the .gitignore file is updated to include the new entries
- .gitignore changes that are managed by the script are organized neatly in a special section inside the .gitignore file
- If Expo app.json, app.config.js or app.config.ts files are found, the .easignore file is also created and updated based on the .gitignore file with "a twist"
- The environment files that are ignored in the .gitignore file are now included in the .easignore file.
- .gitignore and .easignore existing entries are kept unchanged
- The
update-env.lock
file is created to keep track of the changes made by the script and to make sure when changes are made, it is visible in git version control - If you want to add more files to the .gitignore file, but have them managed by the script, you can add them to
the
update-env.ignore
file
- This setup is meant for two environments,
production
andstaging
- Add the
use-production
anduse-staging
scripts to yourpackage.json
file - Create a
.environment
folder in the root of your project - Create a
production
folder in the.environment
folder - Add production files to the
production
folder while respecting the same relative path structure as the root project - Run
./update-env.sh production
to update the project - Create a
staging
folder in the.environment
folder - Add staging files to the
staging
folder while respecting the same relative path structure as the root project - Run
./update-env.sh staging
to update the project
- The script can work with only one environment
- The
.ignored
folder is meant to be used as is and is useful for case where you need to use a secret/certificate, but it is not linked to the project files - If you want to include a file in multiple environments, use copy and paste to add it manually to each one :) Trust me, it's better this way.
- Environments are determined by the subfolders present in the
.environment
folder - An example archive of the
.environment
folder was committed along with the script - There are 2 environments added,
production
andstaging
+ a generic.ignored
folder - The
update-env.ignore
file is currently populated with entries used in Expo React Native projects - The
update-env.lock
file is updated during the script execution, and used similar to a log file - The
#.gitignore file placeholder
and#.easignore file placeholder
are simple lines added to take place of existing lines in both files - they are used simply as part of the example and can be deleted