@likec4/generators 0.32.0 → 0.33.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.
|
@@ -7,6 +7,9 @@ const componentName = (value) => {
|
|
|
7
7
|
value = value.replaceAll('_', '');
|
|
8
8
|
return value.charAt(0).toLocaleUpperCase() + value.slice(1);
|
|
9
9
|
};
|
|
10
|
+
const generateViewId = (views) => joinToNode(views, view => expandToNode `'${view.id}'`, {
|
|
11
|
+
separator: ' | '
|
|
12
|
+
});
|
|
10
13
|
export function generateReact(views) {
|
|
11
14
|
const components = views.map(({ id }) => {
|
|
12
15
|
return {
|
|
@@ -22,15 +25,18 @@ export function generateReact(views) {
|
|
|
22
25
|
******************************************************************************/
|
|
23
26
|
/* eslint-disable */
|
|
24
27
|
|
|
25
|
-
import type { DiagramView
|
|
26
|
-
import {
|
|
28
|
+
import type { DiagramView } from '@likec4/core'
|
|
29
|
+
import { LikeC4 } from '@likec4/diagrams'
|
|
27
30
|
`.append(NL, NL);
|
|
28
31
|
if (components.length == 0) {
|
|
29
32
|
out.append('export {}', NL);
|
|
30
33
|
return toString(out);
|
|
31
34
|
}
|
|
32
|
-
out
|
|
33
|
-
|
|
35
|
+
out.appendTemplate `
|
|
36
|
+
|
|
37
|
+
export type LikeC4ViewId = ${generateViewId(views)};
|
|
38
|
+
export const LikeC4Views = {
|
|
39
|
+
`
|
|
34
40
|
.indent({
|
|
35
41
|
indentation: 2,
|
|
36
42
|
indentedChildren: indent => {
|
|
@@ -40,39 +46,42 @@ export function generateReact(views) {
|
|
|
40
46
|
}));
|
|
41
47
|
}
|
|
42
48
|
})
|
|
43
|
-
.append('}
|
|
44
|
-
export type
|
|
45
|
-
export type LikeC4ViewId = keyof LikeC4ViewsData
|
|
46
|
-
export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
|
|
47
|
-
return typeof value === 'string' && value in LikeC4ViewsData
|
|
48
|
-
}
|
|
49
|
+
.append('} as const satisfies Record<LikeC4ViewId, DiagramView>', NL, NL).appendTemplate `
|
|
50
|
+
export type LikeC4Views = typeof LikeC4Views
|
|
49
51
|
|
|
50
|
-
export
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
export const {
|
|
53
|
+
isViewId,
|
|
54
|
+
Diagram,
|
|
55
|
+
Responsive,
|
|
56
|
+
Embedded,
|
|
57
|
+
Browser
|
|
58
|
+
} = LikeC4.create(LikeC4Views)
|
|
54
59
|
|
|
55
|
-
type
|
|
56
|
-
export
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
60
|
+
export type DiagramProps = LikeC4.Props<LikeC4ViewId>
|
|
61
|
+
export type ResponsiveProps = LikeC4.ResponsiveProps<LikeC4ViewId>
|
|
62
|
+
export type EmbeddedProps = LikeC4.EmbeddedProps<LikeC4ViewId>
|
|
63
|
+
export type BrowserProps = LikeC4.BrowserProps<LikeC4ViewId>
|
|
64
|
+
|
|
65
|
+
`.append(NL, NL).appendTemplate `
|
|
66
|
+
export type {
|
|
67
|
+
DiagramApi
|
|
68
|
+
} from '@likec4/diagrams'
|
|
69
|
+
|
|
70
|
+
export type {
|
|
71
|
+
Fqn,
|
|
72
|
+
Element,
|
|
73
|
+
RelationID,
|
|
74
|
+
Relation,
|
|
75
|
+
NodeId,
|
|
76
|
+
EdgeId,
|
|
77
|
+
ComputedNode,
|
|
78
|
+
ComputedEdge,
|
|
79
|
+
ComputedView,
|
|
80
|
+
DiagramView,
|
|
81
|
+
DiagramNode,
|
|
82
|
+
DiagramEdge,
|
|
83
|
+
DiagramLabel
|
|
84
|
+
} from '@likec4/core'
|
|
85
|
+
`.append(NL, NL);
|
|
77
86
|
return toString(out);
|
|
78
87
|
}
|
|
@@ -9,10 +9,10 @@ export function generateViewsDataTs(views) {
|
|
|
9
9
|
******************************************************************************/
|
|
10
10
|
/* eslint-disable */
|
|
11
11
|
|
|
12
|
-
import type { DiagramView } from '@likec4/
|
|
12
|
+
import type { DiagramView } from '@likec4/core'
|
|
13
13
|
`.append(NL, NL);
|
|
14
14
|
out
|
|
15
|
-
.append('export const
|
|
15
|
+
.append('export const LikeC4Views = {', NL)
|
|
16
16
|
.indent({
|
|
17
17
|
indentation: 2,
|
|
18
18
|
indentedChildren: indent => {
|
|
@@ -23,11 +23,32 @@ export function generateViewsDataTs(views) {
|
|
|
23
23
|
}
|
|
24
24
|
})
|
|
25
25
|
.append('} as const', NL, NL).appendTemplate `
|
|
26
|
-
export type
|
|
27
|
-
export type LikeC4ViewId = keyof
|
|
26
|
+
export type LikeC4Views = typeof LikeC4Views
|
|
27
|
+
export type LikeC4ViewId = keyof LikeC4Views
|
|
28
|
+
|
|
28
29
|
export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
|
|
29
|
-
return
|
|
30
|
+
return (
|
|
31
|
+
value != null &&
|
|
32
|
+
typeof value === 'string' &&
|
|
33
|
+
Object.prototype.hasOwnProperty.call(LikeC4Views, value)
|
|
34
|
+
)
|
|
30
35
|
}
|
|
31
|
-
`.append(NL)
|
|
36
|
+
`.append(NL, NL).appendTemplate `
|
|
37
|
+
export type {
|
|
38
|
+
Fqn,
|
|
39
|
+
Element,
|
|
40
|
+
RelationID,
|
|
41
|
+
Relation,
|
|
42
|
+
NodeId,
|
|
43
|
+
EdgeId,
|
|
44
|
+
ComputedNode,
|
|
45
|
+
ComputedEdge,
|
|
46
|
+
ComputedView,
|
|
47
|
+
DiagramView,
|
|
48
|
+
DiagramNode,
|
|
49
|
+
DiagramEdge,
|
|
50
|
+
DiagramLabel
|
|
51
|
+
} from '@likec4/core'
|
|
52
|
+
`.append(NL, NL);
|
|
32
53
|
return toString(out);
|
|
33
54
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/generators",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test:watch": "run -T vitest"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@likec4/core": "0.
|
|
41
|
+
"@likec4/core": "0.33.1",
|
|
42
42
|
"json5": "^2.2.3",
|
|
43
43
|
"langium": "^1.2.1",
|
|
44
44
|
"rambdax": "^9.1.1"
|