mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: add -y flag to upgrade, closes #13023
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.start();
|
||||
const result = await prompt.get({
|
||||
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...');
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user