From aaa8dfa626025847d61688db760f086e8513a5dc Mon Sep 17 00:00:00 2001 From: PantheRedEye Date: Mon, 23 Sep 2024 06:47:41 -0500 Subject: [PATCH 1/4] Prompt to confirm upgrade --- packages/cli/src/commands/upgrade.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/commands/upgrade.js b/packages/cli/src/commands/upgrade.js index c0ddb00b52e8..0a31e96e80e8 100644 --- a/packages/cli/src/commands/upgrade.js +++ b/packages/cli/src/commands/upgrade.js @@ -97,6 +97,21 @@ export const handler = async ({ dryRun, tag, verbose, dedupe }) => { // structuring as nested tasks to avoid bug with task.title causing duplicates const tasks = new Listr( [ + { + title: 'Confirm upgrade', + task: async (ctx, task) => { + const proceed = await task.prompt({ + type: 'Confirm', + message: + 'This will upgrade your RedwoodJS project to the latest version. Do you want to proceed?', + initial: true, + }) + if (!proceed) { + task.skip('Upgrade cancelled by user.') + process.exit(0) + } + }, + }, { title: 'Checking latest version', task: async (ctx) => setLatestVersionToContext(ctx, tag), @@ -183,7 +198,7 @@ export const handler = async ({ dryRun, tag, verbose, dedupe }) => { }, ], { - renderer: verbose && 'verbose', + renderer: verbose ? 'verbose' : 'default', rendererOptions: { collapseSubtasks: false }, }, ) From 017807316a5a5e12598aed53e4ec79ae13ab2c4a Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 27 Dec 2024 16:41:44 +0100 Subject: [PATCH 2/4] changeset --- .changesets/11601.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changesets/11601.md diff --git a/.changesets/11601.md b/.changesets/11601.md new file mode 100644 index 000000000000..3c02cf9e0e6b --- /dev/null +++ b/.changesets/11601.md @@ -0,0 +1,3 @@ +- Prompt to confirm upgrade (#11601) by @pantheredeye + +A prompt is added to `yarn rw upgrade` to confirm before starting. From 0bc1946eab6c33362be124aef2eb565c6f1ea952 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 27 Dec 2024 16:59:48 +0100 Subject: [PATCH 3/4] Answer "Yes" to the upgrade prompt --- .github/actions/set-up-test-project/setUpTestProject.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/set-up-test-project/setUpTestProject.mjs b/.github/actions/set-up-test-project/setUpTestProject.mjs index 5075ed383d64..74948331a057 100644 --- a/.github/actions/set-up-test-project/setUpTestProject.mjs +++ b/.github/actions/set-up-test-project/setUpTestProject.mjs @@ -54,7 +54,9 @@ async function setUpTestProject({ canary }) { if (canary) { console.log(`Upgrading project to canary`) - await execInProject('yarn rw upgrade -t canary') + await execInProject('yarn rw upgrade -t canary', { + input: Buffer.from('Y'), + }) console.log() } From ad2826a04857bea0f637f53d084f0f0a7d16f1c1 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 27 Dec 2024 17:47:36 +0100 Subject: [PATCH 4/4] --yes and Yes/no --- packages/cli/src/commands/upgrade.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/upgrade.js b/packages/cli/src/commands/upgrade.js index 0a31e96e80e8..c628fce0c939 100644 --- a/packages/cli/src/commands/upgrade.js +++ b/packages/cli/src/commands/upgrade.js @@ -47,6 +47,12 @@ export const builder = (yargs) => { type: 'boolean', default: true, }) + .option('yes', { + alias: 'y', + describe: 'Skip prompts and use defaults', + default: false, + type: 'boolean', + }) .epilogue( `Also see the ${terminalLink( 'Redwood CLI Reference for the upgrade command', @@ -85,13 +91,14 @@ export const validateTag = (tag) => { return tag } -export const handler = async ({ dryRun, tag, verbose, dedupe }) => { +export const handler = async ({ dryRun, tag, verbose, dedupe, yes }) => { recordTelemetryAttributes({ command: 'upgrade', dryRun, tag, verbose, dedupe, + yes, }) // structuring as nested tasks to avoid bug with task.title causing duplicates @@ -100,11 +107,24 @@ export const handler = async ({ dryRun, tag, verbose, dedupe }) => { { title: 'Confirm upgrade', task: async (ctx, task) => { + if (yes) { + task.skip('Skipping confirmation prompt because of --yes flag.') + return + } + const proceed = await task.prompt({ type: 'Confirm', message: 'This will upgrade your RedwoodJS project to the latest version. Do you want to proceed?', - initial: true, + initial: 'Y', + default: '(Yes/no)', + format: function (value) { + if (this.state.submitted) { + return this.isTrue(value) ? 'yes' : 'no' + } + + return 'Yes' + }, }) if (!proceed) { task.skip('Upgrade cancelled by user.')