|
| 1 | +[](https://github.com/smbcheeky/update-env) |
| 2 | +[](https://img.shields.io/github/stars/smbcheeky/update-env) |
| 3 | + |
| 4 | +## Description |
| 5 | + |
| 6 | +This script was initially created to manage the environment configuration and secrets of any file-based project. |
| 7 | + |
| 8 | +It allows the developer to exclude sensitive files from git version control and help keep every environment folder |
| 9 | +organized with relative paths, similar to the root project. |
| 10 | + |
| 11 | +The script conditionally includes special treatment for development with React Native and Expo, but can be easily |
| 12 | +adjusted to ignore this part. |
| 13 | + |
| 14 | +## Expo, React Native, EAS Build and .easignore |
| 15 | + |
| 16 | +The EAS Build process uses the contents of .gitignore file to determine which files to include in the created JS bundle. |
| 17 | +If however the files are excluded from git version control, they are not included in the bundle unless they are |
| 18 | +explicitly included via the .easignore file. |
| 19 | + |
| 20 | +If Expo is detected, the .easignore file will be automatically updated and the environment files entries will be |
| 21 | +included in the EAS Build process and still kept outside git version control. |
| 22 | + |
| 23 | +## How does it work? |
| 24 | + |
| 25 | +```bash |
| 26 | +chmod +x ./update-env.sh |
| 27 | +./update-env.sh production |
| 28 | +``` |
| 29 | + |
| 30 | +1. Copy the `update-env.sh` script to the root of the project |
| 31 | +2. The script checks for the existence of the `.environment` folder in the root of the project |
| 32 | +3. If the `.environment` folder exists, it checks for the existence of the `production` subfolder |
| 33 | +4. It makes sure all files that need to be included in git version control are included, and all files that are not, are |
| 34 | + excluded. |
| 35 | +5. It overrides the project files with the ones found in the `production` subfolder |
| 36 | +6. To make sure everything is copied correctly, the `production` subfolder needs uses the same folder structure as the |
| 37 | + root project directory. |
| 38 | +7. Once copied, the .gitignore file is updated to include the new entries |
| 39 | +8. .gitignore changes that are managed by the script are organized neatly in a special section inside the .gitignore |
| 40 | + file |
| 41 | +9. If Expo app.json, app.config.js or app.config.ts files are found, the .easignore file is also created and updated |
| 42 | + based on the .gitignore file with "a twist" |
| 43 | +10. The environment files that are ignored in the .gitignore file are now included in the .easignore file. |
| 44 | +11. .gitignore and .easignore existing entries are kept unchanged |
| 45 | +12. The `update-env.lock` file is created to keep track of the changes made by the script and to make sure when changes |
| 46 | + are made, it is visible in git version control |
| 47 | +13. If you want to add more files to the .gitignore file, but have them managed by the script, you can add them to |
| 48 | + the `update-env.ignore` file |
| 49 | + |
| 50 | +## Setup example |
| 51 | + |
| 52 | +- This setup is meant for two environments, `production` and `staging` |
| 53 | +- Add the `use-production` and `use-staging` scripts to your `package.json` file |
| 54 | +- Create a `.environment` folder in the root of your project |
| 55 | +- Create a `production` folder in the `.environment` folder |
| 56 | +- Add production files to the `production` folder while respecting the same relative path structure as the root project |
| 57 | +- Run `./update-env.sh production` to update the project |
| 58 | +- Create a `staging` folder in the `.environment` folder |
| 59 | +- Add staging files to the `staging` folder while respecting the same relative path structure as the root project |
| 60 | +- Run `./update-env.sh staging` to update the project |
| 61 | + |
| 62 | +## Other notes |
| 63 | + |
| 64 | +- The script can work with only one environment |
| 65 | +- The `.ignored` folder is meant to be used as is and is useful for case where you need to use a secret/certificate, but |
| 66 | + it is not linked to the project files |
| 67 | +- If you want to include a file in multiple environments, use copy and paste to add it manually to each one :) Trust me, |
| 68 | + it's better this way. |
| 69 | +- Environments are determined by the subfolders present in the `.environment` folder |
| 70 | +- An example archive of the `.environment` folder was committed along with the script |
| 71 | +- There are 2 environments added, `production` and `staging` + a generic `.ignored` folder |
| 72 | +- The `update-env.ignore` file is currently populated with entries used in Expo React Native projects |
| 73 | +- The `update-env.lock` file is updated during the script execution, and used similar to a log file |
| 74 | +- The `#.gitignore file placeholder` and `#.easignore file placeholder` are simple lines added to take place of existing |
| 75 | + lines in both files - they are used simply as part of the example and can be deleted |
0 commit comments