Simple Node JS js script that will recusively substitute placeholders in the form of ${ENV_VAR}
or $ENV_VAR
in the folder set in FILE_PATH
.
Only files with the extensions as set in allowedExtensions will be taken into account:
const allowedExtensions = ['.json', '.yml', '.yaml', '.csv', '.xml', '.properties', '.txt'];
Set the source folder to search in:
$ export FILE_PATH=<path to folder to substitute>
Eg:
├── my_source_folder
│ └── folder1
│ ├── file.txt - "Hello $WORLD"
Export the variables values to be substituted:
$ export ENV_VAR=testenv
Eg:
export WORLD=Uganda!
Run:
$ node cmd.js
All references to ENV_VAR
are now replaced by testenv
Eg:
├── my_source_folder
│ └── folder1
│ ├── file.txt - "Hello Uganda!"
Though this project is already covered by a GitHub Actions workflow which builds and publishes the Docker image, you can build it locally with the following command:
$ docker build . -t mekomsolutions/env-substitution