Skip to main content
View as Markdown

Function: writeFlow()

writeFlow(directory): (flow, options) => Promise<void>

Defined in: flows.ts:131

Write a flow to EventCatalog.

You can optionally override the path of the flow.

Parameters

ParameterType
directorystring

Returns

Function

Parameters

ParameterType
flowFlow
options{ format: "md" | "mdx"; override: boolean; path: string; versionExistingContent: boolean; }
options.format?"md" | "mdx"
options.override?boolean
options.path?string
options.versionExistingContent?boolean

Returns

Promise<void>

Example

import utils, { FlowBuilder } from '@eventcatalog/utils';

const { writeFlow } = utils('/path/to/eventcatalog');

// Build a flow using the fluent builder API
const flow = FlowBuilder.create({
id: 'PaymentFlow',
name: 'Payment Flow',
version: '0.0.1',
summary: 'Business flow for processing payments',
markdown: '# Payment Flow',
})
.addMessageStep({
id: 'PlaceOrder',
title: 'Place order',
message: { id: 'PlaceOrder', version: '0.0.1' },
nextSteps: [{ id: 'PaymentProcessed', label: 'Payment processed' }],
})
.addMessageStep({
id: 'PaymentProcessed',
title: 'Payment processed',
message: { id: 'PaymentProcessed', version: '0.0.1' },
})
.build();

// Flow would be written to flows/PaymentFlow
await writeFlow(flow);

// You can also write a raw Flow object
await writeFlow({
id: 'RewardFlow',
name: 'Reward Flow',
version: '0.0.1',
markdown: '# Reward Flow',
steps: [],
});

// Write a flow to the catalog but override the path
// Flow would be written to flows/Payments/RewardFlow
await writeFlow({
id: 'RewardFlow',
name: 'Reward Flow',
version: '0.0.1',
markdown: '# Reward Flow',
steps: [],
}, { path: '/Payments/RewardFlow' });

// Write a flow to the catalog and override the existing content
await writeFlow({
id: 'RewardFlow',
name: 'Reward Flow',
version: '0.0.1',
markdown: '# Reward Flow',
steps: [],
}, { override: true });