Attributes

The meta of a template document is called Attributes. Several options can be combined for flexible file generation.

Options#

List of attributes that can be specified with Front Matter.

keytypedescription
name
(required)
stringName of template.
root
(required)
stringThe directory as the starting point of the output destination.
output
(required)
string
string[]
Directory starting from root and being a destination candidate. You can use glob syntax. (see globby document)
ignorestring[]Directory to exclude from candidate output destination. You can use glob syntax. (see globby document)
questionsobjectMessage to display when accepting input.

Questions#

questions is a protocol for accepting the necessary input for the template. scaffdog provides several options so that you can define a suitable question type.

Free text#

Invokes the most commonly used prompt that accepts strings.

questions:
# syntax sugar
value1: 'Please enter any text.'
# with message
value2:
message: 'Please enter any text.'
# with default value
value3:
message: 'Please enter any text.'
initial: 'scaffdog'
free text prompt

Boolean#

Invoke a prompt that accepts a Boolean.

questions:
# basic
bool1:
confirm: 'Do you need something?'
# with default value
bool2:
confirm: 'Do you need something?'
initial: false
boolean prompt

Choice#

Invokes a prompt to select a single value from a list.

questions:
# basic
value1:
message: 'Please select a value.'
choices:
- 'A'
- 'B'
- 'C'
# with default value
value2:
message: 'Please select a value.'
choices:
- 'A'
- 'B'
- 'C'
initial: 'B'
choice prompt

Array#

Invokes a prompt to select multiple selections from the list.

questions:
# basic
value1:
message: 'Please select a value.'
multiple: true
choices:
- 'A'
- 'B'
- 'C'
# with default value
value2:
message: 'Please select a value.'
multiple: true
choices:
- 'A'
- 'B'
- 'C'
initial: ['B']
array prompt

Conditional Prompt#

If the result of the expression in the if field is true, Prompt is invoked. If it false, skip Prompt and assign initial values. The initial value is assigned to the initial field if it exists. If not, a zero value is assigned according to the Prompt type.

questions:
name:
message: 'Please enter a component name.'
# Invokes confirm prompt only when input includes "Form".
test:
if: contains(inputs.name, 'Form')
confirm: 'Do you need a test?'

This is useful when you want to use a Prompt that is only needed for some use cases in the target file.

Edit this page on GitHub

Last edited on

Copyright © 2022 wadackel

Released under the MIT License

Built with Next.js

Source Code