diff --git a/bin/cli b/bin/cli index e01c9cd64..707f41032 100755 --- a/bin/cli +++ b/bin/cli @@ -4,6 +4,7 @@ * Module dependencies. */ +require('./util'); const program = require('commander'); const {head, map} = require('lodash'); const Matcher = require('did-you-mean'); @@ -18,40 +19,37 @@ program .command('users', 'work with the application auth') .command('migration', 'provides utilities for migrating the database') .command('verify', 'provides utilities for performing data verification') - .command( - 'plugins', - 'provides utilities for interacting with the plugin system' - ) + .command('plugins', 'provides utilities for interacting with the plugin system') .parse(process.argv); // If the command wasn't found, output help. -const cmds = map(program.commands, '_name'); -const cmd = head(program.args); -if (!cmds.includes(cmd)) { - const m = new Matcher(cmds); - const similarCMDs = m.list(cmd); +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 '${cmd}' is not a talk cli command. See 'cli --help'.`); - if (similarCMDs.length > 0) { - const sc = similarCMDs.map(({value}) => `\t${value}\n`).join(''); + 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); } -/** - * When this provess exists, check to see if we have a running command, if we do - * check to see if it is still running. If it is, then kill it with a SIGINT - * signal. This is for the use case where we want to kill the process that is - * labled with the PID written out by the parent process. - */ -process.once('exit', () => { - if ( +// /** +// * When this process exists, check to see if we have a running command, if we do +// * check to see if it is still running. If it is, then kill it with a SIGINT +// * signal. This is for the use case where we want to kill the process that is +// * labeled with the PID written out by the parent process. +// */ +// process.once('exit', () => { +// if ( - // program.runningCommand && - program.runningCommand.killed === false && - program.runningCommand.exitCode === null - ) { - program.runningCommand.kill('SIGINT'); - } -}); +// // program.runningCommand && +// program.runningCommand.killed === false && +// program.runningCommand.exitCode === null +// ) { +// program.runningCommand.kill('SIGINT'); +// } +// }); diff --git a/bin/cli-assets b/bin/cli-assets index 456f16877..5c1780c5d 100755 --- a/bin/cli-assets +++ b/bin/cli-assets @@ -4,6 +4,7 @@ * Module dependencies. */ +const util = require('./util'); const program = require('commander'); const parseDuration = require('ms'); const Table = require('cli-table'); @@ -12,7 +13,6 @@ const CommentModel = require('../models/comment'); const AssetsService = require('../services/assets'); const mongoose = require('../services/mongoose'); const scraper = require('../services/scraper'); -const util = require('./util'); const inquirer = require('inquirer'); // Register the shutdown criteria. diff --git a/bin/cli-jobs b/bin/cli-jobs index 345b22b56..26eeab147 100755 --- a/bin/cli-jobs +++ b/bin/cli-jobs @@ -4,10 +4,10 @@ * Module dependencies. */ +const util = require('./util'); const program = require('commander'); const scraper = require('../services/scraper'); const mailer = require('../services/mailer'); -const util = require('./util'); const mongoose = require('../services/mongoose'); const kue = require('../services/kue'); diff --git a/bin/cli-migration b/bin/cli-migration index f730b8fbb..18a8c012a 100755 --- a/bin/cli-migration +++ b/bin/cli-migration @@ -4,8 +4,8 @@ * Module dependencies. */ -const program = require('commander'); const util = require('./util'); +const program = require('commander'); const inquirer = require('inquirer'); const mongoose = require('../services/mongoose'); const MigrationService = require('../services/migration'); diff --git a/bin/cli-plugins b/bin/cli-plugins index 8217b023f..4f293b0c3 100755 --- a/bin/cli-plugins +++ b/bin/cli-plugins @@ -7,6 +7,7 @@ // Interface heavily inspired by the yarn package manager: // https://yarnpkg.com/ +require('./util'); const program = require('commander'); const inquirer = require('inquirer'); diff --git a/bin/cli-serve b/bin/cli-serve index cc00f84ed..3e356d829 100755 --- a/bin/cli-serve +++ b/bin/cli-serve @@ -1,7 +1,7 @@ #!/usr/bin/env node -const program = require('commander'); const util = require('./util'); +const program = require('commander'); const serve = require('../serve'); //============================================================================== diff --git a/bin/cli-settings b/bin/cli-settings index 481e5b2bf..6ffacbeaf 100755 --- a/bin/cli-settings +++ b/bin/cli-settings @@ -1,10 +1,10 @@ #!/usr/bin/env node +const util = require('./util'); const program = require('commander'); const inquirer = require('inquirer'); const mongoose = require('../services/mongoose'); const SettingsService = require('../services/settings'); -const util = require('./util'); // Register the shutdown criteria. util.onshutdown([() => mongoose.disconnect()]); diff --git a/bin/cli-setup b/bin/cli-setup index 35521e05a..0f14add55 100755 --- a/bin/cli-setup +++ b/bin/cli-setup @@ -4,6 +4,7 @@ * Module dependencies. */ +const util = require('./util'); const program = require('commander'); const inquirer = require('inquirer'); const mongoose = require('../services/mongoose'); @@ -12,7 +13,6 @@ const MODERATION_OPTIONS = require('../models/enum/moderation_options'); const SettingsService = require('../services/settings'); const SetupService = require('../services/setup'); const UsersService = require('../services/users'); -const util = require('./util'); const errors = require('../errors'); // Register the shutdown criteria. diff --git a/bin/cli-token b/bin/cli-token index 87d955df9..dc1b09e6f 100755 --- a/bin/cli-token +++ b/bin/cli-token @@ -4,10 +4,10 @@ * Module dependencies. */ +const util = require('./util'); const program = require('commander'); const mongoose = require('../services/mongoose'); const TokensService = require('../services/tokens'); -const util = require('./util'); const Table = require('cli-table'); // Register the shutdown criteria. diff --git a/bin/cli-users b/bin/cli-users index b80af1fab..71c51e44d 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -156,6 +156,10 @@ async function searchUsers() { throw errors[0]; } + if (data.users === null) { + return []; + } + return data.users.nodes.map((user) => { const emails = user.profiles .filter(({provider}) => provider === 'local') diff --git a/bin/cli-verify b/bin/cli-verify index 9a4c30ab1..5a55f2bd2 100755 --- a/bin/cli-verify +++ b/bin/cli-verify @@ -4,9 +4,9 @@ * Module dependencies. */ +const util = require('./util'); const program = require('commander'); const mongoose = require('../services/mongoose'); -const util = require('./util'); const databaseVerifications = require('./verifications/database'); // Register the shutdown criteria. diff --git a/bin/util.js b/bin/util.js index abcbeaade..546607c20 100644 --- a/bin/util.js +++ b/bin/util.js @@ -1,3 +1,7 @@ + +// Setup the environment. +require('../services/env'); + const debug = require('debug')('talk:util'); const util = module.exports = {}; diff --git a/config.js b/config.js index e617b93e8..954d7a8df 100644 --- a/config.js +++ b/config.js @@ -2,17 +2,8 @@ // application. All defaults are assumed here, validation should also be // completed here. -// Perform rewrites to the runtime environment variables based on the contents -// of the process.env.REWRITE_ENV if it exists. This is done here as it is the -// entrypoint for the entire applications configuration. -require('env-rewrite').rewrite(); - -if (process.env.NODE_ENV !== 'test') { - - // Apply all the configuration provided in the .env file if it isn't already - // in the environment. - require('dotenv').config(); -} +// Setup the environment. +require('./services/env'); const uniq = require('lodash/uniq'); const ms = require('ms'); diff --git a/models/user.js b/models/user.js index 17e3a173d..37edf4dde 100644 --- a/models/user.js +++ b/models/user.js @@ -295,6 +295,14 @@ UserSchema.virtual('hasVerifiedEmail').get(function() { }); }); +UserSchema.virtual('system') + .get(function() { + return this._system; + }) + .set(function(system) { + this._system = system; + }); + /** * banned returns true when the user is currently banned, and sets the banned * status locally. diff --git a/package.json b/package.json index 5675ca588..7c8a0f9a0 100644 --- a/package.json +++ b/package.json @@ -173,6 +173,7 @@ "snake-case": "2.1.0", "style-loader": "^0.16.0", "subscriptions-transport-ws": "^0.7.2", + "supports-color": "^4", "timeago.js": "^2.0.3", "timekeeper": "^1.0.0", "tlds": "^1.196.0", diff --git a/services/env.js b/services/env.js new file mode 100644 index 000000000..a9feb67a8 --- /dev/null +++ b/services/env.js @@ -0,0 +1,11 @@ +// Perform rewrites to the runtime environment variables based on the contents +// of the process.env.REWRITE_ENV if it exists. This is done here as it is the +// entrypoint for the entire applications configuration. +require('env-rewrite').rewrite(); + +if (process.env.NODE_ENV !== 'test') { + + // Apply all the configuration provided in the .env file if it isn't already + // in the environment. + require('dotenv').config(); +} diff --git a/services/mongoose.js b/services/mongoose.js index 747df2d66..6f0759908 100644 --- a/services/mongoose.js +++ b/services/mongoose.js @@ -1,14 +1,14 @@ -const mongoose = require('mongoose'); -const debug = require('debug')('talk:db'); -const enabled = require('debug').enabled; -const queryDebugger = require('debug')('talk:db:query'); - const { MONGO_URL, WEBPACK, CREATE_MONGO_INDEXES, } = require('../config'); +const mongoose = require('mongoose'); +const debug = require('debug')('talk:db'); +const enabled = require('debug').enabled; +const queryDebugger = require('debug')('talk:db:query'); + // Loading the formatter from Mongoose: // // https://github.com/Automattic/mongoose/blob/1a93d1f4d12e441e17ddf451e96fbc5f6e8f54b8/lib/drivers/node-mongodb-native/collection.js#L182 diff --git a/yarn.lock b/yarn.lock index 2448dd1d6..cbdddb034 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8997,7 +8997,7 @@ supports-color@^3.1.0, supports-color@^3.1.2, supports-color@^3.2.3: dependencies: has-flag "^1.0.0" -supports-color@^4.0.0, supports-color@^4.4.0: +supports-color@^4, supports-color@^4.0.0, supports-color@^4.4.0: version "4.5.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b" dependencies: