removing outdated logic to call process.exit on reset completion as all invocations use callbacks now. Allowing invocation of reset -p and -t without nodebb-plugin- or nodebb-theme- prefix

v1.18.x
Julian Lam 8 years ago
parent c25836b5fc
commit 9e23d09e5e

@ -12,20 +12,32 @@ Reset.reset = function (callback) {
db.init(function (err) { db.init(function (err) {
if (err) { if (err) {
winston.error(err.message); winston.error(err.message);
process.exit(); process.exit(1);
} }
if (nconf.get('t')) { if (nconf.get('t')) {
if(nconf.get('t') === true) { var themeId = nconf.get('t');
if (themeId === true) {
resetThemes(callback); resetThemes(callback);
} else { } else {
resetTheme(nconf.get('t'), callback); if (themeId.indexOf('nodebb-') !== 0) {
// Allow omission of `nodebb-theme-`
themeId = 'nodebb-theme-' + themeId;
}
resetTheme(themeId, callback);
} }
} else if (nconf.get('p')) { } else if (nconf.get('p')) {
if (nconf.get('p') === true) { var pluginId = nconf.get('p');
if (pluginId === true) {
resetPlugins(callback); resetPlugins(callback);
} else { } else {
resetPlugin(nconf.get('p'), callback); if (pluginId.indexOf('nodebb-') !== 0) {
// Allow omission of `nodebb-plugin-`
pluginId = 'nodebb-plugin-' + pluginId;
}
resetPlugin(pluginId, callback);
} }
} else if (nconf.get('w')) { } else if (nconf.get('w')) {
resetWidgets(callback); resetWidgets(callback);
@ -39,11 +51,7 @@ Reset.reset = function (callback) {
winston.error('[reset] Errors were encountered while resetting your forum settings: %s', err.message); winston.error('[reset] Errors were encountered while resetting your forum settings: %s', err.message);
} }
if (typeof callback === 'function') { callback();
callback();
} else {
process.exit(0);
}
}); });
} else { } else {
process.stdout.write('\nNodeBB Reset\n'.bold); process.stdout.write('\nNodeBB Reset\n'.bold);
@ -58,7 +66,7 @@ Reset.reset = function (callback) {
process.stdout.write('\nPlugin and theme reset flags (-p & -t) can take a single argument\n'); 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.stdout.write(' e.g. ./nodebb reset -p nodebb-plugin-mentions, ./nodebb reset -t nodebb-theme-persona\n');
process.exit(); process.exit(0);
} }
}); });
}; };
@ -67,11 +75,7 @@ function resetSettings(callback) {
var meta = require('./meta'); var meta = require('./meta');
meta.configs.set('allowLocalLogin', 1, function (err) { meta.configs.set('allowLocalLogin', 1, function (err) {
winston.info('[reset] Settings reset to default'); winston.info('[reset] Settings reset to default');
if (typeof callback === 'function') { callback(err);
callback(err);
} else {
process.exit();
}
}); });
} }
@ -82,7 +86,7 @@ function resetTheme(themeId, callback) {
fs.access('node_modules/' + themeId + '/package.json', function (err, fd) { fs.access('node_modules/' + themeId + '/package.json', function (err, fd) {
if (err) { if (err) {
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId); winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
process.exit(); callback(new Error('theme-not-found'));
} else { } else {
meta.themes.set({ meta.themes.set({
type: 'local', type: 'local',
@ -94,11 +98,7 @@ function resetTheme(themeId, callback) {
winston.info('[reset] Theme reset to ' + themeId); winston.info('[reset] Theme reset to ' + themeId);
} }
if (typeof callback === 'function') { callback();
callback();
} else {
process.exit(0);
}
}); });
} }
}); });
@ -112,11 +112,7 @@ function resetThemes(callback) {
id: 'nodebb-theme-persona' id: 'nodebb-theme-persona'
}, function (err) { }, function (err) {
winston.info('[reset] Theme reset to Persona'); winston.info('[reset] Theme reset to Persona');
if (typeof callback === 'function') { callback(err);
callback(err);
} else {
process.exit(0);
}
}); });
} }
@ -143,36 +139,25 @@ function resetPlugin(pluginId, callback) {
} else { } else {
winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId); winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId);
winston.info('[reset] No action taken.'); winston.info('[reset] No action taken.');
err = new Error('plugin-not-active');
} }
} }
if (typeof callback === 'function') { callback(err);
callback();
} else {
process.exit(0);
}
}); });
} }
function resetPlugins(callback) { function resetPlugins(callback) {
db.delete('plugins:active', function (err) { db.delete('plugins:active', function (err) {
winston.info('[reset] All Plugins De-activated'); winston.info('[reset] All Plugins De-activated');
if (typeof callback === 'function') { callback(err);
callback(err);
} else {
process.exit(0);
}
}); });
} }
function resetWidgets(callback) { function resetWidgets(callback) {
require('./widgets').reset(function (err) { require('./widgets').reset(function (err) {
winston.info('[reset] All Widgets moved to Draft Zone'); winston.info('[reset] All Widgets moved to Draft Zone');
if (typeof callback === 'function') { callback(err);
callback(err);
} else {
process.exit();
}
}); });
} }

Loading…
Cancel
Save