From 4f682a310ed9239c1bc5cdbc1c6f7769a805a6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 6 Jan 2025 10:54:04 -0500 Subject: [PATCH] feat: add -y flag to upgrade, closes #13023 --- src/cli/index.js | 7 +++++-- src/cli/upgrade-plugins.js | 22 ++++++++++++---------- src/cli/upgrade.js | 10 +++++----- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/cli/index.js b/src/cli/index.js index e6f0485585..7bd1c37b87 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -87,7 +87,8 @@ program .option('--log-level ', 'Default logging level to use', 'info') .option('--config ', '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.js index 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; } + let result = { upgrade: 'y' }; + if (!unattended) { + prompt.message = ''; + prompt.delimiter = ''; - prompt.message = ''; - prompt.delimiter = ''; - - prompt.start(); - const result = await prompt.get({ - name: 'upgrade', - description: '\nProceed with upgrade (y|n)?', - type: 'string', - }); + 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.js index 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; }