mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-08 15:41:33 +02:00
refactor: async/await
src/cli/manage.js src/meta/build.js src/meta/css.js src/meta/js.js
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
const winston = require('winston');
|
||||
const childProcess = require('child_process');
|
||||
const _ = require('lodash');
|
||||
@@ -35,59 +34,40 @@ function buildTargets() {
|
||||
);
|
||||
}
|
||||
|
||||
function activate(plugin) {
|
||||
async function activate(plugin) {
|
||||
if (themeNamePattern.test(plugin)) {
|
||||
reset.reset({
|
||||
await reset.reset({
|
||||
theme: plugin,
|
||||
}, function (err) {
|
||||
if (err) { throw err; }
|
||||
process.exit();
|
||||
});
|
||||
return;
|
||||
process.exit();
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.init(next);
|
||||
},
|
||||
function (next) {
|
||||
if (!pluginNamePattern.test(plugin)) {
|
||||
// Allow omission of `nodebb-plugin-`
|
||||
plugin = 'nodebb-plugin-' + plugin;
|
||||
}
|
||||
plugins.isInstalled(plugin, next);
|
||||
},
|
||||
function (isInstalled, next) {
|
||||
if (!isInstalled) {
|
||||
return next(new Error('plugin not installed'));
|
||||
}
|
||||
plugins.isActive(plugin, next);
|
||||
},
|
||||
function (isActive, next) {
|
||||
if (isActive) {
|
||||
winston.info('Plugin `%s` already active', plugin);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
db.sortedSetCard('plugins:active', next);
|
||||
},
|
||||
function (numPlugins, next) {
|
||||
winston.info('Activating plugin `%s`', plugin);
|
||||
db.sortedSetAdd('plugins:active', numPlugins, plugin, next);
|
||||
},
|
||||
function (next) {
|
||||
events.log({
|
||||
type: 'plugin-activate',
|
||||
text: plugin,
|
||||
}, next);
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
winston.error('An error occurred during plugin activation', err.stack);
|
||||
throw err;
|
||||
try {
|
||||
await db.init();
|
||||
if (!pluginNamePattern.test(plugin)) {
|
||||
// Allow omission of `nodebb-plugin-`
|
||||
plugin = 'nodebb-plugin-' + plugin;
|
||||
}
|
||||
const isInstalled = await plugins.isInstalled(plugin);
|
||||
if (!isInstalled) {
|
||||
throw new Error('plugin not installed');
|
||||
}
|
||||
const isActive = await plugins.isActive(plugin);
|
||||
if (isActive) {
|
||||
winston.info('Plugin `%s` already active', plugin);
|
||||
process.exit(0);
|
||||
}
|
||||
const numPlugins = await db.sortedSetCard('plugins:active');
|
||||
winston.info('Activating plugin `%s`', plugin);
|
||||
await db.sortedSetAdd('plugins:active', numPlugins, plugin);
|
||||
await events.log({
|
||||
type: 'plugin-activate',
|
||||
text: plugin,
|
||||
});
|
||||
process.exit(0);
|
||||
});
|
||||
} catch (err) {
|
||||
winston.error('An error occurred during plugin activation', err.stack);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function listPlugins() {
|
||||
@@ -125,103 +105,74 @@ async function listPlugins() {
|
||||
process.exit();
|
||||
}
|
||||
|
||||
function listEvents(count) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.init(next);
|
||||
},
|
||||
async.apply(events.getEvents, '', 0, (count || 10) - 1),
|
||||
function (eventData) {
|
||||
console.log(('\nDisplaying last ' + count + ' administrative events...').bold);
|
||||
eventData.forEach(function (event) {
|
||||
console.log(' * ' + String(event.timestampISO).green + ' ' + String(event.type).yellow + (event.text ? ' ' + event.text : '') + ' (uid: '.reset + (event.uid ? event.uid : 0) + ')');
|
||||
});
|
||||
process.exit();
|
||||
},
|
||||
], function (err) {
|
||||
throw err;
|
||||
async function listEvents(count) {
|
||||
await db.init();
|
||||
const eventData = await events.getEvents('', 0, (count || 10) - 1);
|
||||
console.log(('\nDisplaying last ' + count + ' administrative events...').bold);
|
||||
eventData.forEach(function (event) {
|
||||
console.log(' * ' + String(event.timestampISO).green + ' ' + String(event.type).yellow + (event.text ? ' ' + event.text : '') + ' (uid: '.reset + (event.uid ? event.uid : 0) + ')');
|
||||
});
|
||||
process.exit();
|
||||
}
|
||||
|
||||
function info() {
|
||||
async function info() {
|
||||
console.log('');
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
var version = require('../../package.json').version;
|
||||
console.log(' version: ' + version);
|
||||
const version = require('../../package.json').version;
|
||||
console.log(' version: ' + version);
|
||||
|
||||
console.log(' Node ver: ' + process.version);
|
||||
next();
|
||||
},
|
||||
function (next) {
|
||||
var hash = childProcess.execSync('git rev-parse HEAD');
|
||||
console.log(' git hash: ' + hash);
|
||||
next();
|
||||
},
|
||||
function (next) {
|
||||
var config = require('../../config.json');
|
||||
console.log(' database: ' + config.database);
|
||||
next();
|
||||
},
|
||||
function (next) {
|
||||
db.init(next);
|
||||
},
|
||||
function (next) {
|
||||
db.info(db.client, next);
|
||||
},
|
||||
function (info, next) {
|
||||
var config = require('../../config.json');
|
||||
console.log(' Node ver: ' + process.version);
|
||||
|
||||
switch (config.database) {
|
||||
case 'redis':
|
||||
console.log(' version: ' + info.redis_version);
|
||||
console.log(' disk sync: ' + info.rdb_last_bgsave_status);
|
||||
break;
|
||||
const hash = childProcess.execSync('git rev-parse HEAD');
|
||||
console.log(' git hash: ' + hash);
|
||||
|
||||
case 'mongo':
|
||||
console.log(' version: ' + info.version);
|
||||
console.log(' engine: ' + info.storageEngine);
|
||||
break;
|
||||
}
|
||||
const config = require('../../config.json');
|
||||
console.log(' database: ' + config.database);
|
||||
|
||||
next();
|
||||
await db.init();
|
||||
const info = await db.info(db.client);
|
||||
|
||||
switch (config.database) {
|
||||
case 'redis':
|
||||
console.log(' version: ' + info.redis_version);
|
||||
console.log(' disk sync: ' + info.rdb_last_bgsave_status);
|
||||
break;
|
||||
|
||||
case 'mongo':
|
||||
console.log(' version: ' + info.version);
|
||||
console.log(' engine: ' + info.storageEngine);
|
||||
break;
|
||||
}
|
||||
|
||||
const analyticsData = await analytics.getHourlyStatsForSet('analytics:pageviews', Date.now(), 24);
|
||||
const graph = new CliGraph({
|
||||
height: 12,
|
||||
width: 25,
|
||||
center: {
|
||||
x: 0,
|
||||
y: 11,
|
||||
},
|
||||
async.apply(analytics.getHourlyStatsForSet, 'analytics:pageviews', Date.now(), 24),
|
||||
function (data, next) {
|
||||
var graph = new CliGraph({
|
||||
height: 12,
|
||||
width: 25,
|
||||
center: {
|
||||
x: 0,
|
||||
y: 11,
|
||||
},
|
||||
});
|
||||
var min = Math.min(...data);
|
||||
var max = Math.max(...data);
|
||||
|
||||
data.forEach(function (point, idx) {
|
||||
graph.addPoint(idx + 1, Math.round(point / max * 10));
|
||||
});
|
||||
|
||||
console.log('');
|
||||
console.log(graph.toString());
|
||||
console.log('Pageviews, last 24h (min: ' + min + ' max: ' + max + ')');
|
||||
next();
|
||||
},
|
||||
], function (err) {
|
||||
if (err) { throw err; }
|
||||
process.exit();
|
||||
});
|
||||
const min = Math.min(...analyticsData);
|
||||
const max = Math.max(...analyticsData);
|
||||
|
||||
analyticsData.forEach(function (point, idx) {
|
||||
graph.addPoint(idx + 1, Math.round(point / max * 10));
|
||||
});
|
||||
|
||||
console.log('');
|
||||
console.log(graph.toString());
|
||||
console.log('Pageviews, last 24h (min: ' + min + ' max: ' + max + ')');
|
||||
process.exit();
|
||||
}
|
||||
|
||||
function buildWrapper(targets, options) {
|
||||
build.build(targets, options, function (err) {
|
||||
if (err) {
|
||||
winston.error(err.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
async function buildWrapper(targets, options) {
|
||||
try {
|
||||
await build.build(targets, options);
|
||||
process.exit(0);
|
||||
});
|
||||
} catch (err) {
|
||||
winston.error(err.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
exports.build = buildWrapper;
|
||||
|
||||
Reference in New Issue
Block a user