Events
The Dinghy engine emits events at various stages of its operation. You can provide custom event handlers to modify the data model or perform additional tasks in response to these events as needed.
Event Handler
- To handle events, create a file named
events/on.EVENT_NAME.tsthat exports a default function. - The function's name can be anything; only the file name and only its default export is required.
- The function can be asynchronous if your handler needs to perform async work.
For example:
export default function onRenderStart(renderOptions: any) {
console.log('render started with stack based renderOptions', renderOptions)
}
Lifecyle Events
Lifecycle events are emitted as the Dinghy Engine executes commands. Most events
have start and finish variants to indicate the beginning and successful
completion of a phase. Some events may also have a failed variant, triggered
if an error occurs before completion.
You can refer to the relevant source code to see what arguments are passed to each event.
- engine.start|finish|failed - Wrap around engine command source
- render.start|finish - Wrap around render operation source
- tf.* - Events generated by tf-combined-cmds.ts for tf related operations
Format Based Events
These events occur right before the generated data model is written out in the final output format, giving you a last opportunity to make any modifications before the result is saved.
tf.generated– Fired after the Terraformtf.jsonmodel is produced sourcedrawio.generated– Fired after the DrawIO XML is generated source
Event Handler Arguments
- generated data model (modifiable)
- renderOptions used for output generation
Example Sequence
Below is the sequence of events emitted during a
dinghy tf diff --debug | grep dinghy:event command execution:
- engine.start
- tf.render.start (the following sequence repeats for each active stack)
- render.start
- tf.generated
- render.finish
- tf.render.finish
- tf.stacks.start (the following sequence repeats for each active stack)
- tf.stack.start
- tf.stack.init.start
- tf.stack.init.finish
- tf.stack.plan.start
- tf.stack.plan.finish
- tf.stack.changes.detected
- tf.stack.finish
- tf.stacks.changes.detected
- tf.stacks.finish
- tf.render.start (the following sequence repeats for each active stack)
- engine.finish