import { parseDocument } from 'yaml'; import { modelIdFromName, titleFromName } from './templates'; /** * Example models shipped with the extension (templates/models/). * "Archify | New Model…" offers them; each is a complete model folder: * main.archify, registry/*.archify-registry and diagrams by level. */ export interface ModelExample { /** Folder under templates/models and the default name of the new model folder. */ folder: string; label: string; description: string; } export const MODEL_EXAMPLES: readonly ModelExample[] = [ { folder: 'c4-standard-web-app', label: 'C4 - Standard Web App', description: 'Single-page app, API, database, cache, file storage, identity provider' }, { folder: 'c4-e-shop', label: 'C4 - E-Shop', description: 'Web shop, API, worker, queue, payment and email providers' }, { folder: 'c4-event-based-integration', label: 'C4 - Event-Based Integration', description: 'Event bus, router, dead-letter queue, event store, consumers' }, ]; /** * The example's main.archify for a new model folder. When the folder keeps * the example's name the file is used as written; otherwise id, name and the * overview title follow the folder name and the description is kept. */ export function mainFromExample(mainText: string, folderName: string, example: ModelExample): string { if (folderName === example.folder) return mainText; const doc = parseDocument(mainText); doc.setIn(['model', 'id'], modelIdFromName(folderName)); doc.setIn(['model', 'name'], titleFromName(folderName)); if (doc.hasIn(['meta', 'title'])) doc.setIn(['meta', 'title'], `${titleFromName(folderName)} — overview`); return doc.toString({ lineWidth: 0, flowCollectionPadding: false }); }