From 65b2cc1fd035b937f299105dc550bc8bc0feb66e Mon Sep 17 00:00:00 2001 From: mraerino Date: Fri, 30 Dec 2016 17:04:43 +0100 Subject: [PATCH 1/2] Fix typo in deploy command --- lib/commands/deploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/deploy.js b/lib/commands/deploy.js index d9977264339..56e919bc027 100644 --- a/lib/commands/deploy.js +++ b/lib/commands/deploy.js @@ -67,7 +67,7 @@ function sanityCheck(config) { exports.cmd = function(config, cmd) { var siteId = config.getSiteId(cmd), - siePromise = null; + sitePromise = null; if (siteId) { sitePromise = config.client.site(siteId); From b4174a788bcf8209da4ddb8b499abd199df4a7ce Mon Sep 17 00:00:00 2001 From: mraerino Date: Fri, 30 Dec 2016 17:14:16 +0100 Subject: [PATCH 2/2] Add "env" command for fetching environment variables Outputs dotenv compatible syntax --- bin/cli.js | 8 ++++++++ lib/commands/env.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 lib/commands/env.js diff --git a/bin/cli.js b/bin/cli.js index 24642e22573..cf1dcf7f249 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -13,6 +13,7 @@ var program = require("commander"), list = require("../lib/commands/list_sites"), updateSite = require("../lib/commands/update_site"), openSite = require("../lib/commands/open"), + env = require("../lib/commands/env"), updateNotifier = require('update-notifier'), pkg = require('../package.json'); @@ -77,6 +78,13 @@ program .description("Configure continuous deployment") .action(config.wrap(program, init.cmd)); +program + .command("env") + .description("Output configured env variables") + .option("-s --site-id [id]", "Fetch from site with ") + .option("-f --file [filename]", "Save to file called ") + .action(config.wrap(program, env.cmd)); + program .command("*","",{noHelp: true}) .action(function(cmd) { diff --git a/lib/commands/env.js b/lib/commands/env.js new file mode 100644 index 00000000000..d02113dd1a2 --- /dev/null +++ b/lib/commands/env.js @@ -0,0 +1,43 @@ +var chalk = require("chalk"), + inquirer = require("inquirer"), + when = require("when"), + fn = require("when/callbacks"), + fs = require("fs"), + confirm = require("../helpers/confirm"), + site_picker = require("../helpers/site_picker"), + errorLogger = require("../helpers/error_logger"); + +exports.cmd = function(config, cmd) { + var siteId = config.getSiteId(cmd), + sitePromise = null, + file = cmd.file; + + if (siteId) { + sitePromise = config.client.site(siteId); + } else { + sitePromise = site_picker.pickSite(config.client, {}); + } + + sitePromise + .then(function(site) { + const envVars = site.build_settings.env; + const envContents = Object.keys(envVars).map(function(key) { + return key + '="' + envVars[key] + '"'; + }).join('\n'); + + if(file) { + fs.writeFile(file, envContents, function(err) { + if(err) { + console.error("Could not save file."); + process.exit(1); + } else { + console.log("Saved to " + chalk.bold(file)); + process.exit(0); + } + }); + } else { + console.log(envContents); + process.exit(0); + } + }); +}; \ No newline at end of file