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) {
if (err) {
winston.error(err.message);
process.exit();
process.exit(1);
}
if (nconf.get('t')) {
if(nconf.get('t') === true) {
var themeId = nconf.get('t');
if (themeId === true) {
resetThemes(callback);
} 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')) {
if (nconf.get('p') === true) {
var pluginId = nconf.get('p');
if (pluginId === true) {
resetPlugins(callback);
} 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')) {
resetWidgets(callback);
@ -39,11 +51,7 @@ Reset.reset = function (callback) {
winston.error('[reset] Errors were encountered while resetting your forum settings: %s', err.message);
}
if (typeof callback === 'function') {
callback();
} else {
process.exit(0);
}
callback();
});
} else {
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(' 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');
meta.configs.set('allowLocalLogin', 1, function (err) {
winston.info('[reset] Settings reset to default');
if (typeof callback === 'function') {
callback(err);
} else {
process.exit();
}
callback(err);
});
}
@ -82,7 +86,7 @@ function resetTheme(themeId, callback) {
fs.access('node_modules/' + themeId + '/package.json', function (err, fd) {
if (err) {
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
process.exit();
callback(new Error('theme-not-found'));
} else {
meta.themes.set({
type: 'local',
@ -94,11 +98,7 @@ function resetTheme(themeId, callback) {
winston.info('[reset] Theme reset to ' + themeId);
}
if (typeof callback === 'function') {
callback();
} else {
process.exit(0);
}
callback();
});
}
});
@ -112,11 +112,7 @@ function resetThemes(callback) {
id: 'nodebb-theme-persona'
}, function (err) {
winston.info('[reset] Theme reset to Persona');
if (typeof callback === 'function') {
callback(err);
} else {
process.exit(0);
}
callback(err);
});
}
@ -143,36 +139,25 @@ function resetPlugin(pluginId, callback) {
} else {
winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId);
winston.info('[reset] No action taken.');
err = new Error('plugin-not-active');
}
}
if (typeof callback === 'function') {
callback();
} else {
process.exit(0);
}
callback(err);
});
}
function resetPlugins(callback) {
db.delete('plugins:active', function (err) {
winston.info('[reset] All Plugins De-activated');
if (typeof callback === 'function') {
callback(err);
} else {
process.exit(0);
}
callback(err);
});
}
function resetWidgets(callback) {
require('./widgets').reset(function (err) {
winston.info('[reset] All Widgets moved to Draft Zone');
if (typeof callback === 'function') {
callback(err);
} else {
process.exit();
}
callback(err);
});
}

Loading…
Cancel
Save