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('--log-level <level>', 'Default logging level to use', 'info')
|
||||||
.option('--config <value>', 'Specify a config file', 'config.json')
|
.option('--config <value>', 'Specify a config file', 'config.json')
|
||||||
.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)
|
||||||
|
.option('-y, --unattended', 'Answer yes to any prompts, like plugin upgrades', false);
|
||||||
|
|
||||||
// provide a yargs object ourselves
|
// provide a yargs object ourselves
|
||||||
// otherwise yargs will consume `--help` or `help`
|
// otherwise yargs will consume `--help` or `help`
|
||||||
@@ -294,6 +295,7 @@ program
|
|||||||
].join('\n')}`);
|
].join('\n')}`);
|
||||||
})
|
})
|
||||||
.action((scripts, options) => {
|
.action((scripts, options) => {
|
||||||
|
options.unattended = program.opts().unattended;
|
||||||
if (program.opts().dev) {
|
if (program.opts().dev) {
|
||||||
process.env.NODE_ENV = 'development';
|
process.env.NODE_ENV = 'development';
|
||||||
global.env = 'development';
|
global.env = 'development';
|
||||||
@@ -308,7 +310,8 @@ program
|
|||||||
.alias('upgradePlugins')
|
.alias('upgradePlugins')
|
||||||
.description('Upgrade plugins')
|
.description('Upgrade plugins')
|
||||||
.action(() => {
|
.action(() => {
|
||||||
require('./upgrade-plugins').upgradePlugins((err) => {
|
const { unattended } = program.opts();
|
||||||
|
require('./upgrade-plugins').upgradePlugins(unattended, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ async function checkPlugins() {
|
|||||||
return upgradable;
|
return upgradable;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function upgradePlugins() {
|
async function upgradePlugins(unattended = false) {
|
||||||
try {
|
try {
|
||||||
const found = await checkPlugins();
|
const found = await checkPlugins();
|
||||||
if (found && found.length) {
|
if (found && found.length) {
|
||||||
@@ -132,16 +132,18 @@ async function upgradePlugins() {
|
|||||||
console.log(chalk.green('\nAll packages up-to-date!'));
|
console.log(chalk.green('\nAll packages up-to-date!'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let result = { upgrade: 'y' };
|
||||||
|
if (!unattended) {
|
||||||
|
prompt.message = '';
|
||||||
|
prompt.delimiter = '';
|
||||||
|
|
||||||
prompt.message = '';
|
prompt.start();
|
||||||
prompt.delimiter = '';
|
result= await prompt.get({
|
||||||
|
name: 'upgrade',
|
||||||
prompt.start();
|
description: '\nProceed with upgrade (y|n)?',
|
||||||
const result = await prompt.get({
|
type: 'string',
|
||||||
name: 'upgrade',
|
});
|
||||||
description: '\nProceed with upgrade (y|n)?',
|
}
|
||||||
type: 'string',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (['y', 'Y', 'yes', 'YES'].includes(result.upgrade)) {
|
if (['y', 'Y', 'yes', 'YES'].includes(result.upgrade)) {
|
||||||
console.log('\nUpgrading packages...');
|
console.log('\nUpgrading packages...');
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ const steps = {
|
|||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
message: 'Checking installed plugins for updates...',
|
message: 'Checking installed plugins for updates...',
|
||||||
handler: async function () {
|
handler: async function (options) {
|
||||||
await require('../database').init();
|
await require('../database').init();
|
||||||
await upgradePlugins();
|
await upgradePlugins(options.unattended);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
@@ -45,14 +45,14 @@ const steps = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
async function runSteps(tasks) {
|
async function runSteps(tasks, options) {
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < tasks.length; i++) {
|
for (let i = 0; i < tasks.length; i++) {
|
||||||
const step = steps[tasks[i]];
|
const step = steps[tasks[i]];
|
||||||
if (step && step.message && step.handler) {
|
if (step && step.message && step.handler) {
|
||||||
process.stdout.write(`\n${chalk.bold(`${i + 1}. `)}${chalk.yellow(step.message)}`);
|
process.stdout.write(`\n${chalk.bold(`${i + 1}. `)}${chalk.yellow(step.message)}`);
|
||||||
/* eslint-disable-next-line */
|
/* eslint-disable-next-line */
|
||||||
await step.handler();
|
await step.handler(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const message = 'NodeBB Upgrade Complete!';
|
const message = 'NodeBB Upgrade Complete!';
|
||||||
@@ -95,7 +95,7 @@ async function runUpgrade(upgrades, options) {
|
|||||||
options.plugins || options.schema || options.build) {
|
options.plugins || options.schema || options.build) {
|
||||||
tasks = tasks.filter(key => options[key]);
|
tasks = tasks.filter(key => options[key]);
|
||||||
}
|
}
|
||||||
await runSteps(tasks);
|
await runSteps(tasks, options);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user