From e8b566e9d097d438e01d791b5458ef60942bcb90 Mon Sep 17 00:00:00 2001 From: Gita Alekhya Paul <54375111+gitaalekhyapaul@users.noreply.github.com> Date: Thu, 15 Apr 2021 12:35:38 +0530 Subject: [PATCH 1/4] fix: remove redundant prompt #6535 --- .../src/init-steps/s0-analyzeProject.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts b/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts index 95e0ee5a2ef..6115e25d4da 100644 --- a/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts +++ b/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts @@ -255,7 +255,7 @@ async function getEnvName(context: $TSContext) { } else { const allEnvs = context.amplify.getAllEnvs(); - if (allEnvs.length > 0) { + if (allEnvs.length > 0 && addNewEnv(context).exec === false) { if (await context.amplify.confirmPrompt('Do you want to use an existing environment?')) { const envQuestion: inquirer.ListQuestion = { type: 'list', @@ -268,6 +268,8 @@ async function getEnvName(context: $TSContext) { } else { await newEnvQuestion(); } + } else if (addNewEnv(context).exec === true && addNewEnv(context).envName) { + envName = addNewEnv(context).envName; } else { await newEnvQuestion(); } @@ -310,3 +312,29 @@ function getDefaultEditor() { return localEnvInfo.defaultEditor; } + +/** + *Checks if `amplify env add` has been executed, and extract environment name if exists + * @param {$TSContext} context The Amplify context object + * @returns `{exec: boolean, envName?: string | null}` + * + * `exec` denotes if `amplify env add` has been executed + * + * `envName` extracts environment name if provided + */ +function addNewEnv(context): { exec: boolean; envName?: string | null } { + if (context.parameters.command === 'env' && context.parameters.array[0] === 'add') { + let envName = null; + if (context.parameters.first) { + envName = context.parameters.first; + } + return { + exec: true, + envName, + }; + } else { + return { + exec: false, + }; + } +} From 24eb2f7692a47cdbcb77e4aeac1c1d810f6a8cf2 Mon Sep 17 00:00:00 2001 From: Gita Alekhya Paul <54375111+gitaalekhyapaul@users.noreply.github.com> Date: Sat, 17 Apr 2021 14:07:33 +0530 Subject: [PATCH 2/4] refactor: remove repeating code --- .../src/init-steps/s0-analyzeProject.ts | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts b/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts index 6115e25d4da..343dfb7e7db 100644 --- a/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts +++ b/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts @@ -254,8 +254,9 @@ async function getEnvName(context: $TSContext) { await newEnvQuestion(); } else { const allEnvs = context.amplify.getAllEnvs(); + const envAddExec = checkEnvAddExec(context); - if (allEnvs.length > 0 && addNewEnv(context).exec === false) { + if (allEnvs.length > 0 && envAddExec === false) { if (await context.amplify.confirmPrompt('Do you want to use an existing environment?')) { const envQuestion: inquirer.ListQuestion = { type: 'list', @@ -268,8 +269,8 @@ async function getEnvName(context: $TSContext) { } else { await newEnvQuestion(); } - } else if (addNewEnv(context).exec === true && addNewEnv(context).envName) { - envName = addNewEnv(context).envName; + } else if (envAddExec === true && context.parameters.first) { + envName = context.parameters.first; } else { await newEnvQuestion(); } @@ -314,27 +315,14 @@ function getDefaultEditor() { } /** - *Checks if `amplify env add` has been executed, and extract environment name if exists + *Checks if `amplify env add` has been executed * @param {$TSContext} context The Amplify context object - * @returns `{exec: boolean, envName?: string | null}` - * - * `exec` denotes if `amplify env add` has been executed - * - * `envName` extracts environment name if provided + * @returns `boolean` */ -function addNewEnv(context): { exec: boolean; envName?: string | null } { +function checkEnvAddExec(context): boolean { if (context.parameters.command === 'env' && context.parameters.array[0] === 'add') { - let envName = null; - if (context.parameters.first) { - envName = context.parameters.first; - } - return { - exec: true, - envName, - }; + return true; } else { - return { - exec: false, - }; + return false; } } From 445c87565a21288fe9a1aa010692d6459f6cb72e Mon Sep 17 00:00:00 2001 From: Gita Alekhya Paul <54375111+gitaalekhyapaul@users.noreply.github.com> Date: Wed, 28 Apr 2021 01:37:14 +0530 Subject: [PATCH 3/4] refactor: update return statement --- packages/amplify-cli/src/init-steps/s0-analyzeProject.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts b/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts index 343dfb7e7db..81e7864dcdf 100644 --- a/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts +++ b/packages/amplify-cli/src/init-steps/s0-analyzeProject.ts @@ -315,14 +315,10 @@ function getDefaultEditor() { } /** - *Checks if `amplify env add` has been executed + * Checks if `amplify env add` has been executed * @param {$TSContext} context The Amplify context object * @returns `boolean` */ function checkEnvAddExec(context): boolean { - if (context.parameters.command === 'env' && context.parameters.array[0] === 'add') { - return true; - } else { - return false; - } + return context.parameters.command === 'env' && context.parameters.array[0] === 'add'; } From 5cf773119650968e2e4646895185f8ee2c8790ba Mon Sep 17 00:00:00 2001 From: Gita Alekhya Paul <54375111+gitaalekhyapaul@users.noreply.github.com> Date: Wed, 12 May 2021 22:42:42 +0530 Subject: [PATCH 4/4] fix: update env E2E tests --- packages/amplify-e2e-tests/src/environment/env.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/amplify-e2e-tests/src/environment/env.ts b/packages/amplify-e2e-tests/src/environment/env.ts index e6340a3ef0a..67698d95cd8 100644 --- a/packages/amplify-e2e-tests/src/environment/env.ts +++ b/packages/amplify-e2e-tests/src/environment/env.ts @@ -3,8 +3,6 @@ import { nspawn as spawn, getCLIPath, getSocialProviders } from 'amplify-e2e-cor export function addEnvironment(cwd: string, settings: { envName: string; numLayers?: number }): Promise { return new Promise((resolve, reject) => { const chain = spawn(getCLIPath(), ['env', 'add'], { cwd, stripColors: true }) - .wait('Do you want to use an existing environment?') - .sendLine('n') .wait('Enter a name for the environment') .sendLine(settings.envName) .wait('Select the authentication method you want to use:') @@ -29,8 +27,6 @@ export function addEnvironment(cwd: string, settings: { envName: string; numLaye export function addEnvironmentWithImportedAuth(cwd: string, settings: { envName: string; currentEnvName: string }): Promise { return new Promise((resolve, reject) => { spawn(getCLIPath(), ['env', 'add'], { cwd, stripColors: true }) - .wait('Do you want to use an existing environment?') - .sendConfirmNo() .wait('Enter a name for the environment') .sendLine(settings.envName) .wait('Select the authentication method you want to use:') @@ -150,8 +146,6 @@ export function addEnvironmentHostedUI(cwd: string, settings: { envName: string } = getSocialProviders(); return new Promise((resolve, reject) => { spawn(getCLIPath(), ['env', 'add'], { cwd, stripColors: true }) - .wait('Do you want to use an existing environment?') - .sendLine('n') .wait('Enter a name for the environment') .sendLine(settings.envName) .wait('Select the authentication method you want to use:')