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.shscript to the root of the project - The script checks for the existence of the
.environmentfolder in the root of the project - If the
.environmentfolder exists, it checks for the existence of theproductionsubfolder - 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
productionsubfolder - To make sure everything is copied correctly, the
productionsubfolder 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.lockfile 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.ignorefile
- This setup is meant for two environments,
productionandstaging - Add the
use-productionanduse-stagingscripts to yourpackage.jsonfile - Create a
.environmentfolder in the root of your project - Create a
productionfolder in the.environmentfolder - Add production files to the
productionfolder while respecting the same relative path structure as the root project - Run
./update-env.sh productionto update the project - Create a
stagingfolder in the.environmentfolder - Add staging files to the
stagingfolder while respecting the same relative path structure as the root project - Run
./update-env.sh stagingto update the project
- The script can work with only one environment
- The
.ignoredfolder 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
.environmentfolder - An example archive of the
.environmentfolder was committed along with the script - There are 2 environments added,
productionandstaging+ a generic.ignoredfolder - The
update-env.ignorefile is currently populated with entries used in Expo React Native projects - The
update-env.lockfile is updated during the script execution, and used similar to a log file - The
#.gitignore file placeholderand#.easignore file placeholderare 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