Producer APIs
Production APIs can be used to create Creations:
produceBase
: generates Base optionsproduceBlock
: runs a Block productionproduceInput
: runs an InputproducePreset
: runs a Preset production
Each production API takes in up to two arguments:
- The construct to be produced
- An object with properties from the construct’s context as well as System contexts
produceBase
Given a Base, creates an options object by running its produce()
.
produceBase
takes in up to two argument:
base
(required): a Basesettings
(optional): any properties from a Base Context, except fortake
produceBase
returns a Promise for the resultant Creation.
For example, given this Base that declares an optional value
option that defaults to "default"
, produceBase
can run its produce()
with any provided options:
offline
Whether to hint to the Base not to make network requests.
This is equivalent to the --offline
CLI flag.
If provided, Input fetchers will reject with an Error instead of resolving.
For example, this Base is told to run offline:
options
Any number of options defined by the base.
For example, this Base is run with a name
option:
produceBlock
Given a Block, creates a Creation output by running its produce()
.
produceBlock
takes in up to two arguments:
block
(required): a Blocksettings
(required): at leastoptions
, as well as any other properties from a Block Context
For example, given this Block that produces the start of a README.md file, produceBlock
can run its produce()
with any provided options:
args
Any number of Args defined by the Block.
For example, given this Block with a prefix
Arg and a name
Option, both can be specified in produceBlock
:
created
Any Creations to simulate having been made from previously-produced Blocks.
offline
Whether to hint to the Block not to make network requests.
This is equivalent to the --offline
CLI flag.
If provided, Input fetchers will reject with an Error instead of resolving.
For example, this Base is told to run offline:
options
Any number of options defined by the Block’s Base.
For example, this Block is run with no Args and one name
Option:
produceInput
Given an Input, runs its produce()
with any provided args.
produceInput
takes in up to two arguments:
input
(required): an Inputsettings
(required): at leastoptions
, as well as any other properties from an Input Context other thantake
produceInput
returns a Promise for the result of the Input’s produce()
.
For example, this Input production reads data from an existing data.json
file on disk:
args
For example, this Input production reads data from a JSON file on disk by path:
producePreset
Given a Preset, creates a Creation output by running each of its Blocks produce()
.
producePreset
takes in up to two arguments:
preset
(required): a Presetsettings
(required):addons
(optional): any additional Addons to provide to Blocksblocks
(optional): any additions and/or removals of Blocksoptions
(required): Base options to run with- (optional) any other properties from a Block Context
producePreset
returns a Promise for an object containing:
creation
: The Preset’sCreation
, including both direct creations and indirect creationsoptions
: The full merged options that production ran with
For example, given this Preset that includes the block from produceBlock
, producePreset
can run its produce()
with any provided options:
addons
Any additional Addons to provide to Blocks.
For example, this production adds a "generated"
Addon to a Prettier Block:
See Configuration > addons
for how this is used.
blocks
Any Blocks to add
and/or remove
.
For example, this production swaps in a Jest Block instead of a Vitest Block:
See Configuration > blocks
for how this is used.
offline
Whether to hint to the Preset not to make network requests.
This is equivalent to the --offline
CLI flag.
If provided, Input fetchers will reject with an Error instead of resolving.
For example, this Preset is told to run offline:
options
Any options defined by the Preset’s Base.
This must include all required Options from the Base. It may also include any other optional Options.
For example, this Preset is run with a name
option:
System Overrides
The properties specific to System Contexts can be overridden in production APIs.
This can be useful if you’d like a production’s Inputs to run in a virtual environment or otherwise augment system interactions.
For example, this Block production adds an authorization header to all network requests: