Node.js based forum software built for the modern web
feat: add -y flag to upgrade, closes #13023
Barış Soner Uşaklı4f682a310ed9
diff --git a/src/cli/index.js b/src/cli/index.jsindex e6f0485585..7bd1c37b87 100644--- a/src/cli/index.js+++ b/src/cli/index.js@@ -87,7 +87,8 @@ program.option('--log-level <level>', 'Default logging level to use', 'info').option('--config <value>', 'Specify a config file', 'config.json').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)+ .option('-y, --unattended', 'Answer yes to any prompts, like plugin upgrades', false);// provide a yargs object ourselves// otherwise yargs will consume `--help` or `help`@@ -294,6 +295,7 @@ program].join('\n')}`);}).action((scripts, options) => {+ options.unattended = program.opts().unattended;if (program.opts().dev) {process.env.NODE_ENV = 'development';global.env = 'development';@@ -308,7 +310,8 @@ program.alias('upgradePlugins').description('Upgrade plugins').action(() => {- require('./upgrade-plugins').upgradePlugins((err) => {+ const { unattended } = program.opts();+ require('./upgrade-plugins').upgradePlugins(unattended, (err) => {if (err) {throw err;}diff --git a/src/cli/upgrade-plugins.js b/src/cli/upgrade-plugins.jsindex b68db55eac..ec25fdaa69 100644--- a/src/cli/upgrade-plugins.js+++ b/src/cli/upgrade-plugins.js@@ -120,7 +120,7 @@ async function checkPlugins() {return upgradable;}-async function upgradePlugins() {+async function upgradePlugins(unattended = false) {try {const found = await checkPlugins();if (found && found.length) {@@ -132,16 +132,18 @@ async function upgradePlugins() {console.log(chalk.green('\nAll packages up-to-date!'));return;}-- prompt.message = '';- prompt.delimiter = '';-- prompt.start();- const result = await prompt.get({- name: 'upgrade',- description: '\nProceed with upgrade (y|n)?',- type: 'string',- });+ let result = { upgrade: 'y' };+ if (!unattended) {+ prompt.message = '';+ prompt.delimiter = '';++ prompt.start();+ result= await prompt.get({+ name: 'upgrade',+ description: '\nProceed with upgrade (y|n)?',+ type: 'string',+ });+ }if (['y', 'Y', 'yes', 'YES'].includes(result.upgrade)) {console.log('\nUpgrading packages...');diff --git a/src/cli/upgrade.js b/src/cli/upgrade.jsindex ff3487388c..e879239b7a 100644--- a/src/cli/upgrade.js+++ b/src/cli/upgrade.js@@ -24,9 +24,9 @@ const steps = {},plugins: {message: 'Checking installed plugins for updates...',- handler: async function () {+ handler: async function (options) {await require('../database').init();- await upgradePlugins();+ await upgradePlugins(options.unattended);},},schema: {@@ -45,14 +45,14 @@ const steps = {},};-async function runSteps(tasks) {+async function runSteps(tasks, options) {try {for (let i = 0; i < tasks.length; i++) {const step = steps[tasks[i]];if (step && step.message && step.handler) {process.stdout.write(`\n${chalk.bold(`${i + 1}. `)}${chalk.yellow(step.message)}`);/* eslint-disable-next-line */- await step.handler();+ await step.handler(options);}}const message = 'NodeBB Upgrade Complete!';@@ -95,7 +95,7 @@ async function runUpgrade(upgrades, options) {options.plugins || options.schema || options.build) {tasks = tasks.filter(key => options[key]);}- await runSteps(tasks);+ await runSteps(tasks, options);return;}