From 47ec89d555ccde192a86015f5ed3b8d7bd279ae5 Mon Sep 17 00:00:00 2001 From: Lindsay Evans Date: Tue, 25 Jun 2024 02:39:32 +1000 Subject: [PATCH] feat: add list prop type --- examples/web-app.md | 11 +++++++++-- src/cli/addTemplateOptions.ts | 4 ++++ src/cli/checkRequiredOptions.ts | 8 +++++++- src/lib/types.ts | 3 ++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/web-app.md b/examples/web-app.md index be2c22e..cb79479 100644 --- a/examples/web-app.md +++ b/examples/web-app.md @@ -4,6 +4,13 @@ props: name: type: string required: true + packageManager: + type: list + default: yarn + options: + - npm + - yarn + - pnpm includeStyle: type: boolean default: true @@ -16,8 +23,8 @@ props: postInstallCommands: - echo "Hello ${ @scffld name }!" - git init - - npm install - - npm run prettier + - ${ @scffld packageManager } install + - ${ @scffld packageManager } run prettier postInstallMessage: | ___ # Your web app '' has been created! diff --git a/src/cli/addTemplateOptions.ts b/src/cli/addTemplateOptions.ts index 4d20238..8cf302b 100644 --- a/src/cli/addTemplateOptions.ts +++ b/src/cli/addTemplateOptions.ts @@ -54,6 +54,10 @@ export const addTemplateOptions = ( option.parseArg = (value: string) => value === 'true'; } + if (prop.type === 'list') { + option.argChoices = prop.options; + } + if (prop.description) { option.description = prop.description; } diff --git a/src/cli/checkRequiredOptions.ts b/src/cli/checkRequiredOptions.ts index 8c96fc1..bc1e727 100644 --- a/src/cli/checkRequiredOptions.ts +++ b/src/cli/checkRequiredOptions.ts @@ -32,10 +32,16 @@ export const checkRequiredOptions = async ( if (params.props) { const prop = params.props[k]; prompts.push({ - type: prop.type === 'string' ? 'input' : 'confirm', + type: + prop.type === 'string' + ? 'input' + : prop.type === 'list' + ? 'list' + : 'confirm', name: k, message: prop.prompt || k, default: prop.default, + choices: prop.type === 'list' ? prop.options : undefined, }); } }); diff --git a/src/lib/types.ts b/src/lib/types.ts index aa2025e..d8c4876 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -5,10 +5,11 @@ export type TemplateProps = Record< { prompt?: string; shortName?: string; - type?: string; + type?: 'string' | 'boolean' | 'list'; required?: boolean; default?: TemplatePropType; description?: string; + options?: string[]; } >;