@likec4/generators 1.31.0 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/d2/generate-d2.d.ts +3 -2
- package/dist/d2/generate-d2.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mmd/generate-mmd.d.ts +3 -2
- package/dist/mmd/generate-mmd.js +2 -1
- package/dist/model/generate-aux.d.ts +2 -0
- package/dist/model/generate-aux.js +66 -0
- package/dist/model/generate-likec4-model.d.ts +2 -2
- package/dist/model/generate-likec4-model.js +8 -10
- package/dist/puml/generate-puml.d.ts +2 -0
- package/dist/puml/generate-puml.js +176 -0
- package/dist/puml/index.d.ts +1 -0
- package/dist/puml/index.js +1 -0
- package/dist/react/generate-react-types.d.ts +2 -2
- package/dist/react/generate-react-types.js +14 -73
- package/dist/views-data-ts/generate-views-data.d.ts +9 -0
- package/package.json +6 -6
- package/src/__mocks__/data.ts +83 -83
- package/src/d2/__snapshots__/generate-d2.spec.ts.snap +78 -0
- package/src/d2/generate-d2.spec.ts +91 -4
- package/src/d2/generate-d2.ts +20 -15
- package/src/index.ts +1 -0
- package/src/mmd/generate-mmd.spec.ts +12 -4
- package/src/mmd/generate-mmd.ts +25 -20
- package/src/model/__snapshots__/aux.generate-valid-code.snap +56 -0
- package/src/model/__snapshots__/{likec4-model.snap → likec4.computed-model.snap} +342 -165
- package/src/model/__snapshots__/likec4.parsed-model.snap +671 -0
- package/src/model/generate-aux.spec.ts +65 -0
- package/src/model/generate-aux.ts +72 -0
- package/src/model/generate-likec4-model.spec.ts +34 -8
- package/src/model/generate-likec4-model.ts +13 -14
- package/src/puml/__snapshots__/generate-puml.spec.ts.snap +184 -0
- package/src/puml/generate-puml.spec.ts +26 -0
- package/src/puml/generate-puml.ts +264 -0
- package/src/puml/index.ts +1 -0
- package/src/react/__snapshots__/valid-code.snap +111 -0
- package/src/react/generate-react-types.spec.ts +67 -0
- package/src/react/generate-react-types.ts +16 -77
- package/src/views-data-ts/generate-views-data.ts +18 -9
package/dist/d2/generate-d2.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { LikeC4ViewModel } from '@likec4/core/model';
|
|
2
|
+
import type { aux } from '@likec4/core/types';
|
|
3
|
+
export declare function generateD2(viewmodel: LikeC4ViewModel<aux.Unknown>): any;
|
package/dist/d2/generate-d2.js
CHANGED
|
@@ -38,7 +38,8 @@ const d2shape = ({ shape }) => {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
export function generateD2(
|
|
41
|
+
export function generateD2(viewmodel) {
|
|
42
|
+
const view = viewmodel.$view;
|
|
42
43
|
const { nodes, edges } = view;
|
|
43
44
|
const names = /* @__PURE__ */ new Map();
|
|
44
45
|
const printNode = (node, parentName) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { generateD2 } from './d2/generate-d2';
|
|
2
2
|
export { generateMermaid } from './mmd/generate-mmd';
|
|
3
3
|
export { generateLikeC4Model } from './model/generate-likec4-model';
|
|
4
|
+
export { generatePuml } from './puml/generate-puml';
|
|
4
5
|
export { generateReactNext } from './react-next/generate-react-next';
|
|
5
6
|
export { generateReactTypes } from './react/generate-react-types';
|
|
6
7
|
export { generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs } from './views-data-ts/generate-views-data';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { generateD2 } from "./d2/generate-d2.js";
|
|
2
2
|
export { generateMermaid } from "./mmd/generate-mmd.js";
|
|
3
3
|
export { generateLikeC4Model } from "./model/generate-likec4-model.js";
|
|
4
|
+
export { generatePuml } from "./puml/generate-puml.js";
|
|
4
5
|
export { generateReactNext } from "./react-next/generate-react-next.js";
|
|
5
6
|
export { generateReactTypes } from "./react/generate-react-types.js";
|
|
6
7
|
export { generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs } from "./views-data-ts/generate-views-data.js";
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { LikeC4ViewModel } from '@likec4/core/model';
|
|
2
|
+
import type { aux } from '@likec4/core/types';
|
|
3
|
+
export declare function generateMermaid(viewmodel: LikeC4ViewModel<aux.Unknown>): any;
|
package/dist/mmd/generate-mmd.js
CHANGED
|
@@ -22,7 +22,8 @@ const mmdshape = ({ shape }) => {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
export function generateMermaid(
|
|
25
|
+
export function generateMermaid(viewmodel) {
|
|
26
|
+
const view = viewmodel.$view;
|
|
26
27
|
const { nodes, edges } = view;
|
|
27
28
|
const names = /* @__PURE__ */ new Map();
|
|
28
29
|
const printNode = (node, parentName) => {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compareNatural,
|
|
3
|
+
sortNaturalByFqn
|
|
4
|
+
} from "@likec4/core";
|
|
5
|
+
import { keys, map, pipe, values } from "remeda";
|
|
6
|
+
function toUnion(elements) {
|
|
7
|
+
if (elements.length === 0) {
|
|
8
|
+
return "never";
|
|
9
|
+
}
|
|
10
|
+
let union = elements.sort(compareNatural).map((v) => ` | ${JSON.stringify(v)}`);
|
|
11
|
+
return union.join("\n").trimStart();
|
|
12
|
+
}
|
|
13
|
+
function elementIdToUnion(_elements) {
|
|
14
|
+
const elements = values(_elements);
|
|
15
|
+
if (elements.length === 0) {
|
|
16
|
+
return "never";
|
|
17
|
+
}
|
|
18
|
+
let union = pipe(
|
|
19
|
+
elements,
|
|
20
|
+
sortNaturalByFqn,
|
|
21
|
+
map((v) => ` | ${JSON.stringify(v.id)}`)
|
|
22
|
+
);
|
|
23
|
+
return union.join("\n").trimStart();
|
|
24
|
+
}
|
|
25
|
+
export function generateAux(model) {
|
|
26
|
+
return `
|
|
27
|
+
import type { Aux, SpecAux } from '@likec4/core/types';
|
|
28
|
+
|
|
29
|
+
export type $Specs = SpecAux<
|
|
30
|
+
// Element kinds
|
|
31
|
+
${toUnion(keys(model.specification.elements))},
|
|
32
|
+
// Deployment kinds
|
|
33
|
+
${toUnion(keys(model.specification.deployments ?? {}))},
|
|
34
|
+
// Relationship kinds
|
|
35
|
+
${toUnion(keys(model.specification.relationships ?? {}))},
|
|
36
|
+
// Tags
|
|
37
|
+
${toUnion(keys(model.specification.tags ?? {}))},
|
|
38
|
+
// Metadata keys
|
|
39
|
+
${toUnion(model.specification.metadataKeys ?? [])}
|
|
40
|
+
>
|
|
41
|
+
|
|
42
|
+
export type $Aux = Aux<
|
|
43
|
+
${JSON.stringify(model.stage)},
|
|
44
|
+
// Elements
|
|
45
|
+
${elementIdToUnion(model.$data.elements)},
|
|
46
|
+
// Deployments
|
|
47
|
+
${elementIdToUnion(model.$data.deployments.elements)},
|
|
48
|
+
// Views
|
|
49
|
+
${toUnion(keys(model.$data.views))},
|
|
50
|
+
// Project ID
|
|
51
|
+
${JSON.stringify(model.projectId)},
|
|
52
|
+
$Specs
|
|
53
|
+
>
|
|
54
|
+
|
|
55
|
+
export type $ElementId = $Aux['ElementId']
|
|
56
|
+
export type $DeploymentId = $Aux['DeploymentId']
|
|
57
|
+
export type $ViewId = $Aux['ViewId']
|
|
58
|
+
|
|
59
|
+
export type $ElementKind = $Aux['ElementKind']
|
|
60
|
+
export type $RelationKind = $Aux['RelationKind']
|
|
61
|
+
export type $DeploymentKind = $Aux['DeploymentKind']
|
|
62
|
+
export type $Tag = $Aux['Tag']
|
|
63
|
+
export type $Tags = readonly $Aux['Tag'][]
|
|
64
|
+
export type $MetadataKey = $Aux['MetadataKey']
|
|
65
|
+
`.trimStart();
|
|
66
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function generateLikeC4Model(model: LikeC4Model): any;
|
|
1
|
+
import type { LikeC4Model } from '@likec4/core/model';
|
|
2
|
+
export declare function generateLikeC4Model(model: LikeC4Model<any>): any;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import JSON5 from "json5";
|
|
2
2
|
import { CompositeGeneratorNode, toString } from "langium/generate";
|
|
3
|
+
import { capitalize } from "remeda";
|
|
4
|
+
import { generateAux } from "./generate-aux.js";
|
|
3
5
|
export function generateLikeC4Model(model) {
|
|
4
6
|
const out = new CompositeGeneratorNode();
|
|
7
|
+
const aux = generateAux(model);
|
|
8
|
+
const ModelData = capitalize(model.stage) + "LikeC4ModelData";
|
|
5
9
|
out.appendTemplate`
|
|
6
10
|
/* prettier-ignore-start */
|
|
7
11
|
/* eslint-disable */
|
|
@@ -11,17 +15,11 @@ export function generateLikeC4Model(model) {
|
|
|
11
15
|
* DO NOT EDIT MANUALLY!
|
|
12
16
|
******************************************************************************/
|
|
13
17
|
|
|
14
|
-
import { LikeC4Model } from 'likec4/model'
|
|
18
|
+
import { LikeC4Model } from '@likec4/core/model'
|
|
19
|
+
import type { ${ModelData} } from '@likec4/core/types'
|
|
20
|
+
${aux}
|
|
15
21
|
|
|
16
|
-
export const
|
|
17
|
-
space: 2,
|
|
18
|
-
quote: "'"
|
|
19
|
-
})})
|
|
20
|
-
|
|
21
|
-
export type LikeC4ModelTypes = typeof likeC4Model.Aux
|
|
22
|
-
export type LikeC4ElementId = LikeC4ModelTypes['Fqn']
|
|
23
|
-
export type LikeC4DeploymentId = LikeC4ModelTypes['Deployment']
|
|
24
|
-
export type LikeC4ViewId = LikeC4ModelTypes['ViewId']
|
|
22
|
+
export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(<${ModelData}<$Aux>>(${JSON5.stringify(model.$data, { space: 2, quote: "'" })} as unknown))
|
|
25
23
|
|
|
26
24
|
/* prettier-ignore-end */
|
|
27
25
|
`;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { CompositeGeneratorNode, joinToNode, NL, toString } from "langium/generate";
|
|
2
|
+
import { isNullish as isNil } from "remeda";
|
|
3
|
+
const capitalizeFirstLetter = (value) => value.charAt(0).toLocaleUpperCase() + value.slice(1);
|
|
4
|
+
const fqnName = (nodeId) => nodeId.split(".").map(capitalizeFirstLetter).join("");
|
|
5
|
+
const nodeName = (node) => {
|
|
6
|
+
return fqnName(node.parent ? node.id.slice(node.parent.length + 1) : node.id);
|
|
7
|
+
};
|
|
8
|
+
const pumlColor = (color, customColorProvider, defaultColor = "#3b82f6") => {
|
|
9
|
+
switch (color) {
|
|
10
|
+
case "blue":
|
|
11
|
+
case "primary": {
|
|
12
|
+
return "#3b82f6";
|
|
13
|
+
}
|
|
14
|
+
case "amber": {
|
|
15
|
+
return "#a35829";
|
|
16
|
+
}
|
|
17
|
+
case "gray": {
|
|
18
|
+
return "#737373";
|
|
19
|
+
}
|
|
20
|
+
case "green": {
|
|
21
|
+
return "#428a4f";
|
|
22
|
+
}
|
|
23
|
+
case "indigo": {
|
|
24
|
+
return "#6366f1";
|
|
25
|
+
}
|
|
26
|
+
case "slate":
|
|
27
|
+
case "muted": {
|
|
28
|
+
return "#64748b";
|
|
29
|
+
}
|
|
30
|
+
case "red": {
|
|
31
|
+
return "#ac4d39";
|
|
32
|
+
}
|
|
33
|
+
case "sky":
|
|
34
|
+
case "secondary": {
|
|
35
|
+
return "#0284c7";
|
|
36
|
+
}
|
|
37
|
+
case null:
|
|
38
|
+
case void 0: {
|
|
39
|
+
return defaultColor;
|
|
40
|
+
}
|
|
41
|
+
default:
|
|
42
|
+
return customColorProvider(color) || color;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const pumlDirection = ({ autoLayout }) => {
|
|
46
|
+
switch (autoLayout.direction) {
|
|
47
|
+
case "TB": {
|
|
48
|
+
return "top to bottom";
|
|
49
|
+
}
|
|
50
|
+
case "BT": {
|
|
51
|
+
console.warn("Bottom to top direction is not supported. Defaulting to top to bottom.");
|
|
52
|
+
return "top to bottom";
|
|
53
|
+
}
|
|
54
|
+
case "LR": {
|
|
55
|
+
return "left to right";
|
|
56
|
+
}
|
|
57
|
+
case "RL": {
|
|
58
|
+
console.warn("Right to left direction is not supported. Defaulting to left to right.");
|
|
59
|
+
return "left to right";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const pumlShape = ({ shape }) => {
|
|
64
|
+
switch (shape) {
|
|
65
|
+
case "queue":
|
|
66
|
+
case "rectangle":
|
|
67
|
+
case "person": {
|
|
68
|
+
return shape;
|
|
69
|
+
}
|
|
70
|
+
case "storage":
|
|
71
|
+
case "cylinder": {
|
|
72
|
+
return "database";
|
|
73
|
+
}
|
|
74
|
+
case "mobile":
|
|
75
|
+
case "browser": {
|
|
76
|
+
return "rectangle";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const escapeLabel = (label) => isNil(label) ? null : JSON.stringify(label).slice(1, -1);
|
|
81
|
+
export function generatePuml(viewmodel) {
|
|
82
|
+
const view = viewmodel.$view;
|
|
83
|
+
const customColorDefinitions = viewmodel.$model.specification.customColors ?? {};
|
|
84
|
+
const { nodes, edges } = view;
|
|
85
|
+
const customColors = new Map(Object.entries(customColorDefinitions));
|
|
86
|
+
const elemntColorProvider = (key) => (colorKey) => customColors.get(colorKey)?.elements[key];
|
|
87
|
+
const relationshipsColorProvider = (key) => (colorKey) => customColors.get(colorKey)?.relationships[key];
|
|
88
|
+
const names = /* @__PURE__ */ new Map();
|
|
89
|
+
const printHeader = () => {
|
|
90
|
+
return new CompositeGeneratorNode().append('title "', view.title || view.id, '"', NL).append(pumlDirection(view), " direction", NL);
|
|
91
|
+
};
|
|
92
|
+
const printTheme = () => {
|
|
93
|
+
return new CompositeGeneratorNode().append("hide stereotype", NL).append("skinparam ranksep ", "60", NL).append("skinparam nodesep ", "30", NL).append("skinparam {", NL).indent({
|
|
94
|
+
indentedChildren: (indent) => indent.append("arrowFontSize ", "10", NL).append("defaultTextAlignment ", "center", NL).append("wrapWidth ", "200", NL).append("maxMessageSize ", "100", NL).append("shadowing ", "false", NL),
|
|
95
|
+
indentation: 2
|
|
96
|
+
}).append("}", NL);
|
|
97
|
+
};
|
|
98
|
+
const printStereotypes = (node) => {
|
|
99
|
+
const shape = pumlShape(node);
|
|
100
|
+
const fqn = fqnName(node.id);
|
|
101
|
+
return new CompositeGeneratorNode().append("skinparam ", shape, "<<", fqn, ">>", "{", NL).indent({
|
|
102
|
+
indentedChildren: (indent) => indent.append("BackgroundColor ", pumlColor(node.color, elemntColorProvider("fill")), NL).append(
|
|
103
|
+
"FontColor ",
|
|
104
|
+
customColors.has(node.color) ? pumlColor(node.color, elemntColorProvider("hiContrast")) : "#FFFFFF",
|
|
105
|
+
NL
|
|
106
|
+
).append("BorderColor ", pumlColor(node.color, elemntColorProvider("stroke")), NL),
|
|
107
|
+
indentation: 2
|
|
108
|
+
}).append("}", NL);
|
|
109
|
+
};
|
|
110
|
+
const printNode = (node) => {
|
|
111
|
+
const shape = pumlShape(node);
|
|
112
|
+
const fqn = fqnName(node.id);
|
|
113
|
+
const label = escapeLabel(node.title) || nodeName(node);
|
|
114
|
+
const tech = escapeLabel(node.technology);
|
|
115
|
+
names.set(node.id, fqn);
|
|
116
|
+
return new CompositeGeneratorNode().append(shape, " ").append('"').append("==", label).appendIf(!!tech, "\\n", "<size:10>[", tech, "]</size>").appendIf(!!node.description, "\\n\\n", escapeLabel(node.description)).append('"', " <<", fqn, ">> ", "as ", fqn, NL);
|
|
117
|
+
};
|
|
118
|
+
const printBoundary = (node) => {
|
|
119
|
+
const label = escapeLabel(node.title) || nodeName(node);
|
|
120
|
+
const fqn = fqnName(node.id);
|
|
121
|
+
names.set(node.id, fqn);
|
|
122
|
+
return new CompositeGeneratorNode().append('rectangle "', label, '" <<', fqn, ">> as ", fqn, " {", NL).indent({
|
|
123
|
+
indentedChildren: (indent) => indent.append(
|
|
124
|
+
"skinparam ",
|
|
125
|
+
"RectangleBorderColor<<",
|
|
126
|
+
fqn,
|
|
127
|
+
">> ",
|
|
128
|
+
pumlColor(node.color, elemntColorProvider("fill")),
|
|
129
|
+
NL
|
|
130
|
+
).append(
|
|
131
|
+
"skinparam ",
|
|
132
|
+
"RectangleFontColor<<",
|
|
133
|
+
fqn,
|
|
134
|
+
">> ",
|
|
135
|
+
pumlColor(node.color, elemntColorProvider("fill")),
|
|
136
|
+
NL
|
|
137
|
+
).append("skinparam ", "RectangleBorderStyle<<", fqn, ">> ", "dashed", NL, NL).append(joinToNode(
|
|
138
|
+
nodes.filter((n) => n.parent === node.id),
|
|
139
|
+
(c) => c.children.length > 0 ? printBoundary(c) : printNode(c)
|
|
140
|
+
)),
|
|
141
|
+
indentation: 2
|
|
142
|
+
}).append("}", NL);
|
|
143
|
+
};
|
|
144
|
+
const printEdge = (edge) => {
|
|
145
|
+
const tech = escapeLabel(edge.technology) || "";
|
|
146
|
+
const label = escapeLabel(edge.label) || "";
|
|
147
|
+
const color = pumlColor(edge.color, relationshipsColorProvider("lineColor"), "#777777");
|
|
148
|
+
const colorTag = (color2) => `<color:${color2}>`;
|
|
149
|
+
return new CompositeGeneratorNode().append(names.get(edge.source), " .[", color, ",thickness=2].> ", names.get(edge.target)).appendIf(!!(label || tech), ' : "', colorTag(color)).appendIf(!!label, label, colorTag(color)).appendIf(!!(label && tech), "\\n").appendIf(!!tech, colorTag(color), "<size:8>[", tech, "]</size>").appendIf(!!(label || tech), '"').append(NL);
|
|
150
|
+
};
|
|
151
|
+
return toString(
|
|
152
|
+
new CompositeGeneratorNode().append("@startuml", NL).append(printHeader(), NL).append(printTheme(), NL).append(
|
|
153
|
+
joinToNode(
|
|
154
|
+
nodes.filter((n) => n.children.length == 0),
|
|
155
|
+
(n) => printStereotypes(n),
|
|
156
|
+
{
|
|
157
|
+
appendNewLineIfNotEmpty: true
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
).append(
|
|
161
|
+
joinToNode(
|
|
162
|
+
nodes.filter((n) => isNil(n.parent)),
|
|
163
|
+
(n) => n.children.length > 0 ? printBoundary(n) : printNode(n),
|
|
164
|
+
{
|
|
165
|
+
appendNewLineIfNotEmpty: true
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
).appendIf(
|
|
169
|
+
edges.length > 0,
|
|
170
|
+
NL,
|
|
171
|
+
joinToNode(edges, (e) => printEdge(e), {
|
|
172
|
+
appendNewLineIfNotEmpty: true
|
|
173
|
+
})
|
|
174
|
+
).append(`@enduml`, NL)
|
|
175
|
+
);
|
|
176
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generate-puml';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./generate-puml.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function generateReactTypes(model:
|
|
1
|
+
import type { AnyLikeC4Model } from '@likec4/core/model';
|
|
2
|
+
export declare function generateReactTypes(model: AnyLikeC4Model): string;
|
|
@@ -1,41 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
if (unionset instanceof Set) {
|
|
4
|
-
unionset = [...unionset].sort(compareNatural);
|
|
5
|
-
}
|
|
6
|
-
const union = unionset.map((v) => ` | ${JSON.stringify(v)}`);
|
|
7
|
-
if (union.length === 0) {
|
|
8
|
-
union.push(" never");
|
|
9
|
-
}
|
|
10
|
-
return union.join("\n") + ";";
|
|
11
|
-
}
|
|
1
|
+
import { invariant } from "@likec4/core";
|
|
2
|
+
import { generateAux } from "../model/generate-aux.js";
|
|
12
3
|
export function generateReactTypes(model) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
tags,
|
|
16
|
-
kinds
|
|
17
|
-
} = sortNaturalByFqn([...model.elements()]).reduce((acc, d) => {
|
|
18
|
-
acc.fqns.push(d.id);
|
|
19
|
-
acc.kinds.add(d.kind);
|
|
20
|
-
acc.tags.push(...d.tags);
|
|
21
|
-
return acc;
|
|
22
|
-
}, {
|
|
23
|
-
fqns: [],
|
|
24
|
-
kinds: /* @__PURE__ */ new Set(),
|
|
25
|
-
tags: []
|
|
26
|
-
});
|
|
27
|
-
const deploymentFqns = sortNaturalByFqn([...model.deployment.elements()]).map((e) => e.id);
|
|
28
|
-
const {
|
|
29
|
-
viewIds
|
|
30
|
-
} = [...model.views()].reduce((acc, d) => {
|
|
31
|
-
acc.viewIds.add(d.id);
|
|
32
|
-
acc.tags.push(...d.tags);
|
|
33
|
-
acc.tags.push(...d.includedTags);
|
|
34
|
-
return acc;
|
|
35
|
-
}, {
|
|
36
|
-
viewIds: /* @__PURE__ */ new Set(),
|
|
37
|
-
tags
|
|
38
|
-
});
|
|
4
|
+
invariant(!model.isParsed(), "can not generate react types for parsed model");
|
|
5
|
+
const aux = generateAux(model);
|
|
39
6
|
return `
|
|
40
7
|
/* prettier-ignore-start */
|
|
41
8
|
/* eslint-disable */
|
|
@@ -47,39 +14,20 @@ export function generateReactTypes(model) {
|
|
|
47
14
|
|
|
48
15
|
import type { PropsWithChildren } from 'react'
|
|
49
16
|
import type { JSX } from 'react/jsx-runtime'
|
|
50
|
-
import type {
|
|
51
|
-
|
|
52
|
-
LikeC4Model as GenericLikeC4Model,
|
|
53
|
-
} from 'likec4/model'
|
|
17
|
+
import type { LikeC4Model } from '@likec4/core/model'
|
|
18
|
+
import type { DiagramView } from '@likec4/core/types'
|
|
54
19
|
import type {
|
|
55
20
|
LikeC4ViewProps as GenericLikeC4ViewProps,
|
|
56
21
|
ReactLikeC4Props as GenericReactLikeC4Props
|
|
57
22
|
} from 'likec4/react'
|
|
58
23
|
|
|
59
|
-
|
|
60
|
-
${toUnion(fqns)}
|
|
61
|
-
|
|
62
|
-
type LikeC4DeploymentId =
|
|
63
|
-
${toUnion(deploymentFqns)}
|
|
64
|
-
|
|
65
|
-
type LikeC4ViewId =
|
|
66
|
-
${toUnion(viewIds)}
|
|
67
|
-
|
|
68
|
-
type LikeC4ElementKind =
|
|
69
|
-
${toUnion(kinds)}
|
|
70
|
-
|
|
71
|
-
type LikeC4Tag =
|
|
72
|
-
${toUnion(new Set(tags))}
|
|
73
|
-
|
|
74
|
-
declare function isLikeC4ViewId(value: unknown): value is LikeC4ViewId;
|
|
24
|
+
${aux}
|
|
75
25
|
|
|
76
|
-
|
|
77
|
-
type LikeC4Model = GenericLikeC4Model<Aux>;
|
|
78
|
-
type LikeC4ViewModel = GenericLikeC4Model.View<Aux>;
|
|
26
|
+
declare function isLikeC4ViewId(value: unknown): value is $ViewId;
|
|
79
27
|
|
|
80
|
-
declare const
|
|
81
|
-
declare function useLikeC4Model(): LikeC4Model
|
|
82
|
-
declare function useLikeC4View(viewId:
|
|
28
|
+
declare const likec4model: LikeC4Model<$Aux>;
|
|
29
|
+
declare function useLikeC4Model(): LikeC4Model<$Aux>;
|
|
30
|
+
declare function useLikeC4View(viewId: $ViewId): DiagramView<$Aux>;
|
|
83
31
|
|
|
84
32
|
declare function LikeC4ModelProvider(props: PropsWithChildren): JSX.Element;
|
|
85
33
|
|
|
@@ -92,26 +40,19 @@ type IconRendererProps = {
|
|
|
92
40
|
}
|
|
93
41
|
declare function RenderIcon(props: IconRendererProps): JSX.Element;
|
|
94
42
|
|
|
95
|
-
type LikeC4ViewProps = GenericLikeC4ViewProps
|
|
43
|
+
type LikeC4ViewProps = GenericLikeC4ViewProps<$Aux>;
|
|
96
44
|
declare function LikeC4View({viewId, ...props}: LikeC4ViewProps): JSX.Element;
|
|
97
45
|
|
|
98
|
-
type ReactLikeC4Props = GenericReactLikeC4Props
|
|
46
|
+
type ReactLikeC4Props = GenericReactLikeC4Props<$Aux>
|
|
99
47
|
declare function ReactLikeC4({viewId, ...props}: ReactLikeC4Props): JSX.Element;
|
|
100
48
|
|
|
101
49
|
export {
|
|
102
|
-
type LikeC4ElementId,
|
|
103
|
-
type LikeC4DeploymentId,
|
|
104
|
-
type LikeC4ViewId,
|
|
105
|
-
type LikeC4Tag,
|
|
106
|
-
type LikeC4ElementKind,
|
|
107
50
|
type LikeC4ViewProps,
|
|
108
51
|
type ReactLikeC4Props,
|
|
109
|
-
type LikeC4Model,
|
|
110
52
|
isLikeC4ViewId,
|
|
111
53
|
useLikeC4Model,
|
|
112
54
|
useLikeC4View,
|
|
113
|
-
|
|
114
|
-
likeC4Model,
|
|
55
|
+
likec4model,
|
|
115
56
|
LikeC4ModelProvider,
|
|
116
57
|
LikeC4View,
|
|
117
58
|
RenderIcon,
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { DiagramView } from '@likec4/core';
|
|
2
|
+
/**
|
|
3
|
+
* Generate *.js file with views data
|
|
4
|
+
*/
|
|
2
5
|
export declare function generateViewsDataJs(diagrams: Iterable<DiagramView>): any;
|
|
6
|
+
/**
|
|
7
|
+
* Generate *.ts file with views data
|
|
8
|
+
*/
|
|
3
9
|
export declare function generateViewsDataTs(diagrams: Iterable<DiagramView>): any;
|
|
10
|
+
/**
|
|
11
|
+
* Generate *.d.ts
|
|
12
|
+
*/
|
|
4
13
|
export declare function generateViewsDataDTs(diagrams: Iterable<DiagramView>): any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/generators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"json5": "^2.2.3",
|
|
35
35
|
"langium": "3.5.0",
|
|
36
|
-
"remeda": "^2.
|
|
37
|
-
"@likec4/core": "1.
|
|
36
|
+
"remeda": "^2.23.0",
|
|
37
|
+
"@likec4/core": "1.32.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/node": "^20.
|
|
40
|
+
"@types/node": "^20.19.0",
|
|
41
41
|
"typescript": "^5.8.3",
|
|
42
42
|
"unbuild": "^3.5.0",
|
|
43
|
-
"vitest": "^3.
|
|
44
|
-
"@likec4/tsconfig": "1.
|
|
43
|
+
"vitest": "^3.2.3",
|
|
44
|
+
"@likec4/tsconfig": "1.32.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"typecheck": "tsc -b --verbose",
|