Skip to content

Commit

Permalink
feat: add list prop type
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayevans committed Jun 24, 2024
1 parent 016eee9 commit 47ec89d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
11 changes: 9 additions & 2 deletions examples/web-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ props:
name:
type: string
required: true
packageManager:
type: list
default: yarn
options:
- npm
- yarn
- pnpm
includeStyle:
type: boolean
default: true
Expand All @@ -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 '<!-- @scffld name -->' has been created!
Expand Down
4 changes: 4 additions & 0 deletions src/cli/addTemplateOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 7 additions & 1 deletion src/cli/checkRequiredOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
>;

Expand Down

0 comments on commit 47ec89d

Please sign in to comment.