@likec4/generators 1.46.4 → 1.48.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/LICENSE +1 -1
- package/dist/index.d.mts +59 -0
- package/dist/index.mjs +589 -0
- package/package.json +19 -16
- package/src/d2/generate-d2.ts +5 -1
- package/src/mmd/generate-mmd.ts +33 -18
- package/src/puml/generate-puml.ts +41 -16
- package/src/puml/index.ts +1 -1
- package/src/react/generate-react-types.ts +2 -2
- package/dist/d2/generate-d2.d.ts +0 -3
- package/dist/d2/generate-d2.js +0 -83
- package/dist/d2/index.d.ts +0 -1
- package/dist/d2/index.js +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -7
- package/dist/mmd/generate-mmd.d.ts +0 -3
- package/dist/mmd/generate-mmd.js +0 -92
- package/dist/mmd/index.d.ts +0 -1
- package/dist/mmd/index.js +0 -1
- package/dist/model/generate-aux.d.ts +0 -4
- package/dist/model/generate-aux.js +0 -67
- package/dist/model/generate-likec4-model.d.ts +0 -4
- package/dist/model/generate-likec4-model.js +0 -22
- package/dist/model/generate-likec4.d.ts +0 -2
- package/dist/model/generate-likec4.js +0 -2
- package/dist/puml/generate-puml.d.ts +0 -3
- package/dist/puml/generate-puml.js +0 -148
- package/dist/puml/index.d.ts +0 -1
- package/dist/puml/index.js +0 -1
- package/dist/react/generate-react-types.d.ts +0 -4
- package/dist/react/generate-react-types.js +0 -64
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +0 -1
- package/dist/react-next/generate-react-next.d.ts +0 -20
- package/dist/react-next/generate-react-next.js +0 -102
- package/dist/react-next/index.d.ts +0 -1
- package/dist/react-next/index.js +0 -1
- package/dist/views-data-ts/generate-views-data.d.ts +0 -13
- package/dist/views-data-ts/generate-views-data.js +0 -130
- package/dist/views-data-ts/generateViewId.d.ts +0 -2
- package/dist/views-data-ts/generateViewId.js +0 -7
- package/dist/views-data-ts/index.d.ts +0 -1
- package/dist/views-data-ts/index.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/generators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
|
11
11
|
"src",
|
|
12
|
-
"
|
|
13
|
-
"!**/
|
|
14
|
-
"
|
|
12
|
+
"**/package.json",
|
|
13
|
+
"!**/__*/**",
|
|
14
|
+
"!**/*.spec.*",
|
|
15
|
+
"!**/*.snap",
|
|
15
16
|
"!**/*.map"
|
|
16
17
|
],
|
|
17
18
|
"repository": {
|
|
@@ -25,9 +26,9 @@
|
|
|
25
26
|
".": {
|
|
26
27
|
"sources": "./src/index.ts",
|
|
27
28
|
"default": {
|
|
28
|
-
"types": "./dist/index.d.
|
|
29
|
-
"import": "./dist/index.
|
|
30
|
-
"default": "./dist/index.
|
|
29
|
+
"types": "./dist/index.d.mts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"default": "./dist/index.mjs"
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
},
|
|
@@ -36,27 +37,29 @@
|
|
|
36
37
|
"access": "public"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
40
|
+
"remeda": "^2.32.0",
|
|
39
41
|
"json5": "^2.2.3",
|
|
40
42
|
"langium": "3.5.0",
|
|
41
|
-
"
|
|
42
|
-
"@likec4/
|
|
43
|
+
"@likec4/core": "1.48.0",
|
|
44
|
+
"@likec4/log": "1.48.0"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
|
-
"@types/node": "~22.19.
|
|
47
|
+
"@types/node": "~22.19.7",
|
|
46
48
|
"typescript": "5.9.3",
|
|
47
|
-
"
|
|
48
|
-
"vitest": "4.0.
|
|
49
|
-
"@likec4/tsconfig": "1.
|
|
49
|
+
"obuild": "^0.4.20",
|
|
50
|
+
"vitest": "4.0.18",
|
|
51
|
+
"@likec4/tsconfig": "1.48.0",
|
|
50
52
|
"@likec4/devops": "1.42.0"
|
|
51
53
|
},
|
|
52
54
|
"scripts": {
|
|
53
55
|
"typecheck": "tsc -b --verbose",
|
|
54
|
-
"build": "
|
|
56
|
+
"build": "obuild",
|
|
55
57
|
"lint": "run -T eslint src/ --fix",
|
|
56
58
|
"clean": "likec4ops clean",
|
|
59
|
+
"pack": "pnpm pack",
|
|
57
60
|
"test": "vitest run --no-isolate",
|
|
58
61
|
"test:watch": "vitest"
|
|
59
62
|
},
|
|
60
|
-
"types": "dist/index.d.
|
|
61
|
-
"module": "dist/index.
|
|
63
|
+
"types": "dist/index.d.mts",
|
|
64
|
+
"module": "dist/index.mjs"
|
|
62
65
|
}
|
package/src/d2/generate-d2.ts
CHANGED
|
@@ -36,12 +36,16 @@ const d2shape = ({ shape }: Node) => {
|
|
|
36
36
|
case 'queue':
|
|
37
37
|
case 'cylinder':
|
|
38
38
|
case 'rectangle':
|
|
39
|
-
case '
|
|
39
|
+
case 'document': {
|
|
40
40
|
return shape
|
|
41
41
|
}
|
|
42
|
+
case 'person': {
|
|
43
|
+
return 'c4-person' as const
|
|
44
|
+
}
|
|
42
45
|
case 'storage': {
|
|
43
46
|
return 'stored_data' as const
|
|
44
47
|
}
|
|
48
|
+
case 'bucket':
|
|
45
49
|
case 'mobile':
|
|
46
50
|
case 'browser': {
|
|
47
51
|
return 'rectangle' as const
|
package/src/mmd/generate-mmd.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nonexhaustive } from '@likec4/core'
|
|
1
2
|
import type { LikeC4ViewModel } from '@likec4/core/model'
|
|
2
3
|
import type { aux, NodeId, ProcessedView as AnyView } from '@likec4/core/types'
|
|
3
4
|
import { CompositeGeneratorNode, joinToNode, NL, toString } from 'langium/generate'
|
|
@@ -14,21 +15,38 @@ const nodeName = (node: Node): string => {
|
|
|
14
15
|
return fqnName(node.parent ? node.id.slice(node.parent.length + 1) : node.id)
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
+
const toSingleQuotes = (str: string): string => str.replace(/\\?"/g, `'`)
|
|
19
|
+
|
|
20
|
+
const mmdshape = ({ shape, title }: Node): string => {
|
|
21
|
+
const label = `label: ${JSON.stringify(title)}`
|
|
18
22
|
switch (shape) {
|
|
19
|
-
case 'queue':
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
case 'queue': {
|
|
24
|
+
return `@{ shape: horizontal-cylinder, ${label} }`
|
|
25
|
+
}
|
|
22
26
|
case 'person': {
|
|
23
|
-
return
|
|
27
|
+
return `@{ icon: "fa:user", shape: rounded, ${label} }`
|
|
28
|
+
}
|
|
29
|
+
case 'storage': {
|
|
30
|
+
return `@{ shape: disk, ${label} }`
|
|
31
|
+
}
|
|
32
|
+
case 'cylinder': {
|
|
33
|
+
return `@{ shape: cylinder, ${label} }`
|
|
24
34
|
}
|
|
25
|
-
case 'storage':
|
|
26
|
-
return ['([', '])']
|
|
27
35
|
case 'mobile':
|
|
28
|
-
case 'browser':
|
|
36
|
+
case 'browser': {
|
|
37
|
+
return `@{ shape: rounded, ${label} }`
|
|
38
|
+
}
|
|
39
|
+
case 'bucket': {
|
|
40
|
+
return `@{ shape: trap-t, ${label} }`
|
|
41
|
+
}
|
|
29
42
|
case 'rectangle': {
|
|
30
|
-
return
|
|
43
|
+
return `@{ shape: rectangle, ${label} }`
|
|
31
44
|
}
|
|
45
|
+
case 'document': {
|
|
46
|
+
return `@{ shape: doc, ${label} }`
|
|
47
|
+
}
|
|
48
|
+
default:
|
|
49
|
+
nonexhaustive(shape)
|
|
32
50
|
}
|
|
33
51
|
}
|
|
34
52
|
|
|
@@ -42,13 +60,11 @@ export function generateMermaid(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
|
42
60
|
const fqnName = (parentName ? parentName + '.' : '') + name
|
|
43
61
|
names.set(node.id, fqnName)
|
|
44
62
|
|
|
45
|
-
const label = node.title.replaceAll('\n', '\\n')
|
|
46
|
-
const shape = mmdshape(node)
|
|
47
|
-
|
|
48
63
|
const baseNode = new CompositeGeneratorNode()
|
|
49
64
|
if (node.children.length > 0) {
|
|
65
|
+
const label = toSingleQuotes(node.title)
|
|
50
66
|
baseNode
|
|
51
|
-
.append('subgraph ', fqnName, '[',
|
|
67
|
+
.append('subgraph ', fqnName, '["`', label, '`"]', NL)
|
|
52
68
|
.indent({
|
|
53
69
|
indentedChildren: [
|
|
54
70
|
joinToNode(
|
|
@@ -63,7 +79,7 @@ export function generateMermaid(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
|
63
79
|
})
|
|
64
80
|
.append('end', NL)
|
|
65
81
|
} else {
|
|
66
|
-
baseNode.append(fqnName,
|
|
82
|
+
baseNode.append(fqnName, mmdshape(node))
|
|
67
83
|
}
|
|
68
84
|
return baseNode
|
|
69
85
|
}
|
|
@@ -72,7 +88,7 @@ export function generateMermaid(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
|
72
88
|
return new CompositeGeneratorNode().append(
|
|
73
89
|
names.get(edge.source),
|
|
74
90
|
' -.',
|
|
75
|
-
edge.label ? ' "' + edge.label
|
|
91
|
+
edge.label ? ' "`' + toSingleQuotes(edge.label) + '`" .-' : '-',
|
|
76
92
|
'> ',
|
|
77
93
|
names.get(edge.target),
|
|
78
94
|
)
|
|
@@ -80,11 +96,10 @@ export function generateMermaid(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
|
80
96
|
|
|
81
97
|
return toString(
|
|
82
98
|
new CompositeGeneratorNode()
|
|
83
|
-
.
|
|
84
|
-
view.title !== null && view.title.length > 0,
|
|
99
|
+
.append(
|
|
85
100
|
'---',
|
|
86
101
|
NL,
|
|
87
|
-
`title: ${JSON.stringify(
|
|
102
|
+
`title: ${JSON.stringify(toSingleQuotes(viewmodel.titleOrId))}`,
|
|
88
103
|
NL,
|
|
89
104
|
'---',
|
|
90
105
|
NL,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nonexhaustive } from '@likec4/core'
|
|
1
2
|
import type { LikeC4ViewModel } from '@likec4/core/model'
|
|
2
3
|
import type {
|
|
3
4
|
aux,
|
|
@@ -13,7 +14,7 @@ import type {
|
|
|
13
14
|
} from '@likec4/core/types'
|
|
14
15
|
import { RichText } from '@likec4/core/types'
|
|
15
16
|
import { CompositeGeneratorNode, joinToNode, NL, toString } from 'langium/generate'
|
|
16
|
-
import { isNullish as isNil } from 'remeda'
|
|
17
|
+
import { isEmptyish, isNullish as isNil } from 'remeda'
|
|
17
18
|
|
|
18
19
|
const capitalizeFirstLetter = (value: string) => value.charAt(0).toLocaleUpperCase() + value.slice(1)
|
|
19
20
|
|
|
@@ -67,14 +68,21 @@ const pumlShape = ({ shape }: ComputedNode) => {
|
|
|
67
68
|
case 'cylinder': {
|
|
68
69
|
return 'database' as const
|
|
69
70
|
}
|
|
71
|
+
case 'document':
|
|
70
72
|
case 'mobile':
|
|
73
|
+
case 'bucket':
|
|
71
74
|
case 'browser': {
|
|
72
75
|
return 'rectangle' as const
|
|
73
76
|
}
|
|
77
|
+
default:
|
|
78
|
+
nonexhaustive(shape)
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
const escapeLabel = (label: string | null | undefined) =>
|
|
82
|
+
const escapeLabel = (label: string | null | undefined) =>
|
|
83
|
+
isEmptyish(label) ? null : JSON.stringify(label)
|
|
84
|
+
.slice(1, -1)
|
|
85
|
+
.replace(/\\"/g, '"') // Unescape double quotes - PUML does not support escaped double quotes
|
|
78
86
|
|
|
79
87
|
export function generatePuml(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
80
88
|
const view = viewmodel.$view
|
|
@@ -90,7 +98,7 @@ export function generatePuml(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
|
90
98
|
|
|
91
99
|
const printHeader = () => {
|
|
92
100
|
return new CompositeGeneratorNode()
|
|
93
|
-
.append('title "',
|
|
101
|
+
.append('title "', viewmodel.titleOrId, '"', NL)
|
|
94
102
|
.append(pumlDirection(view), ' direction', NL)
|
|
95
103
|
}
|
|
96
104
|
|
|
@@ -147,8 +155,8 @@ export function generatePuml(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
|
147
155
|
.append(shape, ' ')
|
|
148
156
|
.append('"')
|
|
149
157
|
.append('==', label)
|
|
150
|
-
.appendIf(!!tech,
|
|
151
|
-
.appendIf(description.nonEmpty,
|
|
158
|
+
.appendIf(!!tech, `\\n<size:10>[`, tech!, ']</size>')
|
|
159
|
+
.appendIf(description.nonEmpty, `\\n\\n`, escapeLabel(description.text)!)
|
|
152
160
|
.append('"', ' <<', fqn, '>> ', 'as ', fqn, NL)
|
|
153
161
|
}
|
|
154
162
|
|
|
@@ -189,20 +197,37 @@ export function generatePuml(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
|
189
197
|
}
|
|
190
198
|
|
|
191
199
|
const printEdge = (edge: ComputedEdge): CompositeGeneratorNode => {
|
|
192
|
-
const tech =
|
|
193
|
-
const label =
|
|
200
|
+
const tech = edge.technology || ''
|
|
201
|
+
const label = edge.label || tech
|
|
194
202
|
const color = pumlColor(edge.color, relationshipsColorProvider('line'), '#777777')
|
|
195
203
|
|
|
196
|
-
const
|
|
204
|
+
const withColor = (text: string) => `<color:${color}>${text.replaceAll('"', `'`)}`
|
|
197
205
|
|
|
198
|
-
|
|
199
|
-
.append(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
+
const out = new CompositeGeneratorNode()
|
|
207
|
+
.append(
|
|
208
|
+
names.get(edge.source),
|
|
209
|
+
' .[',
|
|
210
|
+
color,
|
|
211
|
+
',thickness=2].> ',
|
|
212
|
+
names.get(edge.target),
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
if (label || tech) {
|
|
216
|
+
out.append(
|
|
217
|
+
' : ',
|
|
218
|
+
// Prepend color to each line
|
|
219
|
+
label
|
|
220
|
+
.split('\n')
|
|
221
|
+
.map(l => isEmptyish(l) ? l : withColor(l))
|
|
222
|
+
.join('\\n'),
|
|
223
|
+
)
|
|
224
|
+
// Append technology if it exists and is different from the label
|
|
225
|
+
if (tech && tech !== label) {
|
|
226
|
+
out.append('\\n<size:8>[', withColor(tech), ']</size>')
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return out.append(NL)
|
|
206
231
|
}
|
|
207
232
|
|
|
208
233
|
return toString(
|
package/src/puml/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { generatePuml } from './generate-puml'
|
|
@@ -19,7 +19,7 @@ export function generateReactTypes(model: AnyLikeC4Model, options: { useCorePack
|
|
|
19
19
|
import type { PropsWithChildren } from 'react'
|
|
20
20
|
import type { JSX } from 'react/jsx-runtime'
|
|
21
21
|
import type { LikeC4Model } from '${useCorePackage ? '@likec4/core' : 'likec4'}/model'
|
|
22
|
-
import type {
|
|
22
|
+
import type { LayoutedView } from '${useCorePackage ? '@likec4/core/types' : 'likec4/model'}'
|
|
23
23
|
import type {
|
|
24
24
|
LikeC4ViewProps as GenericLikeC4ViewProps,
|
|
25
25
|
ReactLikeC4Props as GenericReactLikeC4Props
|
|
@@ -31,7 +31,7 @@ declare function isLikeC4ViewId(value: unknown): value is $ViewId;
|
|
|
31
31
|
|
|
32
32
|
declare const likec4model: LikeC4Model<$Aux>;
|
|
33
33
|
declare function useLikeC4Model(): LikeC4Model<$Aux>;
|
|
34
|
-
declare function useLikeC4View(viewId: $ViewId):
|
|
34
|
+
declare function useLikeC4View(viewId: $ViewId): LayoutedView<$Aux>;
|
|
35
35
|
|
|
36
36
|
declare function LikeC4ModelProvider(props: PropsWithChildren): JSX.Element;
|
|
37
37
|
|
package/dist/d2/generate-d2.d.ts
DELETED
package/dist/d2/generate-d2.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
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 d2direction = ({ autoLayout }) => {
|
|
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";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const d2shape = ({ shape }) => {
|
|
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";
|
|
34
|
-
}
|
|
35
|
-
case "mobile":
|
|
36
|
-
case "browser": {
|
|
37
|
-
return "rectangle";
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
export function generateD2(viewmodel) {
|
|
42
|
-
const view = viewmodel.$view;
|
|
43
|
-
const { nodes, edges } = view;
|
|
44
|
-
const names = /* @__PURE__ */ new Map();
|
|
45
|
-
const printNode = (node, parentName) => {
|
|
46
|
-
const name = nodeName(node);
|
|
47
|
-
const fqnName2 = (parentName ? parentName + "." : "") + name;
|
|
48
|
-
names.set(node.id, fqnName2);
|
|
49
|
-
const label = JSON.stringify(node.title);
|
|
50
|
-
const shape = d2shape(node);
|
|
51
|
-
return new CompositeGeneratorNode().append(name, ": {", NL).indent({
|
|
52
|
-
indentedChildren: (indent) => indent.append("label: ", label, NL).appendIf(shape !== "rectangle", "shape: ", shape, NL).appendIf(
|
|
53
|
-
node.children.length > 0,
|
|
54
|
-
NL,
|
|
55
|
-
joinToNode(
|
|
56
|
-
nodes.filter((n) => n.parent === node.id),
|
|
57
|
-
(n) => printNode(n, fqnName2)
|
|
58
|
-
)
|
|
59
|
-
),
|
|
60
|
-
indentation: 2
|
|
61
|
-
}).append("}", NL);
|
|
62
|
-
};
|
|
63
|
-
const printEdge = (edge) => {
|
|
64
|
-
return new CompositeGeneratorNode().append(names.get(edge.source), " -> ", names.get(edge.target)).append((out) => edge.label && out.append(": ", JSON.stringify(edge.label)));
|
|
65
|
-
};
|
|
66
|
-
return toString(
|
|
67
|
-
new CompositeGeneratorNode().append("direction: ", d2direction(view), NL, NL).append(
|
|
68
|
-
joinToNode(
|
|
69
|
-
nodes.filter((n) => isNil(n.parent)),
|
|
70
|
-
(n) => printNode(n),
|
|
71
|
-
{
|
|
72
|
-
appendNewLineIfNotEmpty: true
|
|
73
|
-
}
|
|
74
|
-
)
|
|
75
|
-
).appendIf(
|
|
76
|
-
edges.length > 0,
|
|
77
|
-
NL,
|
|
78
|
-
joinToNode(edges, (e) => printEdge(e), {
|
|
79
|
-
appendNewLineIfNotEmpty: true
|
|
80
|
-
})
|
|
81
|
-
)
|
|
82
|
-
);
|
|
83
|
-
}
|
package/dist/d2/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './generate-d2';
|
package/dist/d2/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./generate-d2.js";
|
package/dist/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { generateD2 } from './d2/generate-d2';
|
|
2
|
-
export { generateMermaid } from './mmd/generate-mmd';
|
|
3
|
-
export { generateLikeC4Model } from './model/generate-likec4-model';
|
|
4
|
-
export { generatePuml } from './puml/generate-puml';
|
|
5
|
-
export { generateReactNext } from './react-next/generate-react-next';
|
|
6
|
-
export { generateReactTypes } from './react/generate-react-types';
|
|
7
|
-
export { generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs } from './views-data-ts/generate-views-data';
|
package/dist/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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 { generatePuml } from "./puml/generate-puml.js";
|
|
5
|
-
export { generateReactNext } from "./react-next/generate-react-next.js";
|
|
6
|
-
export { generateReactTypes } from "./react/generate-react-types.js";
|
|
7
|
-
export { generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs } from "./views-data-ts/generate-views-data.js";
|
package/dist/mmd/generate-mmd.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
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 mmdshape = ({ shape }) => {
|
|
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 ["[", "]"];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
export function generateMermaid(viewmodel) {
|
|
26
|
-
const view = viewmodel.$view;
|
|
27
|
-
const { nodes, edges } = view;
|
|
28
|
-
const names = /* @__PURE__ */ new Map();
|
|
29
|
-
const printNode = (node, parentName) => {
|
|
30
|
-
const name = nodeName(node);
|
|
31
|
-
const fqnName2 = (parentName ? parentName + "." : "") + name;
|
|
32
|
-
names.set(node.id, fqnName2);
|
|
33
|
-
const label = node.title.replaceAll("\n", "\\n");
|
|
34
|
-
const shape = mmdshape(node);
|
|
35
|
-
const baseNode = new CompositeGeneratorNode();
|
|
36
|
-
if (node.children.length > 0) {
|
|
37
|
-
baseNode.append("subgraph ", fqnName2, "[", JSON.stringify(node.title), "]", NL).indent({
|
|
38
|
-
indentedChildren: [
|
|
39
|
-
joinToNode(
|
|
40
|
-
nodes.filter((n) => n.parent === node.id),
|
|
41
|
-
(n) => printNode(n, fqnName2),
|
|
42
|
-
{
|
|
43
|
-
appendNewLineIfNotEmpty: true
|
|
44
|
-
}
|
|
45
|
-
)
|
|
46
|
-
],
|
|
47
|
-
indentation: 2
|
|
48
|
-
}).append("end", NL);
|
|
49
|
-
} else {
|
|
50
|
-
baseNode.append(fqnName2, shape[0], label, shape[1]);
|
|
51
|
-
}
|
|
52
|
-
return baseNode;
|
|
53
|
-
};
|
|
54
|
-
const printEdge = (edge) => {
|
|
55
|
-
return new CompositeGeneratorNode().append(
|
|
56
|
-
names.get(edge.source),
|
|
57
|
-
" -.",
|
|
58
|
-
edge.label ? ' "' + edge.label.replaceAll("\n", "\\n") + '" .-' : "-",
|
|
59
|
-
"> ",
|
|
60
|
-
names.get(edge.target)
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
return toString(
|
|
64
|
-
new CompositeGeneratorNode().appendIf(
|
|
65
|
-
view.title !== null && view.title.length > 0,
|
|
66
|
-
"---",
|
|
67
|
-
NL,
|
|
68
|
-
`title: ${JSON.stringify(view.title)}`,
|
|
69
|
-
NL,
|
|
70
|
-
"---",
|
|
71
|
-
NL
|
|
72
|
-
).append("graph ", view.autoLayout.direction, NL).indent({
|
|
73
|
-
indentedChildren: (indent) => {
|
|
74
|
-
indent.append(
|
|
75
|
-
joinToNode(
|
|
76
|
-
nodes.filter((n) => isNil(n.parent)),
|
|
77
|
-
(n) => printNode(n),
|
|
78
|
-
{
|
|
79
|
-
appendNewLineIfNotEmpty: true
|
|
80
|
-
}
|
|
81
|
-
)
|
|
82
|
-
).appendIf(
|
|
83
|
-
edges.length > 0,
|
|
84
|
-
joinToNode(edges, (e) => printEdge(e), {
|
|
85
|
-
appendNewLineIfNotEmpty: true
|
|
86
|
-
})
|
|
87
|
-
);
|
|
88
|
-
},
|
|
89
|
-
indentation: 2
|
|
90
|
-
})
|
|
91
|
-
);
|
|
92
|
-
}
|
package/dist/mmd/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './generate-mmd';
|
package/dist/mmd/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./generate-mmd.js";
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
compareNatural,
|
|
3
|
-
sortNaturalByFqn
|
|
4
|
-
} from "@likec4/core/utils";
|
|
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, options = {}) {
|
|
26
|
-
const { useCorePackage = false } = options;
|
|
27
|
-
return `
|
|
28
|
-
import type { Aux, SpecAux } from '${useCorePackage ? "@likec4/core/types" : "likec4/model"}';
|
|
29
|
-
|
|
30
|
-
export type $Specs = SpecAux<
|
|
31
|
-
// Element kinds
|
|
32
|
-
${toUnion(keys(model.specification.elements))},
|
|
33
|
-
// Deployment kinds
|
|
34
|
-
${toUnion(keys(model.specification.deployments ?? {}))},
|
|
35
|
-
// Relationship kinds
|
|
36
|
-
${toUnion(keys(model.specification.relationships ?? {}))},
|
|
37
|
-
// Tags
|
|
38
|
-
${toUnion(keys(model.specification.tags ?? {}))},
|
|
39
|
-
// Metadata keys
|
|
40
|
-
${toUnion(model.specification.metadataKeys ?? [])}
|
|
41
|
-
>
|
|
42
|
-
|
|
43
|
-
export type $Aux = Aux<
|
|
44
|
-
${JSON.stringify(model.stage)},
|
|
45
|
-
// Elements
|
|
46
|
-
${elementIdToUnion(model.$data.elements)},
|
|
47
|
-
// Deployments
|
|
48
|
-
${elementIdToUnion(model.$data.deployments.elements)},
|
|
49
|
-
// Views
|
|
50
|
-
${toUnion(keys(model.$data.views))},
|
|
51
|
-
// Project ID
|
|
52
|
-
${JSON.stringify(model.projectId)},
|
|
53
|
-
$Specs
|
|
54
|
-
>
|
|
55
|
-
|
|
56
|
-
export type $ElementId = $Aux['ElementId']
|
|
57
|
-
export type $DeploymentId = $Aux['DeploymentId']
|
|
58
|
-
export type $ViewId = $Aux['ViewId']
|
|
59
|
-
|
|
60
|
-
export type $ElementKind = $Aux['ElementKind']
|
|
61
|
-
export type $RelationKind = $Aux['RelationKind']
|
|
62
|
-
export type $DeploymentKind = $Aux['DeploymentKind']
|
|
63
|
-
export type $Tag = $Aux['Tag']
|
|
64
|
-
export type $Tags = readonly $Aux['Tag'][]
|
|
65
|
-
export type $MetadataKey = $Aux['MetadataKey']
|
|
66
|
-
`.trimStart();
|
|
67
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import JSON5 from "json5";
|
|
2
|
-
import { generateAux } from "./generate-aux.js";
|
|
3
|
-
export function generateLikeC4Model(model, options = {}) {
|
|
4
|
-
const aux = generateAux(model, options);
|
|
5
|
-
const { useCorePackage = false } = options;
|
|
6
|
-
return `
|
|
7
|
-
/* prettier-ignore-start */
|
|
8
|
-
/* eslint-disable */
|
|
9
|
-
|
|
10
|
-
/******************************************************************************
|
|
11
|
-
* This file was generated
|
|
12
|
-
* DO NOT EDIT MANUALLY!
|
|
13
|
-
******************************************************************************/
|
|
14
|
-
|
|
15
|
-
import { LikeC4Model } from '${useCorePackage ? "@likec4/core" : "likec4"}/model'
|
|
16
|
-
${aux}
|
|
17
|
-
|
|
18
|
-
export const likec4model: LikeC4Model<$Aux> = new LikeC4Model(${JSON5.stringify(model.$data, { space: 2, quote: "'" })} as any) as any
|
|
19
|
-
|
|
20
|
-
/* prettier-ignore-end */
|
|
21
|
-
`.trimStart();
|
|
22
|
-
}
|