From 1aedbcfa2897d1bfc6f009c00d4fd3951d3baf99 Mon Sep 17 00:00:00 2001 From: mr-loop-1 Date: Wed, 4 Oct 2023 00:11:34 +0530 Subject: [PATCH] feat added prompts when missing name or skeleton --- tools/cli/commands.js | 45 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tools/cli/commands.js b/tools/cli/commands.js index 1af6ed7a18..37317811d3 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -531,6 +531,7 @@ export const AVAILABLE_SKELETONS = [ main.registerCommand({ name: 'create', maxArgs: 1, + minArgs: 0, options: { list: { type: Boolean }, example: { type: String }, @@ -550,8 +551,50 @@ main.registerCommand({ solid: { type: Boolean }, prototype: { type: Boolean } }, + pretty: false, catalogRefresh: new catalog.Refresh.Never() -}, function (options) { +}, async function (options) { + + const setup = async () => { + const ask = createPrompt(); + if(!options.hasOwnProperty("list") && !options.hasOwnProperty("example") && !options.hasOwnProperty("package")) { + let appName, templateName; + if(!options.args[0]) { + const appName = await ask(`What is the name/path of your ${yellow`app`}? `); + checkScaffoldName(appName); + options.args.push(appName) + } + else { + // This part is just for better clarity + Console.info(`Name of your app: ${options.args[0]}`); + } + + const skeletonIndex = AVAILABLE_SKELETONS.findIndex(skeleton => { + return Object.keys(options).includes(skeleton); + }) + if(skeletonIndex === -1) { + let skeletonPrompt = `Which skeleton do you want to use?\nPress Enter for Default (${DEFAULT_SKELETON})\n`; + AVAILABLE_SKELETONS.forEach((skeleton, index) => { + skeletonPrompt += `${index} - ${skeleton}\n`; + }) + skeletonPrompt += `Please Enter the Skeleton Number: ` + + const skeletonIndex2 = await ask(skeletonPrompt); + if(skeletonIndex2 === '') { + options = {...options, [DEFAULT_SKELETON]: true} + } + else if(skeletonIndex2 >= 0 && skeletonIndex2 < AVAILABLE_SKELETONS.length) { + options = {...options, [AVAILABLE_SKELETONS[skeletonIndex2]]: true} + } + else { + Console.error(red`Invalid Skeleton number`); + } + } + } + } + + await setup(); + // Creating a package is much easier than creating an app, so if that's what // we are doing, do that first. (For example, we don't springboard to the // latest release to create a package if we are inside an app)