From 3ea49d33a2b20ad2334bf60ef74236bfe78e7de6 Mon Sep 17 00:00:00 2001 From: Timbuktu1982 <47846931+Timbuktu1982@users.noreply.github.com> Date: Wed, 6 Oct 2021 17:26:03 +0200 Subject: [PATCH] Fix handling for --to "--to latest" or "--to [versionNumber]" will be handle with given string and without specific question ember-cli-update will do the update to given version in case you have set the parameter --to. --- src/choose-blueprint-updates.js | 78 +++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/src/choose-blueprint-updates.js b/src/choose-blueprint-updates.js index 42b1d0091..512f82400 100644 --- a/src/choose-blueprint-updates.js +++ b/src/choose-blueprint-updates.js @@ -108,37 +108,57 @@ All blueprints are up-to-date!`); }; return choices; }, {}); - - let { blueprintUpdate } = await chooseBlueprint({ - choicesByName, - message: 'Blueprint updates have been found. Which one would you like to update?' - }); - - existingBlueprint = blueprintUpdate.blueprint; - - if (typeof to !== 'string') { - let latestVersion = `${blueprintUpdate.latestVersion} (latest)`; - - let answer = await inquirer.prompt([{ - type: 'list', - message: 'Do you want the latest version?', - name: 'choice', - choices: [ - latestVersion, - 'SemVer string' - ] - }]); - - if (answer.choice === latestVersion) { - to = defaultTo; - } else { - answer = await inquirer.prompt([{ - type: 'input', - message: 'What version?', - name: 'semver' + + if (typeof to === "string" && to == "latest") { + let keys = Object.keys(choicesByName); + if ( + keys.length > 0 && + choicesByName[keys[0]]?.blueprintUpdate?.latestVersion && + choicesByName[keys[0]]?.blueprintUpdate?.blueprint + ) { + to = choicesByName[keys[0]].blueprintUpdate.latestVersion; + existingBlueprint = choicesByName[keys[0]].blueprintUpdate.blueprint; + } + } else if (typeof to === "string" && to !== "latest") { + let keys = Object.keys(choicesByName); + if ( + keys.length > 0 && + choicesByName[keys[0]]?.blueprintUpdate?.blueprint + ) { + existingBlueprint = choicesByName[keys[0]].blueprintUpdate.blueprint; + } + } else { + let { blueprintUpdate } = await chooseBlueprint({ + choicesByName, + message: 'Blueprint updates have been found. Which one would you like to update?' + }); + + existingBlueprint = blueprintUpdate.blueprint; + + if (typeof to !== 'string') { + let latestVersion = `${blueprintUpdate.latestVersion} (latest)`; + + let answer = await inquirer.prompt([{ + type: 'list', + message: 'Do you want the latest version?', + name: 'choice', + choices: [ + latestVersion, + 'SemVer string' + ] }]); - to = answer.semver; + if (answer.choice === latestVersion) { + to = defaultTo; + } else { + answer = await inquirer.prompt([{ + type: 'input', + message: 'What version?', + name: 'semver' + }]); + + to = answer.semver; + } } } }