github:https://github.com/calidion/shell-script-readerwith shell-script-reader you can read scripts without redefining variables or read into process.env each time when you changed a small portion of them. Shell Script ReaderShell Script Reader provides a way to read user customized shell script where a lot of environmental variables are defined.So you can easily share your shell variables with your node.js scripts.Instead of using a central process.env, you can use your environmental variable sets for each projects respectively. These way you will be eased from multiple projects and tests for various configurations.And still you can easily interacting with shell variables.Installnpm install --save shell-script-readerUsageImportts import { ShellScriptReader } from "shell-script-reader";Initializets import * as path from "path"; const filename = path.resolve(__dirname, "./env"); const reader = new ShellScriptReader(filename);env file example:```bash export AAA=111 export BBB=sosoisidoeod export ENV=E-SS OS export UN= export UN=aaasossos=aaa export AAAAA export exportSHELL COMMENTSwget https://www.google.com ```Only ^export started lines are read.We will have an env object:ts { AAA: '111', BBB: 'sosoisidoeod', ENV: 'E-SS OS', UN: '', AAAAA: '' }Read process.envIt provides access to process.env for convenience sake.ts const value = reader.getEnvRaw("KEY_NAME");Read Script Variablests const value = reader.getEnv("KEY_NAME");For ./env script defined above:ts const value = reader.getEnv("AAA"); // '111' const value = reader.getEnv("BBB"); // 'sosoisidoeod'If no key is provided, the whole object will be returned:ts const value = reader.getEnv(); // { AAA: '111', // BBB: 'sosoisidoeod', // ENV: 'E-SS OS', // UN: '', // AAAAA: '' }LicenseThe MIT License (MIT)
Submitted December 06, 2019 at 06:25AM by calidion
No comments:
Post a Comment