convert-json-env
Advanced tools
Comparing version 1.0.3 to 1.1.0
21
index.js
@@ -17,2 +17,3 @@ #!/usr/bin/env node | ||
\t--suffix\tThe suffix of environment variables in env file. | ||
\t--embed\tThe suffix of environment variables in env file. | ||
` | ||
@@ -32,3 +33,3 @@ | ||
if (!args._.length) { | ||
if (!inputFile) { | ||
console.log('Invalid usage. Try `convert-json-env --help` for help.'); | ||
@@ -46,6 +47,14 @@ return; | ||
const st = Object.keys(data) | ||
.map(k => `${prefix}${k}${suffix}='${data[k]}'`) | ||
.join('\n'); | ||
fs.writeFileSync(outputFile, st); | ||
console.log(`✅ ${outputFile} created.`) | ||
if (args.embed) { | ||
const embed = | ||
Object.keys(data).map(k => `${k}: ${prefix}${k}${suffix}`).join(',\n '); | ||
console.log(`{ | ||
${embed} | ||
}`) | ||
} else { | ||
const envdata = Object.keys(data) | ||
.map(k => `${prefix}${k}${suffix}='${data[k]}'`) | ||
.join('\n'); | ||
fs.writeFileSync(outputFile, envdata); | ||
console.log(`✅ ${outputFile} created.`) | ||
} |
{ | ||
"name": "convert-json-env", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "A CLI tool for converting JSON to env file.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -34,4 +34,5 @@ # convert-json-env | ||
### Case 1. Export environment variables. | ||
```sh | ||
$convert-json-env example-firebaseConfig.json --prefix="export " | ||
$ convert-json-env example-firebaseConfig.json --prefix="export " | ||
✅ example-firebaseConfig.env created. | ||
@@ -49,4 +50,5 @@ | ||
### Case 2. Environment variables in Vue application. | ||
```sh | ||
$convert-json-env example-firebaseConfig.json --out=.local.env --prefix=VUE_APP_ | ||
$ convert-json-env example-firebaseConfig.json --out=.local.env --prefix=VUE_APP_ | ||
✅ .local.env created. | ||
@@ -62,4 +64,19 @@ | ||
VUE_APP_appId='1:234567890124:web:1234567890abcdef' | ||
``````` | ||
``` | ||
### Case 3. Standard output for code embedded in javascript. | ||
In this case, no files are output. | ||
```sh | ||
$ convert-json-env example-firebaseConfig.json --prefix=VUE_APP_ --embed | ||
{ | ||
apiKey: VUE_APP_apiKey, | ||
authDomain: VUE_APP_authDomain, | ||
databaseURL: VUE_APP_databaseURL, | ||
projectId: VUE_APP_projectId, | ||
storageBucket: VUE_APP_storageBucket, | ||
messagingSenderId: VUE_APP_messagingSenderId, | ||
appId: VUE_APP_appId | ||
} | ||
``` | ||
## All CLI Options | ||
@@ -66,0 +83,0 @@ |
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
6641
7
58
92