- templates/models: C4 - Standard Web App, C4 - E-Shop, C4 - Event-Based Integration; each a complete model (main.archify, registry, context, containers, components) that validates - archify.newModel: pick an example and a folder name, copy it, name the model after the folder, open the model page - Explorer menu: New Model… on folders, Open Model on .archify and .archify-registry files; File → New File… lists New Model… - unit test validates every example end to end; integration test runs the command; README, CHANGELOG, docs/model.md
35 lines
1.7 KiB
TypeScript
35 lines
1.7 KiB
TypeScript
import { parseDocument } from 'yaml';
|
|
import { modelIdFromName, titleFromName } from './templates';
|
|
|
|
/**
|
|
* Example models shipped with the extension (templates/models/<folder>).
|
|
* "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 });
|
|
}
|