mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
fix: --help usage info
yargs (via nconf) would exit when detecting a help flag also improves the speed of `./nodebb help build`
This commit is contained in:
committed by
Andrew Rodrigues
parent
072a0e32d8
commit
a51c5698c7
@@ -146,6 +146,7 @@
|
|||||||
"winston": "3.3.3",
|
"winston": "3.3.3",
|
||||||
"xml": "^1.0.1",
|
"xml": "^1.0.1",
|
||||||
"xregexp": "^4.3.0",
|
"xregexp": "^4.3.0",
|
||||||
|
"yargs": "16.2.0",
|
||||||
"zxcvbn": "^4.4.2"
|
"zxcvbn": "^4.4.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
/* eslint-disable import/order */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@@ -35,13 +37,13 @@ try {
|
|||||||
try {
|
try {
|
||||||
fs.accessSync(path.join(paths.nodeModules, 'semver/package.json'), fs.constants.R_OK);
|
fs.accessSync(path.join(paths.nodeModules, 'semver/package.json'), fs.constants.R_OK);
|
||||||
|
|
||||||
var semver = require('semver');
|
const semver = require('semver');
|
||||||
var defaultPackage = require('../../install/package.json');
|
const defaultPackage = require('../../install/package.json');
|
||||||
|
|
||||||
var checkVersion = function (packageName) {
|
const checkVersion = function (packageName) {
|
||||||
var version = JSON.parse(fs.readFileSync(path.join(paths.nodeModules, packageName, 'package.json'), 'utf8')).version;
|
const version = JSON.parse(fs.readFileSync(path.join(paths.nodeModules, packageName, 'package.json'), 'utf8')).version;
|
||||||
if (!semver.satisfies(version, defaultPackage.dependencies[packageName])) {
|
if (!semver.satisfies(version, defaultPackage.dependencies[packageName])) {
|
||||||
var e = new TypeError('Incorrect dependency version: ' + packageName);
|
const e = new TypeError('Incorrect dependency version: ' + packageName);
|
||||||
e.code = 'DEP_WRONG_VERSION';
|
e.code = 'DEP_WRONG_VERSION';
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -67,14 +69,13 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require('colors');
|
require('colors');
|
||||||
// eslint-disable-next-line
|
const nconf = require('nconf');
|
||||||
var nconf = require('nconf');
|
const { program } = require('commander');
|
||||||
// eslint-disable-next-line
|
const yargs = require('yargs');
|
||||||
var program = require('commander');
|
|
||||||
|
|
||||||
var pkg = require('../../package.json');
|
const pkg = require('../../package.json');
|
||||||
var file = require('../file');
|
const file = require('../file');
|
||||||
var prestart = require('../prestart');
|
const prestart = require('../prestart');
|
||||||
|
|
||||||
program
|
program
|
||||||
.name('./nodebb')
|
.name('./nodebb')
|
||||||
@@ -86,19 +87,23 @@ program
|
|||||||
.option('-d, --dev', 'Development mode, including verbose logging', false)
|
.option('-d, --dev', 'Development mode, including verbose logging', false)
|
||||||
.option('-l, --log', 'Log subprocess output to console', false);
|
.option('-l, --log', 'Log subprocess output to console', false);
|
||||||
|
|
||||||
nconf.argv().env({
|
// provide a yargs object ourselves
|
||||||
|
// otherwise yargs will consume `--help` or `help`
|
||||||
|
// and `nconf` will exit with useless usage info
|
||||||
|
const opts = yargs(process.argv.slice(2)).help(false).exitProcess(false);
|
||||||
|
nconf.argv(opts).env({
|
||||||
separator: '__',
|
separator: '__',
|
||||||
});
|
});
|
||||||
|
|
||||||
var env = program.dev ? 'development' : (process.env.NODE_ENV || 'production');
|
const env = program.dev ? 'development' : (process.env.NODE_ENV || 'production');
|
||||||
process.env.NODE_ENV = env;
|
process.env.NODE_ENV = env;
|
||||||
global.env = env;
|
global.env = env;
|
||||||
|
|
||||||
prestart.setupWinston();
|
prestart.setupWinston();
|
||||||
|
|
||||||
// Alternate configuration file support
|
// Alternate configuration file support
|
||||||
var configFile = path.resolve(paths.baseDir, nconf.get('config') || 'config.json');
|
const configFile = path.resolve(paths.baseDir, nconf.get('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'));
|
||||||
|
|
||||||
prestart.loadConfig(configFile);
|
prestart.loadConfig(configFile);
|
||||||
prestart.versionCheck();
|
prestart.versionCheck();
|
||||||
@@ -195,7 +200,7 @@ program
|
|||||||
require('./manage').build(targets.length ? targets : true, options);
|
require('./manage').build(targets.length ? targets : true, options);
|
||||||
})
|
})
|
||||||
.on('--help', function () {
|
.on('--help', function () {
|
||||||
require('./manage').buildTargets();
|
require('../meta/aliases').buildTargets();
|
||||||
});
|
});
|
||||||
program
|
program
|
||||||
.command('activate [plugin]')
|
.command('activate [plugin]')
|
||||||
@@ -223,7 +228,7 @@ program
|
|||||||
});
|
});
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
var resetCommand = program.command('reset');
|
const resetCommand = program.command('reset');
|
||||||
|
|
||||||
resetCommand
|
resetCommand
|
||||||
.description('Reset plugins, themes, settings, etc')
|
.description('Reset plugins, themes, settings, etc')
|
||||||
@@ -233,7 +238,7 @@ resetCommand
|
|||||||
.option('-s, --settings', 'Reset settings to their default values')
|
.option('-s, --settings', 'Reset settings to their default values')
|
||||||
.option('-a, --all', 'All of the above')
|
.option('-a, --all', 'All of the above')
|
||||||
.action(function (options) {
|
.action(function (options) {
|
||||||
var valid = ['theme', 'plugin', 'widgets', 'settings', 'all'].some(function (x) {
|
const valid = ['theme', 'plugin', 'widgets', 'settings', 'all'].some(function (x) {
|
||||||
return options[x];
|
return options[x];
|
||||||
});
|
});
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
@@ -295,10 +300,11 @@ program
|
|||||||
return program.help();
|
return program.help();
|
||||||
}
|
}
|
||||||
|
|
||||||
var command = program.commands.find(function (command) { return command._name === name; });
|
const command = program.commands.find(function (command) { return command._name === name; });
|
||||||
if (command) {
|
if (command) {
|
||||||
command.help();
|
command.help();
|
||||||
} else {
|
} else {
|
||||||
|
console.log(`error: unknown command '${command}'.`);
|
||||||
program.help();
|
program.help();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -311,4 +317,4 @@ if (process.argv.length === 2) {
|
|||||||
|
|
||||||
program.executables = false;
|
program.executables = false;
|
||||||
|
|
||||||
program.parse(process.argv);
|
program.parse();
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
const childProcess = require('child_process');
|
const childProcess = require('child_process');
|
||||||
const _ = require('lodash');
|
|
||||||
const CliGraph = require('cli-graph');
|
const CliGraph = require('cli-graph');
|
||||||
|
|
||||||
const build = require('../meta/build');
|
const build = require('../meta/build');
|
||||||
@@ -13,27 +12,6 @@ const analytics = require('../analytics');
|
|||||||
const reset = require('./reset');
|
const reset = require('./reset');
|
||||||
const { pluginNamePattern, themeNamePattern } = require('../constants');
|
const { pluginNamePattern, themeNamePattern } = require('../constants');
|
||||||
|
|
||||||
function buildTargets() {
|
|
||||||
var aliases = build.aliases;
|
|
||||||
var length = 0;
|
|
||||||
var output = Object.keys(aliases).map(function (name) {
|
|
||||||
var arr = aliases[name];
|
|
||||||
if (name.length > length) {
|
|
||||||
length = name.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [name, arr.join(', ')];
|
|
||||||
}).map(function (tuple) {
|
|
||||||
return ' ' + _.padEnd('"' + tuple[0] + '"', length + 2).magenta + ' | ' + tuple[1];
|
|
||||||
}).join('\n');
|
|
||||||
console.log(
|
|
||||||
'\n\n Build targets:\n' +
|
|
||||||
('\n ' + _.padEnd('Target', length + 2) + ' | Aliases').green +
|
|
||||||
'\n ------------------------------------------------------\n'.blue +
|
|
||||||
output + '\n'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function activate(plugin) {
|
async function activate(plugin) {
|
||||||
if (themeNamePattern.test(plugin)) {
|
if (themeNamePattern.test(plugin)) {
|
||||||
await reset.reset({
|
await reset.reset({
|
||||||
@@ -176,7 +154,6 @@ async function buildWrapper(targets, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.build = buildWrapper;
|
exports.build = buildWrapper;
|
||||||
exports.buildTargets = buildTargets;
|
|
||||||
exports.activate = activate;
|
exports.activate = activate;
|
||||||
exports.listPlugins = listPlugins;
|
exports.listPlugins = listPlugins;
|
||||||
exports.listEvents = listEvents;
|
exports.listEvents = listEvents;
|
||||||
|
|||||||
44
src/meta/aliases.js
Normal file
44
src/meta/aliases.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const aliases = {
|
||||||
|
'plugin static dirs': ['staticdirs'],
|
||||||
|
'requirejs modules': ['rjs', 'modules'],
|
||||||
|
'client js bundle': ['clientjs', 'clientscript', 'clientscripts'],
|
||||||
|
'admin js bundle': ['adminjs', 'adminscript', 'adminscripts'],
|
||||||
|
javascript: ['js'],
|
||||||
|
'client side styles': [
|
||||||
|
'clientcss', 'clientless', 'clientstyles', 'clientstyle',
|
||||||
|
],
|
||||||
|
'admin control panel styles': [
|
||||||
|
'admincss', 'adminless', 'adminstyles', 'adminstyle', 'acpcss', 'acpless', 'acpstyles', 'acpstyle',
|
||||||
|
],
|
||||||
|
styles: ['css', 'less', 'style'],
|
||||||
|
templates: ['tpl'],
|
||||||
|
languages: ['lang', 'i18n'],
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.aliases = aliases;
|
||||||
|
|
||||||
|
function buildTargets() {
|
||||||
|
var length = 0;
|
||||||
|
var output = Object.keys(aliases).map(function (name) {
|
||||||
|
var arr = aliases[name];
|
||||||
|
if (name.length > length) {
|
||||||
|
length = name.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [name, arr.join(', ')];
|
||||||
|
}).map(function (tuple) {
|
||||||
|
return ' ' + _.padEnd('"' + tuple[0] + '"', length + 2).magenta + ' | ' + tuple[1];
|
||||||
|
}).join('\n');
|
||||||
|
console.log(
|
||||||
|
'\n\n Build targets:\n' +
|
||||||
|
('\n ' + _.padEnd('Target', length + 2) + ' | Aliases').green +
|
||||||
|
'\n ------------------------------------------------------\n'.blue +
|
||||||
|
output + '\n'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.buildTargets = buildTargets;
|
||||||
@@ -8,6 +8,7 @@ const path = require('path');
|
|||||||
const mkdirp = require('mkdirp');
|
const mkdirp = require('mkdirp');
|
||||||
|
|
||||||
const cacheBuster = require('./cacheBuster');
|
const cacheBuster = require('./cacheBuster');
|
||||||
|
const { aliases } = require('./aliases');
|
||||||
let meta;
|
let meta;
|
||||||
|
|
||||||
const targetHandlers = {
|
const targetHandlers = {
|
||||||
@@ -47,26 +48,7 @@ const targetHandlers = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let aliases = {
|
const aliasMap = Object.keys(aliases).reduce(function (prev, key) {
|
||||||
'plugin static dirs': ['staticdirs'],
|
|
||||||
'requirejs modules': ['rjs', 'modules'],
|
|
||||||
'client js bundle': ['clientjs', 'clientscript', 'clientscripts'],
|
|
||||||
'admin js bundle': ['adminjs', 'adminscript', 'adminscripts'],
|
|
||||||
javascript: ['js'],
|
|
||||||
'client side styles': [
|
|
||||||
'clientcss', 'clientless', 'clientstyles', 'clientstyle',
|
|
||||||
],
|
|
||||||
'admin control panel styles': [
|
|
||||||
'admincss', 'adminless', 'adminstyles', 'adminstyle', 'acpcss', 'acpless', 'acpstyles', 'acpstyle',
|
|
||||||
],
|
|
||||||
styles: ['css', 'less', 'style'],
|
|
||||||
templates: ['tpl'],
|
|
||||||
languages: ['lang', 'i18n'],
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.aliases = aliases;
|
|
||||||
|
|
||||||
aliases = Object.keys(aliases).reduce(function (prev, key) {
|
|
||||||
var arr = aliases[key];
|
var arr = aliases[key];
|
||||||
arr.forEach(function (alias) {
|
arr.forEach(function (alias) {
|
||||||
prev[alias] = key;
|
prev[alias] = key;
|
||||||
@@ -151,7 +133,7 @@ exports.build = async function (targets, options) {
|
|||||||
// get full target name
|
// get full target name
|
||||||
.map(function (target) {
|
.map(function (target) {
|
||||||
target = target.toLowerCase().replace(/-/g, '');
|
target = target.toLowerCase().replace(/-/g, '');
|
||||||
if (!aliases[target]) {
|
if (!aliasMap[target]) {
|
||||||
winston.warn('[build] Unknown target: ' + target);
|
winston.warn('[build] Unknown target: ' + target);
|
||||||
if (target.includes(',')) {
|
if (target.includes(',')) {
|
||||||
winston.warn('[build] Are you specifying multiple targets? Separate them with spaces:');
|
winston.warn('[build] Are you specifying multiple targets? Separate them with spaces:');
|
||||||
@@ -161,7 +143,7 @@ exports.build = async function (targets, options) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return aliases[target];
|
return aliasMap[target];
|
||||||
})
|
})
|
||||||
// filter nonexistent targets
|
// filter nonexistent targets
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|||||||
Reference in New Issue
Block a user