@likec4/generators 1.5.0 → 1.29.1
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/LICENSE +21 -0
- package/dist/d2/generate-d2.d.ts +1 -2
- package/dist/d2/generate-d2.js +70 -63
- package/dist/d2/index.d.ts +0 -1
- package/dist/d2/index.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -5
- package/dist/mmd/generate-mmd.d.ts +1 -2
- package/dist/mmd/generate-mmd.js +82 -63
- package/dist/mmd/index.d.ts +0 -1
- package/dist/mmd/index.js +1 -1
- package/dist/model/generate-likec4-model.d.ts +2 -0
- package/dist/model/generate-likec4-model.js +29 -0
- package/dist/model/generate-likec4.d.ts +2 -0
- package/dist/model/generate-likec4.js +2 -0
- package/dist/react/generate-react-types.d.ts +2 -0
- package/dist/react/generate-react-types.js +122 -0
- package/dist/react/index.d.ts +1 -2
- package/dist/react/index.js +1 -1
- package/dist/react-next/generate-react-next.d.ts +9 -7
- package/dist/react-next/generate-react-next.js +26 -26
- package/dist/react-next/index.d.ts +0 -1
- package/dist/react-next/index.js +1 -1
- package/dist/views-data-ts/generate-views-data.d.ts +3 -4
- package/dist/views-data-ts/generate-views-data.js +64 -54
- package/dist/views-data-ts/generateViewId.d.ts +1 -2
- package/dist/views-data-ts/generateViewId.js +5 -4
- package/dist/views-data-ts/index.d.ts +0 -1
- package/dist/views-data-ts/index.js +1 -1
- package/package.json +25 -27
- package/src/__mocks__/data.ts +463 -0
- package/src/d2/__snapshots__/generate-d2.spec.ts.snap +91 -0
- package/src/d2/generate-d2.spec.ts +15 -0
- package/src/d2/generate-d2.ts +106 -0
- package/src/d2/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/mmd/__snapshots__/generate-mmd.spec.ts.snap +55 -0
- package/src/mmd/generate-mmd.spec.ts +15 -0
- package/src/mmd/generate-mmd.ts +110 -0
- package/src/mmd/index.ts +1 -0
- package/src/model/__snapshots__/likec4-model.snap +990 -0
- package/src/model/generate-likec4-model.spec.ts +158 -0
- package/src/model/generate-likec4-model.ts +33 -0
- package/src/model/generate-likec4.ts +5 -0
- package/src/react/generate-react-types.ts +127 -0
- package/src/react/index.ts +1 -0
- package/src/react-next/generate-react-next.ts +111 -0
- package/src/react-next/index.ts +1 -0
- package/src/views-data-ts/__snapshots__/generate-views-data.spec.ts.snap +83 -0
- package/src/views-data-ts/generate-views-data.spec.ts +15 -0
- package/src/views-data-ts/generate-views-data.ts +147 -0
- package/src/views-data-ts/generateViewId.ts +9 -0
- package/src/views-data-ts/index.ts +1 -0
- package/dist/__mocks__/data.d.ts +0 -5
- package/dist/__mocks__/data.d.ts.map +0 -1
- package/dist/__mocks__/data.js +0 -456
- package/dist/d2/generate-d2.d.ts.map +0 -1
- package/dist/d2/generate-d2.spec.d.ts +0 -2
- package/dist/d2/generate-d2.spec.d.ts.map +0 -1
- package/dist/d2/generate-d2.spec.js +0 -12
- package/dist/d2/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mmd/generate-mmd.d.ts.map +0 -1
- package/dist/mmd/generate-mmd.spec.d.ts +0 -2
- package/dist/mmd/generate-mmd.spec.d.ts.map +0 -1
- package/dist/mmd/generate-mmd.spec.js +0 -12
- package/dist/mmd/index.d.ts.map +0 -1
- package/dist/react/generate-react.d.ts +0 -3
- package/dist/react/generate-react.d.ts.map +0 -1
- package/dist/react/generate-react.js +0 -97
- package/dist/react/generate-react.spec.d.ts +0 -2
- package/dist/react/generate-react.spec.d.ts.map +0 -1
- package/dist/react/generate-react.spec.js +0 -6
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react-next/generate-react-next.d.ts.map +0 -1
- package/dist/react-next/generate-react-next.spec.d.ts +0 -2
- package/dist/react-next/generate-react-next.spec.d.ts.map +0 -1
- package/dist/react-next/generate-react-next.spec.js +0 -9
- package/dist/react-next/index.d.ts.map +0 -1
- package/dist/views-data-ts/generate-views-data.d.ts.map +0 -1
- package/dist/views-data-ts/generate-views-data.spec.d.ts +0 -2
- package/dist/views-data-ts/generate-views-data.spec.d.ts.map +0 -1
- package/dist/views-data-ts/generate-views-data.spec.js +0 -12
- package/dist/views-data-ts/generateViewId.d.ts.map +0 -1
- package/dist/views-data-ts/index.d.ts.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-2025 Denis Davydkov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/d2/generate-d2.d.ts
CHANGED
package/dist/d2/generate-d2.js
CHANGED
|
@@ -1,75 +1,82 @@
|
|
|
1
|
-
import { CompositeGeneratorNode, joinToNode, NL, toString } from
|
|
2
|
-
import { isNullish as isNil } from
|
|
1
|
+
import { CompositeGeneratorNode, joinToNode, NL, toString } from "langium/generate";
|
|
2
|
+
import { isNullish as isNil } from "remeda";
|
|
3
3
|
const capitalizeFirstLetter = (value) => value.charAt(0).toLocaleUpperCase() + value.slice(1);
|
|
4
|
-
const fqnName = (nodeId) => nodeId.split(
|
|
4
|
+
const fqnName = (nodeId) => nodeId.split(".").map(capitalizeFirstLetter).join("");
|
|
5
5
|
const nodeName = (node) => {
|
|
6
|
-
|
|
6
|
+
return fqnName(node.parent ? node.id.slice(node.parent.length + 1) : node.id);
|
|
7
7
|
};
|
|
8
8
|
const d2direction = ({ autoLayout }) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
9
|
+
switch (autoLayout.direction) {
|
|
10
|
+
case "TB": {
|
|
11
|
+
return "down";
|
|
12
|
+
}
|
|
13
|
+
case "BT": {
|
|
14
|
+
return "up";
|
|
15
|
+
}
|
|
16
|
+
case "LR": {
|
|
17
|
+
return "right";
|
|
18
|
+
}
|
|
19
|
+
case "RL": {
|
|
20
|
+
return "left";
|
|
22
21
|
}
|
|
22
|
+
}
|
|
23
23
|
};
|
|
24
24
|
const d2shape = ({ shape }) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
case 'mobile':
|
|
36
|
-
case 'browser': {
|
|
37
|
-
return 'rectangle';
|
|
38
|
-
}
|
|
25
|
+
switch (shape) {
|
|
26
|
+
case "queue":
|
|
27
|
+
case "cylinder":
|
|
28
|
+
case "rectangle":
|
|
29
|
+
case "person": {
|
|
30
|
+
return shape;
|
|
31
|
+
}
|
|
32
|
+
case "storage": {
|
|
33
|
+
return "stored_data";
|
|
39
34
|
}
|
|
35
|
+
case "mobile":
|
|
36
|
+
case "browser": {
|
|
37
|
+
return "rectangle";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
40
|
};
|
|
41
41
|
export function generateD2(view) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
42
|
+
const { nodes, edges } = view;
|
|
43
|
+
const names = /* @__PURE__ */ new Map();
|
|
44
|
+
const printNode = (node, parentName) => {
|
|
45
|
+
const name = nodeName(node);
|
|
46
|
+
const fqnName2 = (parentName ? parentName + "." : "") + name;
|
|
47
|
+
names.set(node.id, fqnName2);
|
|
48
|
+
const label = JSON.stringify(node.title);
|
|
49
|
+
const shape = d2shape(node);
|
|
50
|
+
return new CompositeGeneratorNode().append(name, ": {", NL).indent({
|
|
51
|
+
indentedChildren: (indent) => indent.append("label: ", label, NL).appendIf(shape !== "rectangle", "shape: ", shape, NL).appendIf(
|
|
52
|
+
node.children.length > 0,
|
|
53
|
+
NL,
|
|
54
|
+
joinToNode(
|
|
55
|
+
nodes.filter((n) => n.parent === node.id),
|
|
56
|
+
(n) => printNode(n, fqnName2)
|
|
57
|
+
)
|
|
58
|
+
),
|
|
59
|
+
indentation: 2
|
|
60
|
+
}).append("}", NL);
|
|
61
|
+
};
|
|
62
|
+
const printEdge = (edge) => {
|
|
63
|
+
return new CompositeGeneratorNode().append(names.get(edge.source), " -> ", names.get(edge.target)).append((out) => edge.label && out.append(": ", JSON.stringify(edge.label)));
|
|
64
|
+
};
|
|
65
|
+
return toString(
|
|
66
|
+
new CompositeGeneratorNode().append("direction: ", d2direction(view), NL, NL).append(
|
|
67
|
+
joinToNode(
|
|
68
|
+
nodes.filter((n) => isNil(n.parent)),
|
|
69
|
+
(n) => printNode(n),
|
|
70
|
+
{
|
|
71
|
+
appendNewLineIfNotEmpty: true
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
).appendIf(
|
|
75
|
+
edges.length > 0,
|
|
76
|
+
NL,
|
|
77
|
+
joinToNode(edges, (e) => printEdge(e), {
|
|
73
78
|
appendNewLineIfNotEmpty: true
|
|
74
|
-
|
|
79
|
+
})
|
|
80
|
+
)
|
|
81
|
+
);
|
|
75
82
|
}
|
package/dist/d2/index.d.ts
CHANGED
package/dist/d2/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./generate-d2.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { generateD2 } from './d2/generate-d2';
|
|
2
2
|
export { generateMermaid } from './mmd/generate-mmd';
|
|
3
|
+
export { generateLikeC4Model } from './model/generate-likec4-model';
|
|
3
4
|
export { generateReactNext } from './react-next/generate-react-next';
|
|
4
|
-
export {
|
|
5
|
+
export { generateReactTypes } from './react/generate-react-types';
|
|
5
6
|
export { generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs } from './views-data-ts/generate-views-data';
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { generateD2 } from
|
|
2
|
-
export { generateMermaid } from
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { generateD2 } from "./d2/generate-d2.js";
|
|
2
|
+
export { generateMermaid } from "./mmd/generate-mmd.js";
|
|
3
|
+
export { generateLikeC4Model } from "./model/generate-likec4-model.js";
|
|
4
|
+
export { generateReactNext } from "./react-next/generate-react-next.js";
|
|
5
|
+
export { generateReactTypes } from "./react/generate-react-types.js";
|
|
6
|
+
export { generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs } from "./views-data-ts/generate-views-data.js";
|
package/dist/mmd/generate-mmd.js
CHANGED
|
@@ -1,72 +1,91 @@
|
|
|
1
|
-
import { CompositeGeneratorNode,
|
|
2
|
-
import { isNullish as isNil } from
|
|
1
|
+
import { CompositeGeneratorNode, joinToNode, NL, toString } from "langium/generate";
|
|
2
|
+
import { isNullish as isNil } from "remeda";
|
|
3
3
|
const capitalizeFirstLetter = (value) => value.charAt(0).toLocaleUpperCase() + value.slice(1);
|
|
4
|
-
const fqnName = (nodeId) => nodeId.split(
|
|
4
|
+
const fqnName = (nodeId) => nodeId.split(".").map(capitalizeFirstLetter).join("");
|
|
5
5
|
const nodeName = (node) => {
|
|
6
|
-
|
|
6
|
+
return fqnName(node.parent ? node.id.slice(node.parent.length + 1) : node.id);
|
|
7
7
|
};
|
|
8
8
|
const mmdshape = ({ shape }) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
case 'storage':
|
|
17
|
-
return ['([', '])'];
|
|
18
|
-
case 'mobile':
|
|
19
|
-
case 'browser':
|
|
20
|
-
case 'rectangle': {
|
|
21
|
-
return ['[', ']'];
|
|
22
|
-
}
|
|
9
|
+
switch (shape) {
|
|
10
|
+
case "queue":
|
|
11
|
+
case "cylinder":
|
|
12
|
+
return ["[(", ")]"];
|
|
13
|
+
case "person": {
|
|
14
|
+
return ["[fa:fa-user ", "]"];
|
|
23
15
|
}
|
|
16
|
+
case "storage":
|
|
17
|
+
return ["([", "])"];
|
|
18
|
+
case "mobile":
|
|
19
|
+
case "browser":
|
|
20
|
+
case "rectangle": {
|
|
21
|
+
return ["[", "]"];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
24
|
};
|
|
25
25
|
export function generateMermaid(view) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.append('end', NL);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
baseNode.append(fqnName, shape[0], label, shape[1]);
|
|
50
|
-
}
|
|
51
|
-
return baseNode;
|
|
52
|
-
};
|
|
53
|
-
// return `${names.get(edge.source)} -> ${names.get(edge.target)}${edge.label ? ': ' + edge.label : ''}`
|
|
54
|
-
const printEdge = (edge) => {
|
|
55
|
-
return new CompositeGeneratorNode().append(names.get(edge.source), ' -.', edge.label ? ' "' + edge.label.replaceAll('\n', '\\n') + '" .-' : '-', '> ', names.get(edge.target));
|
|
56
|
-
};
|
|
57
|
-
return toString(new CompositeGeneratorNode()
|
|
58
|
-
.appendIf(view.title !== null && view.title.length > 0, '---', NL, `title: ${JSON.stringify(view.title)}`, NL, '---', NL)
|
|
59
|
-
.append('graph ', view.autoLayout, NL)
|
|
60
|
-
.indent({
|
|
61
|
-
indentedChildren: indent => {
|
|
62
|
-
indent
|
|
63
|
-
.append(joinToNode(nodes.filter(n => isNil(n.parent)), n => printNode(n), {
|
|
64
|
-
appendNewLineIfNotEmpty: true
|
|
65
|
-
}))
|
|
66
|
-
.appendIf(edges.length > 0, joinToNode(edges, e => printEdge(e), {
|
|
67
|
-
appendNewLineIfNotEmpty: true
|
|
68
|
-
}));
|
|
69
|
-
},
|
|
26
|
+
const { nodes, edges } = view;
|
|
27
|
+
const names = /* @__PURE__ */ new Map();
|
|
28
|
+
const printNode = (node, parentName) => {
|
|
29
|
+
const name = nodeName(node);
|
|
30
|
+
const fqnName2 = (parentName ? parentName + "." : "") + name;
|
|
31
|
+
names.set(node.id, fqnName2);
|
|
32
|
+
const label = node.title.replaceAll("\n", "\\n");
|
|
33
|
+
const shape = mmdshape(node);
|
|
34
|
+
const baseNode = new CompositeGeneratorNode();
|
|
35
|
+
if (node.children.length > 0) {
|
|
36
|
+
baseNode.append("subgraph ", fqnName2, "[", JSON.stringify(node.title), "]", NL).indent({
|
|
37
|
+
indentedChildren: [
|
|
38
|
+
joinToNode(
|
|
39
|
+
nodes.filter((n) => n.parent === node.id),
|
|
40
|
+
(n) => printNode(n, fqnName2),
|
|
41
|
+
{
|
|
42
|
+
appendNewLineIfNotEmpty: true
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
],
|
|
70
46
|
indentation: 2
|
|
71
|
-
|
|
47
|
+
}).append("end", NL);
|
|
48
|
+
} else {
|
|
49
|
+
baseNode.append(fqnName2, shape[0], label, shape[1]);
|
|
50
|
+
}
|
|
51
|
+
return baseNode;
|
|
52
|
+
};
|
|
53
|
+
const printEdge = (edge) => {
|
|
54
|
+
return new CompositeGeneratorNode().append(
|
|
55
|
+
names.get(edge.source),
|
|
56
|
+
" -.",
|
|
57
|
+
edge.label ? ' "' + edge.label.replaceAll("\n", "\\n") + '" .-' : "-",
|
|
58
|
+
"> ",
|
|
59
|
+
names.get(edge.target)
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
return toString(
|
|
63
|
+
new CompositeGeneratorNode().appendIf(
|
|
64
|
+
view.title !== null && view.title.length > 0,
|
|
65
|
+
"---",
|
|
66
|
+
NL,
|
|
67
|
+
`title: ${JSON.stringify(view.title)}`,
|
|
68
|
+
NL,
|
|
69
|
+
"---",
|
|
70
|
+
NL
|
|
71
|
+
).append("graph ", view.autoLayout.direction, NL).indent({
|
|
72
|
+
indentedChildren: (indent) => {
|
|
73
|
+
indent.append(
|
|
74
|
+
joinToNode(
|
|
75
|
+
nodes.filter((n) => isNil(n.parent)),
|
|
76
|
+
(n) => printNode(n),
|
|
77
|
+
{
|
|
78
|
+
appendNewLineIfNotEmpty: true
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
).appendIf(
|
|
82
|
+
edges.length > 0,
|
|
83
|
+
joinToNode(edges, (e) => printEdge(e), {
|
|
84
|
+
appendNewLineIfNotEmpty: true
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
},
|
|
88
|
+
indentation: 2
|
|
89
|
+
})
|
|
90
|
+
);
|
|
72
91
|
}
|
package/dist/mmd/index.d.ts
CHANGED
package/dist/mmd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./generate-mmd.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import JSON5 from "json5";
|
|
2
|
+
import { CompositeGeneratorNode, toString } from "langium/generate";
|
|
3
|
+
export function generateLikeC4Model(model) {
|
|
4
|
+
const out = new CompositeGeneratorNode();
|
|
5
|
+
out.appendTemplate`
|
|
6
|
+
/* prettier-ignore-start */
|
|
7
|
+
/* eslint-disable */
|
|
8
|
+
|
|
9
|
+
/******************************************************************************
|
|
10
|
+
* This file was generated
|
|
11
|
+
* DO NOT EDIT MANUALLY!
|
|
12
|
+
******************************************************************************/
|
|
13
|
+
|
|
14
|
+
import { LikeC4Model } from 'likec4/model'
|
|
15
|
+
|
|
16
|
+
export const likeC4Model = LikeC4Model.fromDump(${JSON5.stringify(model.$model, {
|
|
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']
|
|
25
|
+
|
|
26
|
+
/* prettier-ignore-end */
|
|
27
|
+
`;
|
|
28
|
+
return toString(out);
|
|
29
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { compareNatural, sortNaturalByFqn } from "@likec4/core";
|
|
2
|
+
function toUnion(unionset) {
|
|
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
|
+
}
|
|
12
|
+
export function generateReactTypes(model) {
|
|
13
|
+
const {
|
|
14
|
+
fqns,
|
|
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
|
+
});
|
|
39
|
+
return `
|
|
40
|
+
/* prettier-ignore-start */
|
|
41
|
+
/* eslint-disable */
|
|
42
|
+
|
|
43
|
+
/******************************************************************************
|
|
44
|
+
* This file was generated
|
|
45
|
+
* DO NOT EDIT MANUALLY!
|
|
46
|
+
******************************************************************************/
|
|
47
|
+
|
|
48
|
+
import type { PropsWithChildren } from 'react'
|
|
49
|
+
import type { JSX } from 'react/jsx-runtime'
|
|
50
|
+
import type {
|
|
51
|
+
DiagramView,
|
|
52
|
+
LikeC4Model as GenericLikeC4Model,
|
|
53
|
+
} from 'likec4/model'
|
|
54
|
+
import type {
|
|
55
|
+
LikeC4ViewProps as GenericLikeC4ViewProps,
|
|
56
|
+
ReactLikeC4Props as GenericReactLikeC4Props
|
|
57
|
+
} from 'likec4/react'
|
|
58
|
+
|
|
59
|
+
type LikeC4ElementId =
|
|
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;
|
|
75
|
+
|
|
76
|
+
type Aux = GenericLikeC4Model.Typed<LikeC4ElementId, LikeC4DeploymentId, LikeC4ViewId, DiagramView<LikeC4ViewId>>;
|
|
77
|
+
type LikeC4Model = GenericLikeC4Model<Aux>;
|
|
78
|
+
type LikeC4ViewModel = GenericLikeC4Model.View<Aux>;
|
|
79
|
+
|
|
80
|
+
declare const likeC4Model: LikeC4Model;
|
|
81
|
+
declare function useLikeC4Model(): LikeC4Model;
|
|
82
|
+
declare function useLikeC4View(viewId: LikeC4ViewId): DiagramView<LikeC4ViewId>;
|
|
83
|
+
|
|
84
|
+
declare function LikeC4ModelProvider(props: PropsWithChildren): JSX.Element;
|
|
85
|
+
|
|
86
|
+
type IconRendererProps = {
|
|
87
|
+
node: {
|
|
88
|
+
id: string
|
|
89
|
+
title: string
|
|
90
|
+
icon?: string | undefined
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
declare function RenderIcon(props: IconRendererProps): JSX.Element;
|
|
94
|
+
|
|
95
|
+
type LikeC4ViewProps = GenericLikeC4ViewProps<LikeC4ViewId, LikeC4Tag, LikeC4ElementKind>;
|
|
96
|
+
declare function LikeC4View({viewId, ...props}: LikeC4ViewProps): JSX.Element;
|
|
97
|
+
|
|
98
|
+
type ReactLikeC4Props = GenericReactLikeC4Props<LikeC4ViewId, LikeC4Tag, LikeC4ElementKind>
|
|
99
|
+
declare function ReactLikeC4({viewId, ...props}: ReactLikeC4Props): JSX.Element;
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
type LikeC4ElementId,
|
|
103
|
+
type LikeC4DeploymentId,
|
|
104
|
+
type LikeC4ViewId,
|
|
105
|
+
type LikeC4Tag,
|
|
106
|
+
type LikeC4ElementKind,
|
|
107
|
+
type LikeC4ViewProps,
|
|
108
|
+
type ReactLikeC4Props,
|
|
109
|
+
type LikeC4Model,
|
|
110
|
+
isLikeC4ViewId,
|
|
111
|
+
useLikeC4Model,
|
|
112
|
+
useLikeC4View,
|
|
113
|
+
useLikeC4ViewModel,
|
|
114
|
+
likeC4Model,
|
|
115
|
+
LikeC4ModelProvider,
|
|
116
|
+
LikeC4View,
|
|
117
|
+
RenderIcon,
|
|
118
|
+
ReactLikeC4
|
|
119
|
+
}
|
|
120
|
+
/* prettier-ignore-end */
|
|
121
|
+
`.trimStart();
|
|
122
|
+
}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export { generateReactTypes as default } from './generate-react-types';
|
package/dist/react/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { generateReactTypes as default } from "./generate-react-types.js";
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import type { DiagramView } from '@likec4/core';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated in favor packages/likec4/src/cli/codegen/react/index.ts
|
|
4
|
+
*/
|
|
2
5
|
export declare function generateReactNext(views: Iterable<DiagramView>): {
|
|
3
6
|
viewsData: {
|
|
4
7
|
fileName: string;
|
|
5
|
-
js:
|
|
6
|
-
dts:
|
|
8
|
+
js: any;
|
|
9
|
+
dts: any;
|
|
7
10
|
};
|
|
8
11
|
components: {
|
|
9
|
-
js:
|
|
10
|
-
dts:
|
|
12
|
+
js: any;
|
|
13
|
+
dts: any;
|
|
11
14
|
fileName: string;
|
|
12
15
|
};
|
|
13
16
|
index: {
|
|
14
|
-
js:
|
|
15
|
-
dts:
|
|
17
|
+
js: any;
|
|
18
|
+
dts: any;
|
|
16
19
|
};
|
|
17
20
|
};
|
|
18
|
-
//# sourceMappingURL=generate-react-next.d.ts.map
|