From ec76f6b7068574f9d6c5ebae24b38b74853472a4 Mon Sep 17 00:00:00 2001 From: Eric Ferraiuolo Date: Sun, 20 Nov 2016 23:54:34 -0800 Subject: [PATCH] Add `now.env` in package.json as env source (#119) This adds package.json as new source for environment variables, which are merged with `-e` CLI arguments (CLI args take precedence). With the ability to specify environment variables in package.json, developers don't need to remember which `-e` arguments to add, and can simply run `now`. ```json "now": { "env": { "foo": "bar" } } ``` The above is the same as running: ``` now -e foo=bar ``` Fixes #116 --- bin/now-deploy.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/now-deploy.js b/bin/now-deploy.js index 733f6d1..c99da73 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -21,6 +21,7 @@ import Now from '../lib' import toHumanPath from '../lib/utils/to-human-path' import promptOptions from '../lib/utils/prompt-options' import {handleError, error} from '../lib/error' +import readMetaData from '../lib/read-metadata' const argv = minimist(process.argv.slice(2), { string: [ @@ -291,8 +292,20 @@ async function sync(token) { } } + const {pkg: {now: pkgConfig = {}} = {}} = await readMetaData(path, { + deploymentType, + isStatic, + quiet: true + }) + const now = new Now(apiUrl, token, {debug}) - const envs = [].concat(argv.env || []) + + // Merge `now.env` from package.json with `-e` arguments. + const pkgEnv = pkgConfig.env + const envs = [ + ...Object.keys(pkgEnv || {}).map(k => `${k}=${pkgEnv[k]}`), + ...(argv.env || []) + ] let secrets const findSecret = async uidOrName => {