Blocks
A Block defines the logic to create a portion of a repository.
It defines a produce()
method for its core logic:
- It receives one parameter: a Context object containing options as well as other utilities.
- It returns a Creation object describing the generated pieces of tooling.
When create
scaffolds a repository, it merges together the produced outputs from all Blocks.
For example, this block describes creating a .nvmrc
file:
That blockNvmrc
can then be listed in a Preset’s blocks
array:
That presetCreateMyApp
would then produce an .nvmrc
file with text content 20.12.2
when run.
Options
Each Block runs with the options defined by its parent Schema.
For example, a Schema with a name
option could create a Block that generates part of a README.md file:
Args
Blocks may be extended with their own options, referred to as args. Blocks define args as the properties for a Zod object schema and then receive them in their context.
For example, a Prettier block that optionally allows adding in any plugins:
That blockPrettier
can then be listed in a Preset’s blocks
array:
That presetCreateMyApp
would then produce a .prettierrc.json
file with those three plugins listed in its JSON contents.
Inputs
Blocks can take in data from Inputs.
Blocks receive a take
function in their context that executes an input.
For example, a Blocks that adds all-contributors recognition using a JSON file input:
create
will handle lazily evaluating inputs and retrieving user-specified inputs.