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

Related Articles

What’s recent in Emacs 28.1?

By Mickey Petersen It’s that time again: there’s a new major version of Emacs and, with it, a treasure trove of new features and changes.Notable features include the formal inclusion of native compilation, a technique that will greatly speed up your Emacs experience.A critical issue surrounding the use of ligatures also fixed; without it, you…

Windows 11 Guide

A guide on setting up your Windows 11 Desktop with all the essential Applications, Tools, and Games to make your experience with Windows 11 great! Note: You can easily convert this markdown file to a PDF in VSCode using this handy extension Markdown PDF. Getting Started Windows 11 Desktop Bypass Windows 11’s TPM, CPU and…