From 281440d652d442a055bd399e1dcfcd57a6b42117 Mon Sep 17 00:00:00 2001 From: zhongzhi107 Date: Tue, 7 Mar 2017 18:16:09 +0800 Subject: [PATCH 1/4] feat: Support more dotenv options Options Path Default: .env You can specify a custom path if your file containing environment variables is named or located differently. require('dotenv').config({path: '/custom/path/to/your/env/vars'}) Encoding Default: utf8 You may specify the encoding of your file containing environment variables using this option. require('dotenv').config({encoding: 'base64'}) --- index.js | 3 ++- lib/exec.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8623543..2426694 100755 --- a/index.js +++ b/index.js @@ -3,6 +3,8 @@ var program = require('commander'), scriptName = process.argv[2]; program + .option('-e, --encoding [type]', 'Specify the encoding of dotenv file') + .option('-p, --path [type]', 'Specify a custom path of dotenv file') .option('-s, --silent', 'silent') .parse(process.argv); @@ -42,4 +44,3 @@ exec(pkg.betterScripts[scriptName], program, function (error, stdout, stderr) { console.log('exec error: '+error); } }); - diff --git a/lib/exec.js b/lib/exec.js index 162f649..401e6e3 100644 --- a/lib/exec.js +++ b/lib/exec.js @@ -1,9 +1,15 @@ -require('dotenv').config({silent: true}); - var spawn = require('child_process').spawn, objectAssign = require('object-assign'); module.exports = function exec(script, program) { + var dotenvConfig = { silent: true }; + ['encoding', 'path'].forEach(function (key) { + if (key in program) { + dotenvConfig[key] = program[key]; + } + }); + + require('dotenv').config(dotenvConfig); var argv = process.argv.splice(3), command = (typeof script === 'string' ? script : script.command) + ' ' + argv.join(' '); From da65ee53294a0033ebe8df1821391575475ca480 Mon Sep 17 00:00:00 2001 From: zhongzhi107 Date: Tue, 7 Mar 2017 18:38:01 +0800 Subject: [PATCH 2/4] docs: Update readme.md --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7550af..e1992d5 100644 --- a/README.md +++ b/README.md @@ -123,8 +123,22 @@ using the shorter alias } ``` -Also for silence output, you can use `-s` or verbose `--silence` flags +And for silence output, you can use `-s` or verbose `--silence` flags ``` bnr watch-client -s ``` + +And you can use `-p` or verbose `--path` specify a custom path of dotenv file + +``` +bnr start-dev --path=/custom/path/to/your/env/vars +``` + +Also use `-e` or verbose `--encoding` specify the encoding of dotenv file + +``` +bnr start-dev --encoding=base64 +``` + +See [envdot docs](https://github.com/motdotla/dotenv) for more infomation From f2865d64e82d9a18502bf416425da707ce0b8762 Mon Sep 17 00:00:00 2001 From: zhongzhi107 Date: Mon, 20 Mar 2017 16:21:41 +0800 Subject: [PATCH 3/4] chore: Use object-assign --- lib/exec.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/exec.js b/lib/exec.js index 401e6e3..a51afd5 100644 --- a/lib/exec.js +++ b/lib/exec.js @@ -2,11 +2,9 @@ var spawn = require('child_process').spawn, objectAssign = require('object-assign'); module.exports = function exec(script, program) { - var dotenvConfig = { silent: true }; - ['encoding', 'path'].forEach(function (key) { - if (key in program) { - dotenvConfig[key] = program[key]; - } + var dotenvConfig = objectAssign({ silent: true }, { + encoding: program.encoding, + path: program.path }); require('dotenv').config(dotenvConfig); From 8cbd7e0a84df34e9f7a743afc08180b38977da23 Mon Sep 17 00:00:00 2001 From: zhongzhi107 Date: Mon, 20 Mar 2017 16:22:23 +0800 Subject: [PATCH 4/4] docs: Fix syntax error --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e1992d5..17a5758 100644 --- a/README.md +++ b/README.md @@ -129,13 +129,13 @@ And for silence output, you can use `-s` or verbose `--silence` flags bnr watch-client -s ``` -And you can use `-p` or verbose `--path` specify a custom path of dotenv file +And you can use `-p` or verbose `--path` to specify a custom path of dotenv file ``` bnr start-dev --path=/custom/path/to/your/env/vars ``` -Also use `-e` or verbose `--encoding` specify the encoding of dotenv file +Also use `-e` or verbose `--encoding` to specify the encoding of dotenv file ``` bnr start-dev --encoding=base64