Knowasiak
Reward HN: Node script for recursive shell layout variable exchange in templates

Reward HN: Node script for recursive shell layout variable exchange in templates

Replace shell-layout atmosphere variables recursively. Presents capability in construction environments associated to envsubst with some additional aspects.

The procedure it works

Where you accumulate an environment variable file:

appsettings.construction.env

DB_ADMIN_PASSWORD=123456
DB_APP_USER_PASSWORD=654321

and a template file:

appsettings.Env.json.envt

{
  "App": {
    "DbAdminPassword": "${DB_ADMIN_PASSWORD}",
    "DbAppUserPassword": "${DB_APP_USER_PASSWORD}",
  }
}

Encompass this script for your source and bustle the next reveal from within the conclude level directory from which recursive search would possibly possibly well perhaps impartial easy originate:

node configure.js appsettings.construction.env

On this case this would possibly possibly well invent the file:

appsettings.Building.json

{
  "App": {
    "DbAdminPassword": "123456",
    "DbAppUserPassword": "654321",
  }
}

You would possibly perhaps perhaps perhaps presumably also utilize version administration system ignore scripts (e.g. .gitignore) to discontinuance the output info being dedicated, and forestall secrets and ways being dedicated to repositories.

Functions

(Optionally available) Case Controllable Atmosphere Name in Output File Name

Within the above example appsettings.Env.json.envt became appsettings.Building.json, from an environment file with the title appsettings.construction.env

Listing how the atmosphere title segment .Env. in the template (.envt) file title used to be modified with .Building. from the atmosphere title segment of the enter atmosphere (.env) file. The atmosphere title segment in the template file will also be .Env(pascal case),.ENV(upper case) or.env` (decrease case), and would possibly possibly well perhaps impartial output the atmosphere title in the identical case in the output file. Listing that an environment title segment is non-obligatory.

Reporting on Missing Variables in Template Recordsdata

This script will file the put apart a variable in the atmosphere file used to be no longer referenced in any template info.

Reporting on Missing Variables in Envrionment Recordsdata

This script will file the put apart a variable in the template file used to be no longer satisifed by the atmosphere file.

Licence

MIT Licence

Seize Me a Espresso

https://www.buymeacoffee.com/gbro3n

Read More

About the author: Charlie
Fill your life with experiences so you always have a great story to tell

Get involved!

Get Connected!
One of the Biggest Social Platform for Entrepreneurs, College Students and all. Come and join our community. Expand your network and get to know new people!

Discussion(s)

No comments yet
Knowasiak We would like to show you notifications so you don't miss chats & status updates.
Dismiss
Allow Notifications