wormaworma

Plugin System

The plugin system's 8 lifecycle hooks and progress reporting

worma's plugin system lets you hook into each lifecycle stage of code generation and modify the result.

Lifecycle

Hook execution order

config() → beforeSpecParse() → parse OpenAPI → specParsed()
→ getTemplate()                ← plugin returns the template path
→ beforeCodeGenerate(data)     ← plugin injects config data into templateData
→ onHandlebarsCreated(hbs)     ← can register custom helpers/partials
→ streaming render + write:
    loop each file:
       beforeFileWrite(filePath, content)  ← plugin modifies a single file's content
       writeFile(filePath)
→ codeGenerated(filePaths, renderTemplate)     ← notify / generate extra files (aiDoc, etc.)

Hook overview

HookWhenCan modifyconfig state
configAfter config parsingconfigMutable
beforeSpecParseBefore spec parsingRaw spec text specFrozen
specParsedAfter OpenAPI parsingdocumentFrozen
getTemplateBefore template loadingTemplate pathFrozen
beforeCodeGenerateBefore code generationTemplateDataFrozen
onHandlebarsCreatedAfter Handlebars instance creationhbs instance / partials / helpersFrozen
beforeFileWriteBefore each file writeSingle file contentFrozen
codeGeneratedAfter all files writtenfilePaths / render extra templates via renderTemplateFrozen

Progress reporting

If a plugin runs a slow operation, it can report its progress via reportProgress. Each plugin instance binds its own reportProgress, using the plugin name as the source label:

type ReportProgress = (progress: number, message?: string) => void;

On this page