diff --git a/src/choose-blueprint-updates.js b/src/choose-blueprint-updates.js index 42b1d009..512f8240 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; + } } } }