From ad732935fb5c9c38ee45d1a88e7a4998bb429b7e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 5 Dec 2016 10:23:28 -0500 Subject: [PATCH] closes #5254 --- app.js | 7 ++++++- src/reset.js | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app.js b/app.js index b3fe8f0fc2..d4cc855de9 100644 --- a/app.js +++ b/app.js @@ -73,7 +73,12 @@ if (nconf.get('setup') || nconf.get('install')) { } else if (nconf.get('upgrade')) { upgrade(); } else if (nconf.get('reset')) { - require('./src/reset').reset(); + async.waterfall([ + async.apply(require('./src/reset').reset), + async.apply(require('./build').build, true) + ], function (err) { + process.exit(err ? 1 : 0); + }); } else if (nconf.get('activate')) { activate(); } else if (nconf.get('plugins')) { diff --git a/src/reset.js b/src/reset.js index f38a2be4fd..3baf145edf 100644 --- a/src/reset.js +++ b/src/reset.js @@ -8,7 +8,7 @@ var db = require('./database'); var Reset = {}; -Reset.reset = function () { +Reset.reset = function (callback) { db.init(function (err) { if (err) { winston.error(err.message); @@ -17,20 +17,20 @@ Reset.reset = function () { if (nconf.get('t')) { if(nconf.get('t') === true) { - resetThemes(); + resetThemes(callback); } else { - resetTheme(nconf.get('t')); + resetTheme(nconf.get('t'), callback); } } else if (nconf.get('p')) { if (nconf.get('p') === true) { - resetPlugins(); + resetPlugins(callback); } else { - resetPlugin(nconf.get('p')); + resetPlugin(nconf.get('p'), callback); } } else if (nconf.get('w')) { - resetWidgets(); + resetWidgets(callback); } else if (nconf.get('s')) { - resetSettings(); + resetSettings(callback); } else if (nconf.get('a')) { require('async').series([resetWidgets, resetThemes, resetPlugins, resetSettings], function (err) { if (!err) { @@ -38,7 +38,12 @@ Reset.reset = function () { } else { winston.error('[reset] Errors were encountered while resetting your forum settings: %s', err.message); } - process.exit(); + + if (typeof callback === 'function') { + callback(); + } else { + process.exit(0); + } }); } else { process.stdout.write('\nNodeBB Reset\n'.bold); @@ -52,6 +57,7 @@ Reset.reset = function () { process.stdout.write('\nPlugin and theme reset flags (-p & -t) can take a single argument\n'); process.stdout.write(' e.g. ./nodebb reset -p nodebb-plugin-mentions, ./nodebb reset -t nodebb-theme-persona\n'); + process.exit(); } }); @@ -69,7 +75,7 @@ function resetSettings(callback) { }); } -function resetTheme(themeId) { +function resetTheme(themeId, callback) { var meta = require('./meta'); var fs = require('fs'); @@ -88,7 +94,11 @@ function resetTheme(themeId) { winston.info('[reset] Theme reset to ' + themeId); } - process.exit(); + if (typeof callback === 'function') { + callback(); + } else { + process.exit(0); + } }); } }); @@ -105,12 +115,12 @@ function resetThemes(callback) { if (typeof callback === 'function') { callback(err); } else { - process.exit(); + process.exit(0); } }); } -function resetPlugin(pluginId) { +function resetPlugin(pluginId, callback) { var active = false; async.waterfall([ @@ -136,7 +146,11 @@ function resetPlugin(pluginId) { } } - process.exit(); + if (typeof callback === 'function') { + callback(); + } else { + process.exit(0); + } }); } @@ -146,7 +160,7 @@ function resetPlugins(callback) { if (typeof callback === 'function') { callback(err); } else { - process.exit(); + process.exit(0); } }); }