Files
archify-vscode-ext/scripts/patch-schemas.mjs
T
root-at-skic 7a2b661afe Models: main.archify, registries, refs, links and the model page; 0.7.0
A folder with main.archify at its top is a model, a set of diagrams
that belong together. Opening main.archify shows the model page: the
model's name and description, its own overview diagram when the file
has one, the diagrams grouped by folder (click to open), and the
registry with where each element is used. The page is built by
traversing the folder tree and refreshes when files change.

*.archify-registry files define shared elements once; diagrams draw
them with `ref: <id>` plus position and may override label, sublabel
and tag. References are resolved before Archify runs, so Archify is
unchanged. Hover, go-to-definition and completion on ref; unknown
names, forbidden overrides, duplicate ids and broken registries in
Problems; registry edits re-render open diagrams. `diagram:` links on
elements and components open the linked diagram on double-click.

New command Archify | Open Model, a Model template for New Diagram…,
editor schemas for the new keys and for registries, docs/model.md and
examples/online-shop. Single diagrams behave exactly as before.
2026-10-19 11:37:20 +03:00

80 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
// Adds the model keys to the editor schemas in schemas/ (the CLI keeps the
// strict originals): `model` on main.archify, `ref` and `diagram` on
// architecture components, and a schema for *.archify-registry files.
// Run after sync-archify.mjs, or on its own after editing this file.
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const schemas = path.join(root, 'schemas');
const read = (file) => JSON.parse(fs.readFileSync(path.join(schemas, file), 'utf8'));
const write = (file, value) => fs.writeFileSync(path.join(schemas, file), `${JSON.stringify(value, null, 2)}\n`);
const MODEL = {
type: 'object',
description: 'Only in main.archify: the entry point of a model (a folder of diagrams that belong together).',
additionalProperties: false,
required: ['id', 'name'],
properties: {
id: { type: 'string', pattern: '^[a-zA-Z][a-zA-Z0-9_-]*$', description: 'Stable id of the model.' },
name: { type: 'string', minLength: 1, description: 'Name shown on the model page.' },
description: { type: 'string', description: 'What the model covers; shown on the model page.' },
},
};
const DIAGRAM_LINK = { type: 'string', description: 'Diagram that explains this element, relative to the model root (main.archify). Double-click the node to open it.' };
for (const file of fs.readdirSync(schemas)) {
if (!/^(architecture|workflow|sequence|dataflow|lifecycle)\.schema\.json$/.test(file)) continue;
const schema = read(file);
schema.properties.model = MODEL;
if (file === 'architecture.schema.json') {
const item = schema.properties.components.items;
item.properties.ref = { type: 'string', pattern: '^[a-zA-Z][a-zA-Z0-9_-]*$', description: 'A shared element from the model’s registry (*.archify-registry). Its type, label, sublabel, brand and sources come from there; the diagram adds pos/size and may override label, sublabel and tag.' };
item.properties.diagram = DIAGRAM_LINK;
// A ref brings type and label with it; an inline component must state them.
item.anyOf = [{ required: ['ref'] }, { required: ['id', 'type', 'label'] }];
delete item.required;
}
write(file, schema);
}
const common = read('common.schema.json');
const componentType = common.$defs.componentType;
const registry = {
$schema: 'https://json-schema.org/draft/2020-12/schema',
title: 'Archify model registry',
description: 'Shared elements of a model: one name for one thing. Diagrams refer to an element with `ref: <id>`.',
type: 'object',
additionalProperties: false,
required: ['elements'],
properties: {
schema_version: { const: 1 },
elements: {
type: 'object',
description: 'Element id → element. Ids are unique across all registry files of the model.',
propertyNames: { pattern: '^[a-zA-Z][a-zA-Z0-9_-]*$' },
additionalProperties: {
type: 'object',
additionalProperties: false,
required: ['type', 'label'],
properties: {
type: componentType,
label: { type: 'string', minLength: 1 },
sublabel: { type: 'string' },
tag: { type: 'string' },
icon: common.$defs.nodeIcon,
brand: common.$defs.brandMark,
sources: common.$defs.sourceReferences,
description: { type: 'string', description: 'The one description of this thing; shown on hover and on the model page.' },
diagram: DIAGRAM_LINK,
},
},
},
},
};
write('archify-registry.schema.json', registry);
console.log('Patched editor schemas: model, ref, diagram; wrote archify-registry.schema.json');