mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: resetting theme will reset skin
async/await cli/reset
This commit is contained in:
28
app.js
28
app.js
@@ -21,25 +21,24 @@
|
|||||||
|
|
||||||
require('./require-main');
|
require('./require-main');
|
||||||
|
|
||||||
var nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
nconf.argv().env({
|
nconf.argv().env({
|
||||||
separator: '__',
|
separator: '__',
|
||||||
});
|
});
|
||||||
|
|
||||||
var async = require('async');
|
const winston = require('winston');
|
||||||
var winston = require('winston');
|
const path = require('path');
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
var file = require('./src/file');
|
const file = require('./src/file');
|
||||||
|
|
||||||
global.env = process.env.NODE_ENV || 'production';
|
global.env = process.env.NODE_ENV || 'production';
|
||||||
|
|
||||||
// Alternate configuration file support
|
// Alternate configuration file support
|
||||||
var configFile = path.resolve(__dirname, nconf.any(['config', 'CONFIG']) || 'config.json');
|
const configFile = path.resolve(__dirname, nconf.any(['config', 'CONFIG']) || 'config.json');
|
||||||
|
|
||||||
var configExists = file.existsSync(configFile) || (nconf.get('url') && nconf.get('secret') && nconf.get('database'));
|
const configExists = file.existsSync(configFile) || (nconf.get('url') && nconf.get('secret') && nconf.get('database'));
|
||||||
|
|
||||||
var prestart = require('./src/prestart');
|
const prestart = require('./src/prestart');
|
||||||
prestart.loadConfig(configFile);
|
prestart.loadConfig(configFile);
|
||||||
prestart.setupWinston();
|
prestart.setupWinston();
|
||||||
prestart.versionCheck();
|
prestart.versionCheck();
|
||||||
@@ -60,23 +59,12 @@ if (nconf.get('setup') || nconf.get('install')) {
|
|||||||
} else if (nconf.get('upgrade')) {
|
} else if (nconf.get('upgrade')) {
|
||||||
require('./src/cli/upgrade').upgrade(true);
|
require('./src/cli/upgrade').upgrade(true);
|
||||||
} else if (nconf.get('reset')) {
|
} else if (nconf.get('reset')) {
|
||||||
var options = {
|
require('./src/cli/reset').reset({
|
||||||
theme: nconf.get('t'),
|
theme: nconf.get('t'),
|
||||||
plugin: nconf.get('p'),
|
plugin: nconf.get('p'),
|
||||||
widgets: nconf.get('w'),
|
widgets: nconf.get('w'),
|
||||||
settings: nconf.get('s'),
|
settings: nconf.get('s'),
|
||||||
all: nconf.get('a'),
|
all: nconf.get('a'),
|
||||||
};
|
|
||||||
|
|
||||||
async.series([
|
|
||||||
async.apply(require('./src/cli/reset').reset, options),
|
|
||||||
require('./src/meta/build').buildAll,
|
|
||||||
], function (err) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0);
|
|
||||||
});
|
});
|
||||||
} else if (nconf.get('activate')) {
|
} else if (nconf.get('activate')) {
|
||||||
require('./src/cli/manage').activate(nconf.get('activate'));
|
require('./src/cli/manage').activate(nconf.get('activate'));
|
||||||
|
|||||||
134
src/cli/reset.js
134
src/cli/reset.js
@@ -1,61 +1,65 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
require('colors');
|
require('colors');
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var winston = require('winston');
|
const winston = require('winston');
|
||||||
var async = require('async');
|
const async = require('async');
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const util = require('util');
|
||||||
|
|
||||||
var db = require('../database');
|
const fsAccessAsync = util.promisify(fs.access);
|
||||||
var events = require('../events');
|
|
||||||
var meta = require('../meta');
|
|
||||||
var plugins = require('../plugins');
|
|
||||||
var widgets = require('../widgets');
|
|
||||||
var privileges = require('../privileges');
|
|
||||||
|
|
||||||
var dirname = require('./paths').baseDir;
|
const db = require('../database');
|
||||||
|
const events = require('../events');
|
||||||
|
const meta = require('../meta');
|
||||||
|
const plugins = require('../plugins');
|
||||||
|
const widgets = require('../widgets');
|
||||||
|
const privileges = require('../privileges');
|
||||||
|
|
||||||
var themeNamePattern = /^(@.*?\/)?nodebb-theme-.*$/;
|
const dirname = require('./paths').baseDir;
|
||||||
var pluginNamePattern = /^(@.*?\/)?nodebb-(theme|plugin|widget|rewards)-.*$/;
|
|
||||||
|
|
||||||
exports.reset = function (options, callback) {
|
const themeNamePattern = /^(@.*?\/)?nodebb-theme-.*$/;
|
||||||
var map = {
|
const pluginNamePattern = /^(@.*?\/)?nodebb-(theme|plugin|widget|rewards)-.*$/;
|
||||||
theme: function (next) {
|
|
||||||
var themeId = options.theme;
|
exports.reset = async function (options) {
|
||||||
|
const map = {
|
||||||
|
theme: async function () {
|
||||||
|
let themeId = options.theme;
|
||||||
if (themeId === true) {
|
if (themeId === true) {
|
||||||
resetThemes(next);
|
await resetThemes();
|
||||||
} else {
|
} else {
|
||||||
if (!themeNamePattern.test(themeId)) {
|
if (!themeNamePattern.test(themeId)) {
|
||||||
// Allow omission of `nodebb-theme-`
|
// Allow omission of `nodebb-theme-`
|
||||||
themeId = 'nodebb-theme-' + themeId;
|
themeId = 'nodebb-theme-' + themeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
resetTheme(themeId, next);
|
await resetTheme(themeId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugin: function (next) {
|
plugin: async function () {
|
||||||
var pluginId = options.plugin;
|
let pluginId = options.plugin;
|
||||||
if (pluginId === true) {
|
if (pluginId === true) {
|
||||||
resetPlugins(next);
|
await resetPlugins();
|
||||||
} else {
|
} else {
|
||||||
if (!pluginNamePattern.test(pluginId)) {
|
if (!pluginNamePattern.test(pluginId)) {
|
||||||
// Allow omission of `nodebb-plugin-`
|
// Allow omission of `nodebb-plugin-`
|
||||||
pluginId = 'nodebb-plugin-' + pluginId;
|
pluginId = 'nodebb-plugin-' + pluginId;
|
||||||
}
|
}
|
||||||
|
|
||||||
resetPlugin(pluginId, next);
|
await resetPlugin(pluginId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
widgets: resetWidgets,
|
widgets: resetWidgets,
|
||||||
settings: resetSettings,
|
settings: resetSettings,
|
||||||
all: function (next) {
|
all: async function () {
|
||||||
async.series([resetWidgets, resetThemes, resetPlugins, resetSettings], next);
|
await resetWidgets();
|
||||||
|
await resetThemes();
|
||||||
|
await resetPlugin();
|
||||||
|
await resetSettings();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var tasks = Object.keys(map)
|
const tasks = Object.keys(map).filter(x => options[x]).map(x => map[x]);
|
||||||
.filter(function (x) { return options[x]; })
|
|
||||||
.map(function (x) { return map[x]; });
|
|
||||||
|
|
||||||
if (!tasks.length) {
|
if (!tasks.length) {
|
||||||
console.log([
|
console.log([
|
||||||
@@ -75,58 +79,48 @@ exports.reset = function (options, callback) {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.series([db.init].concat(tasks), function (err) {
|
try {
|
||||||
if (err) {
|
await db.init();
|
||||||
winston.error('[reset] Errors were encountered during reset -- ' + err.message);
|
for (const task of tasks) {
|
||||||
return callback(err);
|
/* eslint-disable no-await-in-loop */
|
||||||
|
await task();
|
||||||
}
|
}
|
||||||
|
|
||||||
winston.info('[reset] Reset complete');
|
winston.info('[reset] Reset complete');
|
||||||
callback();
|
await require('../meta/build').buildAll();
|
||||||
});
|
process.exit(0);
|
||||||
|
} catch (err) {
|
||||||
|
winston.error('[reset] Errors were encountered during reset -- ' + err.message);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function resetSettings(callback) {
|
async function resetSettings() {
|
||||||
privileges.global.give(['local:login'], 'registered-users', function (err) {
|
await privileges.global.give(['local:login'], 'registered-users');
|
||||||
if (err) {
|
winston.info('[reset] registered-users given login privilege');
|
||||||
return callback(err);
|
winston.info('[reset] Settings reset to default');
|
||||||
}
|
|
||||||
winston.info('[reset] registered-users given login privilege');
|
|
||||||
winston.info('[reset] Settings reset to default');
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetTheme(themeId, callback) {
|
async function resetTheme(themeId) {
|
||||||
fs.access(path.join(dirname, 'node_modules', themeId, 'package.json'), function (err) {
|
try {
|
||||||
if (err) {
|
await fsAccessAsync(path.join(dirname, 'node_modules', themeId, 'package.json'));
|
||||||
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
|
} catch (err) {
|
||||||
callback(new Error('theme-not-found'));
|
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
|
||||||
} else {
|
throw new Error('theme-not-found');
|
||||||
meta.themes.set({
|
}
|
||||||
type: 'local',
|
await resetThemeTo(themeId);
|
||||||
id: themeId,
|
|
||||||
}, function (err) {
|
|
||||||
if (err) {
|
|
||||||
winston.warn('[reset] Failed to reset theme to ' + themeId);
|
|
||||||
} else {
|
|
||||||
winston.info('[reset] Theme reset to ' + themeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetThemes(callback) {
|
async function resetThemes() {
|
||||||
meta.themes.set({
|
await resetThemeTo('nodebb-theme-persona');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resetThemeTo(themeId) {
|
||||||
|
await meta.themes.set({
|
||||||
type: 'local',
|
type: 'local',
|
||||||
id: 'nodebb-theme-persona',
|
id: themeId,
|
||||||
}, function (err) {
|
|
||||||
winston.info('[reset] Theme reset to Persona');
|
|
||||||
callback(err);
|
|
||||||
});
|
});
|
||||||
|
await meta.configs.set('bootswatchSkin', '');
|
||||||
|
winston.info('[reset] Theme reset to ' + themeId + ' and default skin');
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetPlugin(pluginId, callback) {
|
function resetPlugin(pluginId, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user