Skip to main content

writeCommand

Callable

  • writeCommand(directory: string): (command: Command, options?: { override?: boolean; path?: string; versionExistingContent?: boolean }) => Promise<void>

  • Write a command to EventCatalog.

    You can optionally override the path of the command.

    @example
    import utils from '@eventcatalog/utils';

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

    // Write a command to the catalog
    // Command would be written to commands/UpdateInventory
    await writeCommand({
    id: 'UpdateInventory',
    name: 'Update Inventory',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    });

    // Write a command to the catalog but override the path
    // Command would be written to commands/Inventory/UpdateInventory
    await writeCommand({
    id: 'UpdateInventory',
    name: 'Update Inventory',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    }, { path: "/Inventory/UpdateInventory"});

    // Write a command to the catalog and override the existing content (if there is any)
    await writeCommand({
    id: 'UpdateInventory',
    name: 'Update Inventory',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    }, { override: true });

    // Write a command to the catalog and version the previous version
    // only works if the new version is greater than the previous version
    await writeCommand({
    id: 'UpdateInventory',
    name: 'Update Inventory',
    version: '0.0.1',
    summary: 'This is a summary',
    markdown: '# Hello world',
    }, { versionExistingContent: true });