From d6828c5ef4736ed75d6c5757a921b98b6a002003 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 1 May 2018 16:27:47 -0600 Subject: [PATCH 1/3] cli fixes --- bin/cli | 29 +++++------------------------ bin/cli-settings | 8 ++++++++ bin/util.js | 5 +++-- package.json | 3 +-- yarn.lock | 13 +------------ 5 files changed, 18 insertions(+), 40 deletions(-) diff --git a/bin/cli b/bin/cli index df2253261..9713d6f40 100755 --- a/bin/cli +++ b/bin/cli @@ -1,14 +1,12 @@ #!/usr/bin/env node -/** - * Module dependencies. - */ - -require('./util'); const program = require('commander'); -const { head, map } = require('lodash'); -const Matcher = require('did-you-mean'); +// We're requiring this here so it'll setup some promise rejection hooks to log +// out. +require('./util'); + +// Setup the program. program .command('serve', 'serve the application') .command('db', 'run database commands') @@ -24,20 +22,3 @@ program 'provides utilities for interacting with the plugin system' ) .parse(process.argv); - -// If the command wasn't found, output help. -const commands = map(program.commands, '_name'); -const command = head(program.args); -if (!commands.includes(command)) { - const m = new Matcher(commands); - const similarCommands = m.list(command); - - console.error( - `cli '${command}' is not a talk cli command. See 'cli --help'.` - ); - if (similarCommands.length > 0) { - const sc = similarCommands.map(({ value }) => `\t${value}\n`).join(''); - console.error(`\nThe most similar commands are\n${sc}`); - } - process.exit(1); -} diff --git a/bin/cli-settings b/bin/cli-settings index 7f449e0d5..d4ff3480e 100755 --- a/bin/cli-settings +++ b/bin/cli-settings @@ -5,6 +5,7 @@ const program = require('commander'); const inquirer = require('inquirer'); const mongoose = require('../services/mongoose'); const SettingsService = require('../services/settings'); +const cache = require('../services/cache'); // Register the shutdown criteria. util.onshutdown([() => mongoose.disconnect()]); @@ -13,6 +14,13 @@ util.onshutdown([() => mongoose.disconnect()]); * Change the organization name */ async function changeOrgName() { + try { + await cache.init(); + } catch (err) { + console.error(err); + util.shutdown(1); + } + try { let settings = await SettingsService.retrieve(); diff --git a/bin/util.js b/bin/util.js index 648c79bcc..3b07f31bf 100644 --- a/bin/util.js +++ b/bin/util.js @@ -4,7 +4,8 @@ require('../services/env'); const debug = require('debug')('talk:util'); const { uniq } = require('lodash'); -const util = (module.exports = {}); +// Setup the utilities. +const util = {}; /** * Stores an array of functions that should be executed in the event that the @@ -15,7 +16,7 @@ util.toshutdown = []; /** * Calls all the shutdown functions and then ends the process. - * @param {Number} [defaultCode=0] default return code upon sucesfull shutdown. + * @param {Number} [defaultCode=0] default return code upon successful shutdown. */ util.shutdown = (defaultCode = 0, signal = null) => { if (signal) { diff --git a/package.json b/package.json index c7e9a78c1..80e11cde8 100644 --- a/package.json +++ b/package.json @@ -79,11 +79,11 @@ "babel-polyfill": "^6.26.0", "babel-preset-es2015": "6.24.1", "babel-preset-react": "^6.23.0", - "bunyan-debug-stream": "^1.0.8", "bcryptjs": "^2.4.3", "bowser": "^1.7.2", "brotli-webpack-plugin": "^0.5.0", "bunyan": "^1.8.12", + "bunyan-debug-stream": "^1.0.8", "cli-table": "^0.3.1", "clipboard": "^1.7.1", "colors": "^1.1.2", @@ -98,7 +98,6 @@ "dataloader": "^1.3.0", "debug": "3.1.0", "dialog-polyfill": "^0.4.9", - "did-you-mean": "^0.0.1", "dotenv": "^4.0.0", "ejs": "^2.5.7", "env-rewrite": "^1.0.2", diff --git a/yarn.lock b/yarn.lock index 74659a4b0..9a455a9a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2982,13 +2982,6 @@ dialog-polyfill@^0.4.9: version "0.4.9" resolved "https://registry.yarnpkg.com/dialog-polyfill/-/dialog-polyfill-0.4.9.tgz#c690b3727c3d82e0f947bd5b910b32af8a2ef57d" -did-you-mean@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/did-you-mean/-/did-you-mean-0.0.1.tgz#8851ce82407903cb62c12cb6ad4f676921ccdec3" - dependencies: - levenshtein "*" - underscore "*" - diff@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" @@ -6487,10 +6480,6 @@ leven@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/leven/-/leven-2.1.0.tgz#c2e7a9f772094dee9d34202ae8acce4687875580" -levenshtein@*: - version "1.0.5" - resolved "https://registry.yarnpkg.com/levenshtein/-/levenshtein-1.0.5.tgz#3911737a9cb56da345d008f55782c6f138979ba3" - levn@^0.3.0, levn@~0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" @@ -11503,7 +11492,7 @@ undefsafe@^2.0.1: dependencies: debug "^2.2.0" -underscore@*, underscore@>=1.3.1: +underscore@>=1.3.1: version "1.8.3" resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022" From 7c16ae222002457430ef7288901958f64426d55c Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 2 May 2018 10:17:41 -0600 Subject: [PATCH 2/3] cli fix --- bin/util.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/util.js b/bin/util.js index 3b07f31bf..78664daa3 100644 --- a/bin/util.js +++ b/bin/util.js @@ -64,3 +64,5 @@ process.on('unhandledRejection', err => { console.error(err); process.exit(1); }); + +module.exports = util; From f5099d94bcef86bea9035d5d7560e58ade6cb91b Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 3 May 2018 14:32:56 -0600 Subject: [PATCH 3/3] fix --- bin/cli-settings | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/bin/cli-settings b/bin/cli-settings index d4ff3480e..72f42672d 100755 --- a/bin/cli-settings +++ b/bin/cli-settings @@ -4,7 +4,7 @@ const util = require('./util'); const program = require('commander'); const inquirer = require('inquirer'); const mongoose = require('../services/mongoose'); -const SettingsService = require('../services/settings'); +const Settings = require('../services/settings'); const cache = require('../services/cache'); // Register the shutdown criteria. @@ -16,15 +16,11 @@ util.onshutdown([() => mongoose.disconnect()]); async function changeOrgName() { try { await cache.init(); - } catch (err) { - console.error(err); - util.shutdown(1); - } - try { - let settings = await SettingsService.retrieve(); + // Get the original settings. + const settings = await Settings.retrieve('organizationName'); - let { organizationName } = await inquirer.prompt([ + const { organizationName } = await inquirer.prompt([ { name: 'organizationName', message: 'Organization Name', @@ -33,9 +29,8 @@ async function changeOrgName() { ]); if (settings.organizationName !== organizationName) { - settings.organizationName = organizationName; - - await SettingsService.update(settings); + // Set the organization name if there was a mutation to it. + await Settings.update({ organizationName }); console.log('Settings were updated.'); } else { @@ -44,9 +39,9 @@ async function changeOrgName() { } catch (err) { console.error(err); util.shutdown(1); + } finally { + util.shutdown(); } - - util.shutdown(); } //==============================================================================