@ngx-rocket/scripts
Advanced tools
Comparing version 5.0.0 to 5.1.0
@@ -0,1 +1,8 @@ | ||
# [5.1.0](https://github.com/ngx-rocket/scripts/compare/5.0.0...5.1.0) (2021-03-12) | ||
### Features | ||
* add option to parse JSON in environment variables ([#24](https://github.com/ngx-rocket/scripts/issues/24)) ([7f2c532](https://github.com/ngx-rocket/scripts/commit/7f2c532169c57f7a5c3bc706bad38bdb437dffc7)) | ||
# [5.0.0](https://github.com/ngx-rocket/scripts/compare/4.0.1...5.0.0) (2021-01-08) | ||
@@ -2,0 +9,0 @@ |
28
index.js
@@ -19,6 +19,9 @@ const path = require('path'); | ||
'env' | ||
)} <env_var> [<env_var2> ...] [--out <file>] [--format json|js] | ||
)} <env_var> [<env_var2> ...] [--out <file>] [--format json|js] [--parse-json] | ||
Export environment variables to a JSON or JavaScript file. | ||
Default output file is ${chalk.cyan('src/environments/.env.ts')} | ||
--parse-json If an environment variable's value is parsable JSON, | ||
it generates an object for it in output file. | ||
${chalk.blue('cordova')} <command> [options] [-- <cordova_options>] | ||
@@ -76,3 +79,4 @@ Execute Cordova commands. | ||
'dist', | ||
'verbose' | ||
'verbose', | ||
'parse-json' | ||
], | ||
@@ -108,3 +112,4 @@ string: [ | ||
this._options.out, | ||
this._options.format | ||
this._options.format, | ||
this._options['parse-json'] | ||
); | ||
@@ -120,3 +125,8 @@ case 'cordova': | ||
_env(vars, outputFile = 'src/environments/.env.ts', format = 'js') { | ||
_env( | ||
vars, | ||
outputFile = 'src/environments/.env.ts', | ||
format = 'js', | ||
parseJson = false | ||
) { | ||
if (vars.length === 0) { | ||
@@ -129,2 +139,8 @@ this._exit(`${chalk.red('Missing arguments')}\n`); | ||
env[v] = process.env[v] === undefined ? null : process.env[v]; | ||
if (parseJson) { | ||
try { | ||
env[v] = JSON.parse(env[v]); | ||
} catch {} | ||
} | ||
return env; | ||
@@ -142,3 +158,5 @@ }, {}), | ||
}); | ||
env = `export const env: { [s: string]: (string | null); } = ${env};\n`; | ||
env = `export const env: { [s: string]: (${ | ||
parseJson ? `any` : `string` | ||
} | null); } = ${env};\n`; | ||
} | ||
@@ -145,0 +163,0 @@ |
{ | ||
"name": "@ngx-rocket/scripts", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "Support scripts for ngX-Rocket projects", | ||
@@ -5,0 +5,0 @@ "repository": "ngx-rocket/scripts", |
@@ -31,3 +31,3 @@ # :rocket: ngx-rocket/scripts | ||
`ngx-scripts env <env_var> [<env_var2> ...] [--out <file>] [--format json|js]` | ||
`ngx-scripts env <env_var> [<env_var2> ...] [--out <file>] [--format json|js] [--parse-json]` | ||
@@ -56,2 +56,3 @@ Default output file is `src/environments/.env.ts` with JavaScript format. | ||
- `--yarn`: Use [Yarn](https://yarnpkg.com) instead of NPM to run the `build` script | ||
- `--parse-json`: During `env`, if an environment variable's value is parsable JSON, it will be a proper object in `.env.ts` | ||
@@ -58,0 +59,0 @@ > Note: Yarn is automatically used instead of NPM is the environment variable `NGX_PACKAGE_MANAGER` is set to `yarn` or |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21167
365
79