@likec4/generators 0.37.1 → 0.40.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 +2 -3
- 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 +1 -2
- package/dist/index.js +4 -4
- package/dist/mmd/generate-mmd.d.ts +2 -3
- package/dist/mmd/generate-mmd.js +76 -52
- package/dist/mmd/index.d.ts +0 -1
- package/dist/mmd/index.js +1 -1
- package/dist/react/generate-react.d.ts +2 -4
- package/dist/react/generate-react.js +38 -34
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +1 -1
- package/dist/views-data-ts/generate-views-data.d.ts +2 -2
- package/dist/views-data-ts/generate-views-data.js +64 -22
- package/dist/views-data-ts/index.d.ts +0 -1
- package/dist/views-data-ts/index.js +1 -1
- package/package.json +14 -12
package/dist/d2/generate-d2.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { ComputedView } from '@likec4/core
|
|
2
|
-
export declare function generateD2<V extends ComputedView>(view: V):
|
|
3
|
-
//# sourceMappingURL=generate-d2.d.ts.map
|
|
1
|
+
import type { ComputedView } from '@likec4/core';
|
|
2
|
+
export declare function generateD2<V extends ComputedView>(view: V): any;
|
package/dist/d2/generate-d2.js
CHANGED
|
@@ -1,75 +1,82 @@
|
|
|
1
|
-
import { CompositeGeneratorNode, NL, joinToNode, toString } from
|
|
2
|
-
import { isNil } from
|
|
1
|
+
import { CompositeGeneratorNode, NL, joinToNode, toString } from "langium";
|
|
2
|
+
import { isNil } from "rambdax";
|
|
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) {
|
|
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 = node.title.replaceAll("\n", "\\n");
|
|
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(": ", edge.label.replaceAll("\n", "\\n")));
|
|
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,5 +1,4 @@
|
|
|
1
1
|
export { generateReact } from './react/generate-react';
|
|
2
2
|
export { generateD2 } from './d2/generate-d2';
|
|
3
3
|
export { generateMermaid } from './mmd/generate-mmd';
|
|
4
|
-
export { generateViewsDataTs } from './views-data-ts/generate-views-data';
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
4
|
+
export { generateViewsDataTs, generateViewsDataJs } from './views-data-ts/generate-views-data';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { generateReact } from
|
|
2
|
-
export { generateD2 } from
|
|
3
|
-
export { generateMermaid } from
|
|
4
|
-
export { generateViewsDataTs } from
|
|
1
|
+
export { generateReact } from "./react/generate-react.js";
|
|
2
|
+
export { generateD2 } from "./d2/generate-d2.js";
|
|
3
|
+
export { generateMermaid } from "./mmd/generate-mmd.js";
|
|
4
|
+
export { generateViewsDataTs, generateViewsDataJs } from "./views-data-ts/generate-views-data.js";
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { ComputedView } from '@likec4/core
|
|
2
|
-
export declare function generateMermaid<V extends ComputedView>(view: V):
|
|
3
|
-
//# sourceMappingURL=generate-mmd.d.ts.map
|
|
1
|
+
import type { ComputedView } from '@likec4/core';
|
|
2
|
+
export declare function generateMermaid<V extends ComputedView>(view: V): any;
|
package/dist/mmd/generate-mmd.js
CHANGED
|
@@ -1,62 +1,86 @@
|
|
|
1
|
-
import { CompositeGeneratorNode, NL, joinToNode, toString } from
|
|
2
|
-
import { isNil } from
|
|
1
|
+
import { CompositeGeneratorNode, NL, joinToNode, toString } from "langium";
|
|
2
|
+
import { isNil } from "rambdax";
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
9
|
+
switch (shape) {
|
|
10
|
+
case "queue":
|
|
11
|
+
case "cylinder":
|
|
12
|
+
return ["[(", ")]"];
|
|
13
|
+
case "person": {
|
|
14
|
+
return ["[fa:fa-user ", "]"];
|
|
15
|
+
}
|
|
16
|
+
case "storage":
|
|
17
|
+
return ["([", "])"];
|
|
18
|
+
case "mobile":
|
|
19
|
+
case "browser":
|
|
20
|
+
case "rectangle": {
|
|
21
|
+
return ["[", "]"];
|
|
23
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
|
-
|
|
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, '["', label, '"]', NL).indent({
|
|
37
|
+
indentedChildren: (indent) => indent.appendIf(
|
|
38
|
+
node.children.length > 0,
|
|
39
|
+
NL,
|
|
40
|
+
joinToNode(
|
|
41
|
+
nodes.filter((n) => n.parent === node.id),
|
|
42
|
+
(n) => printNode(n, fqnName2)
|
|
43
|
+
)
|
|
44
|
+
),
|
|
45
|
+
indentation: 2
|
|
46
|
+
}).append("end", NL);
|
|
47
|
+
} else {
|
|
48
|
+
baseNode.append(fqnName2, shape[0], label, shape[1], NL);
|
|
49
|
+
}
|
|
50
|
+
return baseNode;
|
|
51
|
+
};
|
|
52
|
+
const printEdge = (edge) => {
|
|
53
|
+
return new CompositeGeneratorNode().append(
|
|
54
|
+
names.get(edge.source),
|
|
55
|
+
" --",
|
|
56
|
+
edge.label ? '"' + edge.label.replaceAll("\n", "\\n") + '"--' : "",
|
|
57
|
+
"> ",
|
|
58
|
+
names.get(edge.target)
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
return toString(
|
|
62
|
+
new CompositeGeneratorNode().appendIf(
|
|
63
|
+
view.title !== null && view.title.length > 0,
|
|
64
|
+
"---",
|
|
65
|
+
NL,
|
|
66
|
+
`title: ${view.title}`,
|
|
67
|
+
NL,
|
|
68
|
+
"---",
|
|
69
|
+
NL
|
|
70
|
+
).append("graph ", view.autoLayout, NL, NL).append(
|
|
71
|
+
joinToNode(
|
|
72
|
+
nodes.filter((n) => isNil(n.parent)),
|
|
73
|
+
(n) => printNode(n),
|
|
74
|
+
{
|
|
75
|
+
appendNewLineIfNotEmpty: true
|
|
46
76
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
return toString(new CompositeGeneratorNode()
|
|
54
|
-
.appendIf(view.title !== null && view.title.length > 0, '---', NL, `title: ${view.title}`, NL, '---', NL)
|
|
55
|
-
.append('graph ', view.autoLayout, NL, NL)
|
|
56
|
-
.append(joinToNode(nodes.filter(n => isNil(n.parent)), n => printNode(n), {
|
|
57
|
-
appendNewLineIfNotEmpty: true
|
|
58
|
-
}))
|
|
59
|
-
.appendIf(edges.length > 0, NL, joinToNode(edges, e => printEdge(e), {
|
|
77
|
+
)
|
|
78
|
+
).appendIf(
|
|
79
|
+
edges.length > 0,
|
|
80
|
+
NL,
|
|
81
|
+
joinToNode(edges, (e) => printEdge(e), {
|
|
60
82
|
appendNewLineIfNotEmpty: true
|
|
61
|
-
|
|
83
|
+
})
|
|
84
|
+
)
|
|
85
|
+
);
|
|
62
86
|
}
|
package/dist/mmd/index.d.ts
CHANGED
package/dist/mmd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./generate-mmd.js";
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { DiagramView } from '@likec4/core';
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
export declare function generateReact(views: DiagramView[]): string;
|
|
5
|
-
//# sourceMappingURL=generate-react.d.ts.map
|
|
2
|
+
export declare const generateViewId: (views: DiagramView[]) => any;
|
|
3
|
+
export declare function generateReact(views: DiagramView[]): any;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import JSON5 from
|
|
2
|
-
import { CompositeGeneratorNode, NL, expandToNode, joinToNode, toString } from
|
|
1
|
+
import JSON5 from "json5";
|
|
2
|
+
import { CompositeGeneratorNode, NL, expandToNode, joinToNode, toString } from "langium";
|
|
3
3
|
const componentName = (value) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
if (!value.charAt(0).match(/[a-zA-Z]/)) {
|
|
5
|
+
value = "View" + value;
|
|
6
|
+
}
|
|
7
|
+
value = value.replaceAll("_", "");
|
|
8
|
+
return value.charAt(0).toLocaleUpperCase() + value.slice(1);
|
|
9
9
|
};
|
|
10
|
-
export const generateViewId = (views) => joinToNode(views, view => expandToNode
|
|
11
|
-
|
|
10
|
+
export const generateViewId = (views) => joinToNode(views, (view) => expandToNode`'${view.id}'`, {
|
|
11
|
+
separator: " | "
|
|
12
12
|
});
|
|
13
13
|
export function generateReact(views) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const components = views.map(({ id }) => {
|
|
15
|
+
return {
|
|
16
|
+
id,
|
|
17
|
+
name: componentName(id)
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
const out = new CompositeGeneratorNode();
|
|
21
|
+
out.appendTemplate`
|
|
22
22
|
/******************************************************************************
|
|
23
23
|
* This file was generated
|
|
24
24
|
* DO NOT EDIT MANUALLY!
|
|
@@ -28,25 +28,29 @@ export function generateReact(views) {
|
|
|
28
28
|
import type { DiagramView } from '@likec4/diagrams'
|
|
29
29
|
import { LikeC4 } from '@likec4/diagrams'
|
|
30
30
|
`.append(NL, NL);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
if (components.length == 0) {
|
|
32
|
+
out.append("export {}", NL);
|
|
33
|
+
return toString(out);
|
|
34
|
+
}
|
|
35
|
+
out.appendTemplate`
|
|
36
36
|
|
|
37
37
|
export type LikeC4ViewId = ${generateViewId(views)};
|
|
38
38
|
export const LikeC4Views = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
`.indent({
|
|
40
|
+
indentation: 2,
|
|
41
|
+
indentedChildren(indented) {
|
|
42
|
+
indented.appendNewLineIf(views.length > 1).append(
|
|
43
|
+
joinToNode(
|
|
44
|
+
views,
|
|
45
|
+
(view) => expandToNode`${JSON5.stringify(view.id)}: (${JSON5.stringify(view)} as unknown) as DiagramView`,
|
|
46
|
+
{
|
|
47
|
+
separator: ",",
|
|
48
|
+
appendNewLineIfNotEmpty: true
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}).append("} as const satisfies Record<LikeC4ViewId, DiagramView>", NL, NL).appendTemplate`
|
|
50
54
|
export type LikeC4Views = typeof LikeC4Views
|
|
51
55
|
|
|
52
56
|
export const {
|
|
@@ -83,5 +87,5 @@ export function generateReact(views) {
|
|
|
83
87
|
DiagramView
|
|
84
88
|
} from '@likec4/diagrams'
|
|
85
89
|
`.append(NL, NL);
|
|
86
|
-
|
|
90
|
+
return toString(out);
|
|
87
91
|
}
|
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./generate-react.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DiagramView } from '@likec4/core';
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
2
|
+
export declare function generateViewsDataJs(views: DiagramView[]): any;
|
|
3
|
+
export declare function generateViewsDataTs(views: DiagramView[]): any;
|
|
@@ -1,9 +1,47 @@
|
|
|
1
|
-
import JSON5 from
|
|
2
|
-
import { CompositeGeneratorNode, NL, expandToNode, joinToNode, toString } from
|
|
3
|
-
import { generateViewId } from
|
|
1
|
+
import JSON5 from "json5";
|
|
2
|
+
import { CompositeGeneratorNode, NL, expandToNode, joinToNode, toString } from "langium";
|
|
3
|
+
import { generateViewId } from "../react/generate-react.js";
|
|
4
|
+
export function generateViewsDataJs(views) {
|
|
5
|
+
const out = new CompositeGeneratorNode();
|
|
6
|
+
out.appendTemplate`
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
* This file was generated
|
|
9
|
+
* DO NOT EDIT MANUALLY!
|
|
10
|
+
******************************************************************************/
|
|
11
|
+
/* eslint-disable */
|
|
12
|
+
|
|
13
|
+
`.append(NL, NL);
|
|
14
|
+
if (views.length == 0) {
|
|
15
|
+
out.append("export const LikeC4Views = {}", NL);
|
|
16
|
+
return toString(out);
|
|
17
|
+
}
|
|
18
|
+
out.appendTemplate`
|
|
19
|
+
export const LikeC4Views = {
|
|
20
|
+
`.indent({
|
|
21
|
+
indentation: 2,
|
|
22
|
+
indentedChildren(indented) {
|
|
23
|
+
indented.appendNewLineIf(views.length > 1).append(
|
|
24
|
+
joinToNode(views, (view) => expandToNode`${JSON5.stringify(view.id)}: ${JSON5.stringify(view)}`, {
|
|
25
|
+
separator: ",",
|
|
26
|
+
appendNewLineIfNotEmpty: true
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}).append("}", NL, NL).appendTemplate`
|
|
31
|
+
|
|
32
|
+
export function isLikeC4ViewId(value) {
|
|
33
|
+
return (
|
|
34
|
+
value != null &&
|
|
35
|
+
typeof value === 'string' &&
|
|
36
|
+
Object.prototype.hasOwnProperty.call(LikeC4Views, value)
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
`.append(NL, NL);
|
|
40
|
+
return toString(out);
|
|
41
|
+
}
|
|
4
42
|
export function generateViewsDataTs(views) {
|
|
5
|
-
|
|
6
|
-
|
|
43
|
+
const out = new CompositeGeneratorNode();
|
|
44
|
+
out.appendTemplate`
|
|
7
45
|
/******************************************************************************
|
|
8
46
|
* This file was generated
|
|
9
47
|
* DO NOT EDIT MANUALLY!
|
|
@@ -12,24 +50,28 @@ export function generateViewsDataTs(views) {
|
|
|
12
50
|
|
|
13
51
|
import type { DiagramView } from '@likec4/core'
|
|
14
52
|
`.append(NL, NL);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
53
|
+
if (views.length == 0) {
|
|
54
|
+
out.append("export {}", NL);
|
|
55
|
+
return toString(out);
|
|
56
|
+
}
|
|
57
|
+
out.appendTemplate`
|
|
20
58
|
export type LikeC4ViewId = ${generateViewId(views)};
|
|
21
59
|
export const LikeC4Views = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
60
|
+
`.indent({
|
|
61
|
+
indentation: 2,
|
|
62
|
+
indentedChildren(indented) {
|
|
63
|
+
indented.appendNewLineIf(views.length > 1).append(
|
|
64
|
+
joinToNode(
|
|
65
|
+
views,
|
|
66
|
+
(view) => expandToNode`${JSON5.stringify(view.id)}: (${JSON5.stringify(view)} as unknown) as DiagramView`,
|
|
67
|
+
{
|
|
68
|
+
separator: ",",
|
|
69
|
+
appendNewLineIfNotEmpty: true
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}).append("} as const satisfies Record<LikeC4ViewId, DiagramView>", NL, NL).appendTemplate`
|
|
33
75
|
export type LikeC4Views = typeof LikeC4Views
|
|
34
76
|
|
|
35
77
|
export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
|
|
@@ -57,5 +99,5 @@ export function generateViewsDataTs(views) {
|
|
|
57
99
|
DiagramLabel
|
|
58
100
|
} from '@likec4/core'
|
|
59
101
|
`.append(NL, NL);
|
|
60
|
-
|
|
102
|
+
return toString(out);
|
|
61
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./generate-views-data.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/generators",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
@@ -16,21 +16,22 @@
|
|
|
16
16
|
"url": "https://github.com/likec4/likec4.git",
|
|
17
17
|
"directory": "packages/generators"
|
|
18
18
|
},
|
|
19
|
-
"main": "./dist/index.js",
|
|
20
|
-
"module": "./dist/index.js",
|
|
21
|
-
"types": "./dist/index.d.ts",
|
|
22
19
|
"type": "module",
|
|
23
20
|
"sideEffects": false,
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
24
27
|
"publishConfig": {
|
|
25
28
|
"registry": "https://registry.npmjs.org",
|
|
26
|
-
"access": "public"
|
|
27
|
-
"main": "./dist/index.js",
|
|
28
|
-
"module": "./dist/index.js",
|
|
29
|
-
"types": "./dist/index.d.ts"
|
|
29
|
+
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"
|
|
33
|
-
"build": "tsc",
|
|
32
|
+
"typecheck": "tsc --emitDeclarationOnly",
|
|
33
|
+
"build:watch": "tsc --watch",
|
|
34
|
+
"build": "unbuild",
|
|
34
35
|
"dev": "tsc --watch",
|
|
35
36
|
"lint": "run -T eslint src/ --fix",
|
|
36
37
|
"clean": "run -T rimraf dist",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"test:watch": "run -T vitest"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@likec4/core": "0.
|
|
42
|
+
"@likec4/core": "0.40.0",
|
|
42
43
|
"json5": "^2.2.3",
|
|
43
44
|
"langium": "^2.0.2",
|
|
44
45
|
"rambdax": "^9.1.1"
|
|
@@ -46,7 +47,8 @@
|
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@types/node": "^18.15.11",
|
|
48
49
|
"typescript": "^5.2.2",
|
|
49
|
-
"
|
|
50
|
+
"unbuild": "^2.0.0",
|
|
51
|
+
"vitest": "^0.34.6"
|
|
50
52
|
},
|
|
51
53
|
"packageManager": "yarn@3.6.3"
|
|
52
54
|
}
|