@likec4/generators 1.5.0 → 1.29.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 +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
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import type { ComputedView, DiagramView } from '@likec4/core'
|
|
2
|
+
|
|
3
|
+
export const fakeDiagram: DiagramView = {
|
|
4
|
+
edges: [
|
|
5
|
+
{
|
|
6
|
+
headArrow: [
|
|
7
|
+
[294, 487],
|
|
8
|
+
[291, 496],
|
|
9
|
+
[288, 487]
|
|
10
|
+
],
|
|
11
|
+
id: 'cloud.frontend:cloud.backend',
|
|
12
|
+
label: 'requests',
|
|
13
|
+
labelBox: {
|
|
14
|
+
align: 'left',
|
|
15
|
+
width: 62,
|
|
16
|
+
x: 295,
|
|
17
|
+
y: 459
|
|
18
|
+
},
|
|
19
|
+
points: [
|
|
20
|
+
[291, 406],
|
|
21
|
+
[291, 432],
|
|
22
|
+
[291, 461],
|
|
23
|
+
[291, 487]
|
|
24
|
+
],
|
|
25
|
+
relations: [
|
|
26
|
+
'cloud.frontend.dashboard:cloud.backend.graphql',
|
|
27
|
+
'cloud.frontend.adminPanel:cloud.backend.graphql'
|
|
28
|
+
],
|
|
29
|
+
source: 'cloud.frontend',
|
|
30
|
+
target: 'cloud.backend'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
headArrow: [
|
|
34
|
+
[294, 701],
|
|
35
|
+
[291, 711],
|
|
36
|
+
[288, 701]
|
|
37
|
+
],
|
|
38
|
+
id: 'cloud.backend:amazon',
|
|
39
|
+
label: null,
|
|
40
|
+
labelBox: null,
|
|
41
|
+
points: [
|
|
42
|
+
[291, 641],
|
|
43
|
+
[291, 660],
|
|
44
|
+
[291, 681],
|
|
45
|
+
[291, 702]
|
|
46
|
+
],
|
|
47
|
+
relations: ['cloud.backend.storage:amazon.s3'],
|
|
48
|
+
source: 'cloud.backend',
|
|
49
|
+
target: 'amazon'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
headArrow: [
|
|
53
|
+
[344, 257],
|
|
54
|
+
[336, 263],
|
|
55
|
+
[338, 253]
|
|
56
|
+
],
|
|
57
|
+
id: 'support:cloud.frontend',
|
|
58
|
+
label: null,
|
|
59
|
+
labelBox: null,
|
|
60
|
+
points: [
|
|
61
|
+
[413, 141],
|
|
62
|
+
[391, 176],
|
|
63
|
+
[364, 218],
|
|
64
|
+
[342, 255]
|
|
65
|
+
],
|
|
66
|
+
relations: ['support:cloud.frontend.adminPanel'],
|
|
67
|
+
source: 'support',
|
|
68
|
+
target: 'cloud.frontend'
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
headArrow: [
|
|
72
|
+
[244, 253],
|
|
73
|
+
[246, 263],
|
|
74
|
+
[239, 257]
|
|
75
|
+
],
|
|
76
|
+
id: 'customer:cloud.frontend',
|
|
77
|
+
label: 'opens',
|
|
78
|
+
labelBox: {
|
|
79
|
+
align: 'left',
|
|
80
|
+
width: 44,
|
|
81
|
+
x: 208,
|
|
82
|
+
y: 193
|
|
83
|
+
},
|
|
84
|
+
points: [
|
|
85
|
+
[169, 141],
|
|
86
|
+
[191, 176],
|
|
87
|
+
[218, 218],
|
|
88
|
+
[241, 255]
|
|
89
|
+
],
|
|
90
|
+
relations: ['customer:cloud.frontend.dashboard'],
|
|
91
|
+
source: 'customer',
|
|
92
|
+
target: 'cloud.frontend'
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
height: 855,
|
|
96
|
+
id: 'fakeView',
|
|
97
|
+
nodes: [
|
|
98
|
+
{
|
|
99
|
+
children: [],
|
|
100
|
+
color: 'primary',
|
|
101
|
+
id: 'amazon',
|
|
102
|
+
parent: null,
|
|
103
|
+
position: [165, 715],
|
|
104
|
+
relative: [165, 715],
|
|
105
|
+
shape: 'rectangle',
|
|
106
|
+
size: {
|
|
107
|
+
height: 140,
|
|
108
|
+
width: 251
|
|
109
|
+
},
|
|
110
|
+
title: 'amazon'
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
children: ['cloud.backend', 'cloud.frontend'],
|
|
114
|
+
color: 'primary',
|
|
115
|
+
id: 'cloud',
|
|
116
|
+
parent: null,
|
|
117
|
+
position: [139, 210],
|
|
118
|
+
relative: [139, 210],
|
|
119
|
+
shape: 'rectangle',
|
|
120
|
+
size: {
|
|
121
|
+
height: 457,
|
|
122
|
+
width: 304
|
|
123
|
+
},
|
|
124
|
+
title: 'cloud'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
children: [],
|
|
128
|
+
color: 'primary',
|
|
129
|
+
id: 'customer',
|
|
130
|
+
parent: null,
|
|
131
|
+
position: [0, 0],
|
|
132
|
+
relative: [0, 0],
|
|
133
|
+
shape: 'rectangle',
|
|
134
|
+
size: {
|
|
135
|
+
height: 140,
|
|
136
|
+
width: 251
|
|
137
|
+
},
|
|
138
|
+
title: 'customer'
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
children: [],
|
|
142
|
+
color: 'primary',
|
|
143
|
+
id: 'support',
|
|
144
|
+
parent: null,
|
|
145
|
+
position: [330, 0],
|
|
146
|
+
relative: [330, 0],
|
|
147
|
+
shape: 'rectangle',
|
|
148
|
+
size: {
|
|
149
|
+
height: 140,
|
|
150
|
+
width: 251
|
|
151
|
+
},
|
|
152
|
+
title: 'support'
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
children: [],
|
|
156
|
+
color: 'primary',
|
|
157
|
+
id: 'cloud.backend',
|
|
158
|
+
parent: 'cloud',
|
|
159
|
+
position: [165, 500],
|
|
160
|
+
relative: [26, 290],
|
|
161
|
+
shape: 'rectangle',
|
|
162
|
+
size: {
|
|
163
|
+
height: 140,
|
|
164
|
+
width: 251
|
|
165
|
+
},
|
|
166
|
+
title: 'backend'
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
children: [],
|
|
170
|
+
color: 'primary',
|
|
171
|
+
id: 'cloud.frontend',
|
|
172
|
+
parent: 'cloud',
|
|
173
|
+
position: [165, 266],
|
|
174
|
+
relative: [26, 56],
|
|
175
|
+
shape: 'rectangle',
|
|
176
|
+
size: {
|
|
177
|
+
height: 140,
|
|
178
|
+
width: 251
|
|
179
|
+
},
|
|
180
|
+
title: 'frontend'
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
autoLayout: { direction: 'TB' },
|
|
184
|
+
rules: [
|
|
185
|
+
{
|
|
186
|
+
exprs: [
|
|
187
|
+
{
|
|
188
|
+
wildcard: true
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
isInclude: true
|
|
192
|
+
}
|
|
193
|
+
],
|
|
194
|
+
title: '',
|
|
195
|
+
viewOf: 'cloud',
|
|
196
|
+
width: 582
|
|
197
|
+
} as any
|
|
198
|
+
|
|
199
|
+
export const fakeDiagram2: DiagramView = {
|
|
200
|
+
edges: [
|
|
201
|
+
{
|
|
202
|
+
headArrow: [
|
|
203
|
+
[129, 456],
|
|
204
|
+
[126, 465],
|
|
205
|
+
[123, 456]
|
|
206
|
+
],
|
|
207
|
+
id: 'system.frontend:system.backend',
|
|
208
|
+
label: 'requests',
|
|
209
|
+
labelBox: {
|
|
210
|
+
align: 'left',
|
|
211
|
+
width: 62,
|
|
212
|
+
x: 130,
|
|
213
|
+
y: 428
|
|
214
|
+
},
|
|
215
|
+
points: [
|
|
216
|
+
[126, 375],
|
|
217
|
+
[126, 400],
|
|
218
|
+
[126, 429],
|
|
219
|
+
[126, 456]
|
|
220
|
+
],
|
|
221
|
+
relations: ['671e3db5eb605d5f245f247d95925bd0953e0e4c'],
|
|
222
|
+
source: 'system.frontend',
|
|
223
|
+
target: 'system.backend'
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
headArrow: [
|
|
227
|
+
[129, 221],
|
|
228
|
+
[126, 231],
|
|
229
|
+
[123, 221]
|
|
230
|
+
],
|
|
231
|
+
id: 'client:system.frontend',
|
|
232
|
+
label: 'opens',
|
|
233
|
+
labelBox: {
|
|
234
|
+
align: 'left',
|
|
235
|
+
width: 44,
|
|
236
|
+
x: 130,
|
|
237
|
+
y: 193
|
|
238
|
+
},
|
|
239
|
+
points: [
|
|
240
|
+
[126, 141],
|
|
241
|
+
[126, 166],
|
|
242
|
+
[126, 195],
|
|
243
|
+
[126, 221]
|
|
244
|
+
],
|
|
245
|
+
relations: ['99bffdfd5c78e024393e6223cd9b19225321a5e3'],
|
|
246
|
+
source: 'client',
|
|
247
|
+
target: 'system.frontend'
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
height: 609,
|
|
251
|
+
id: '74f5364fa4b',
|
|
252
|
+
nodes: [
|
|
253
|
+
{
|
|
254
|
+
children: [],
|
|
255
|
+
color: 'primary',
|
|
256
|
+
id: 'client',
|
|
257
|
+
parent: null,
|
|
258
|
+
position: [0, 0],
|
|
259
|
+
relative: [0, 0],
|
|
260
|
+
shape: 'rectangle',
|
|
261
|
+
size: {
|
|
262
|
+
height: 140,
|
|
263
|
+
width: 251
|
|
264
|
+
},
|
|
265
|
+
title: 'client'
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
children: [],
|
|
269
|
+
color: 'primary',
|
|
270
|
+
id: 'system.backend',
|
|
271
|
+
parent: null,
|
|
272
|
+
position: [0, 469],
|
|
273
|
+
relative: [0, 469],
|
|
274
|
+
shape: 'rectangle',
|
|
275
|
+
size: {
|
|
276
|
+
height: 140,
|
|
277
|
+
width: 251
|
|
278
|
+
},
|
|
279
|
+
title: 'backend'
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
children: [],
|
|
283
|
+
color: 'primary',
|
|
284
|
+
id: 'system.frontend',
|
|
285
|
+
parent: null,
|
|
286
|
+
position: [0, 235],
|
|
287
|
+
relative: [0, 235],
|
|
288
|
+
shape: 'rectangle',
|
|
289
|
+
size: {
|
|
290
|
+
height: 140,
|
|
291
|
+
width: 251
|
|
292
|
+
},
|
|
293
|
+
title: 'frontend'
|
|
294
|
+
}
|
|
295
|
+
],
|
|
296
|
+
autoLayout: { direction: 'TB' },
|
|
297
|
+
rules: [
|
|
298
|
+
{
|
|
299
|
+
exprs: [
|
|
300
|
+
{
|
|
301
|
+
wildcard: true
|
|
302
|
+
}
|
|
303
|
+
],
|
|
304
|
+
isInclude: true
|
|
305
|
+
}
|
|
306
|
+
],
|
|
307
|
+
title: 'frontend',
|
|
308
|
+
viewOf: 'system.frontend',
|
|
309
|
+
width: 251
|
|
310
|
+
} as any
|
|
311
|
+
|
|
312
|
+
export const fakeComputedView3Levels: ComputedView = {
|
|
313
|
+
edges: [
|
|
314
|
+
{
|
|
315
|
+
id: 'cloud.frontend.dashboard:cloud.backend.graphql',
|
|
316
|
+
label: null,
|
|
317
|
+
relations: ['cloud.frontend.dashboard:cloud.backend.graphql'],
|
|
318
|
+
source: 'cloud.frontend.dashboard',
|
|
319
|
+
target: 'cloud.backend.graphql'
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
id: 'cloud.frontend.adminPanel:cloud.backend.graphql',
|
|
323
|
+
label: null,
|
|
324
|
+
relations: ['cloud.frontend.adminPanel:cloud.backend.graphql'],
|
|
325
|
+
source: 'cloud.frontend.adminPanel',
|
|
326
|
+
target: 'cloud.backend.graphql'
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
id: 'cloud.backend.storage:amazon',
|
|
330
|
+
label: null,
|
|
331
|
+
relations: ['cloud.backend.storage:amazon.s3'],
|
|
332
|
+
source: 'cloud.backend.storage',
|
|
333
|
+
target: 'amazon'
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
id: 'cloud.backend.graphql:cloud.backend.storage',
|
|
337
|
+
label: null,
|
|
338
|
+
relations: ['cloud.backend.graphql:cloud.backend.storage'],
|
|
339
|
+
source: 'cloud.backend.graphql',
|
|
340
|
+
target: 'cloud.backend.storage'
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
id: 'support:cloud.frontend.adminPanel',
|
|
344
|
+
label: null,
|
|
345
|
+
relations: ['support:cloud.frontend.adminPanel'],
|
|
346
|
+
source: 'support',
|
|
347
|
+
target: 'cloud.frontend.adminPanel'
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
id: 'customer:cloud.frontend.dashboard',
|
|
351
|
+
label: null,
|
|
352
|
+
relations: ['customer:cloud.frontend.dashboard'],
|
|
353
|
+
source: 'customer',
|
|
354
|
+
target: 'cloud.frontend.dashboard'
|
|
355
|
+
}
|
|
356
|
+
],
|
|
357
|
+
id: 'cloud3levels',
|
|
358
|
+
nodes: [
|
|
359
|
+
{
|
|
360
|
+
children: [],
|
|
361
|
+
color: 'primary',
|
|
362
|
+
id: 'amazon',
|
|
363
|
+
parent: null,
|
|
364
|
+
shape: 'rectangle',
|
|
365
|
+
title: 'amazon'
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
children: ['cloud.backend', 'cloud.frontend.adminPanel', 'cloud.frontend.dashboard'],
|
|
369
|
+
color: 'primary',
|
|
370
|
+
id: 'cloud',
|
|
371
|
+
navigateTo: 'fakeView',
|
|
372
|
+
parent: null,
|
|
373
|
+
shape: 'rectangle',
|
|
374
|
+
title: 'cloud'
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
children: [],
|
|
378
|
+
color: 'primary',
|
|
379
|
+
id: 'customer',
|
|
380
|
+
parent: null,
|
|
381
|
+
shape: 'rectangle',
|
|
382
|
+
title: 'customer'
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
children: [],
|
|
386
|
+
color: 'primary',
|
|
387
|
+
id: 'support',
|
|
388
|
+
parent: null,
|
|
389
|
+
shape: 'rectangle',
|
|
390
|
+
title: 'support'
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
children: ['cloud.backend.graphql', 'cloud.backend.storage'],
|
|
394
|
+
color: 'primary',
|
|
395
|
+
id: 'cloud.backend',
|
|
396
|
+
parent: 'cloud',
|
|
397
|
+
shape: 'rectangle',
|
|
398
|
+
title: 'backend'
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
children: [],
|
|
402
|
+
color: 'primary',
|
|
403
|
+
id: 'cloud.backend.graphql',
|
|
404
|
+
parent: 'cloud.backend',
|
|
405
|
+
shape: 'rectangle',
|
|
406
|
+
title: 'graphql'
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
children: [],
|
|
410
|
+
color: 'primary',
|
|
411
|
+
id: 'cloud.backend.storage',
|
|
412
|
+
parent: 'cloud.backend',
|
|
413
|
+
shape: 'rectangle',
|
|
414
|
+
title: 'storage'
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
children: [],
|
|
418
|
+
color: 'primary',
|
|
419
|
+
id: 'cloud.frontend.adminPanel',
|
|
420
|
+
parent: 'cloud',
|
|
421
|
+
shape: 'rectangle',
|
|
422
|
+
title: 'adminPanel'
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
children: [],
|
|
426
|
+
color: 'primary',
|
|
427
|
+
id: 'cloud.frontend.dashboard',
|
|
428
|
+
parent: 'cloud',
|
|
429
|
+
shape: 'rectangle',
|
|
430
|
+
title: 'dashboard'
|
|
431
|
+
}
|
|
432
|
+
],
|
|
433
|
+
autoLayout: { direction: 'TB' },
|
|
434
|
+
rules: [
|
|
435
|
+
{
|
|
436
|
+
exprs: [
|
|
437
|
+
{
|
|
438
|
+
wildcard: true
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
element: 'cloud.frontend',
|
|
442
|
+
isChildren: true
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
element: 'cloud.backend',
|
|
446
|
+
isChildren: true
|
|
447
|
+
}
|
|
448
|
+
],
|
|
449
|
+
isInclude: true
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
exprs: [
|
|
453
|
+
{
|
|
454
|
+
element: 'cloud.frontend',
|
|
455
|
+
isChildren: false
|
|
456
|
+
}
|
|
457
|
+
],
|
|
458
|
+
isInclude: false
|
|
459
|
+
}
|
|
460
|
+
],
|
|
461
|
+
title: 'Context: Cloud',
|
|
462
|
+
viewOf: 'cloud'
|
|
463
|
+
} as any
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`generate D2 - fakeComputedView 3 Levels 1`] = `
|
|
4
|
+
"direction: down
|
|
5
|
+
|
|
6
|
+
Amazon: {
|
|
7
|
+
label: "amazon"
|
|
8
|
+
}
|
|
9
|
+
Cloud: {
|
|
10
|
+
label: "cloud"
|
|
11
|
+
|
|
12
|
+
Backend: {
|
|
13
|
+
label: "backend"
|
|
14
|
+
|
|
15
|
+
Graphql: {
|
|
16
|
+
label: "graphql"
|
|
17
|
+
}
|
|
18
|
+
Storage: {
|
|
19
|
+
label: "storage"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
FrontendAdminPanel: {
|
|
23
|
+
label: "adminPanel"
|
|
24
|
+
}
|
|
25
|
+
FrontendDashboard: {
|
|
26
|
+
label: "dashboard"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
Customer: {
|
|
30
|
+
label: "customer"
|
|
31
|
+
}
|
|
32
|
+
Support: {
|
|
33
|
+
label: "support"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Cloud.FrontendDashboard -> Cloud.Backend.Graphql
|
|
37
|
+
Cloud.FrontendAdminPanel -> Cloud.Backend.Graphql
|
|
38
|
+
Cloud.Backend.Storage -> Amazon
|
|
39
|
+
Cloud.Backend.Graphql -> Cloud.Backend.Storage
|
|
40
|
+
Support -> Cloud.FrontendAdminPanel
|
|
41
|
+
Customer -> Cloud.FrontendDashboard
|
|
42
|
+
"
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
exports[`generate D2 - fakeDiagram 1`] = `
|
|
46
|
+
"direction: down
|
|
47
|
+
|
|
48
|
+
Amazon: {
|
|
49
|
+
label: "amazon"
|
|
50
|
+
}
|
|
51
|
+
Cloud: {
|
|
52
|
+
label: "cloud"
|
|
53
|
+
|
|
54
|
+
Backend: {
|
|
55
|
+
label: "backend"
|
|
56
|
+
}
|
|
57
|
+
Frontend: {
|
|
58
|
+
label: "frontend"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
Customer: {
|
|
62
|
+
label: "customer"
|
|
63
|
+
}
|
|
64
|
+
Support: {
|
|
65
|
+
label: "support"
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Cloud.Frontend -> Cloud.Backend: "requests"
|
|
69
|
+
Cloud.Backend -> Amazon
|
|
70
|
+
Support -> Cloud.Frontend
|
|
71
|
+
Customer -> Cloud.Frontend: "opens"
|
|
72
|
+
"
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
exports[`generate D2 - fakeDiagram2 1`] = `
|
|
76
|
+
"direction: down
|
|
77
|
+
|
|
78
|
+
Client: {
|
|
79
|
+
label: "client"
|
|
80
|
+
}
|
|
81
|
+
SystemBackend: {
|
|
82
|
+
label: "backend"
|
|
83
|
+
}
|
|
84
|
+
SystemFrontend: {
|
|
85
|
+
label: "frontend"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
SystemFrontend -> SystemBackend: "requests"
|
|
89
|
+
Client -> SystemFrontend: "opens"
|
|
90
|
+
"
|
|
91
|
+
`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect, test } from 'vitest'
|
|
2
|
+
import { fakeComputedView3Levels, fakeDiagram, fakeDiagram2 } from '../__mocks__/data'
|
|
3
|
+
import { generateD2 } from './generate-d2'
|
|
4
|
+
|
|
5
|
+
test('generate D2 - fakeDiagram', () => {
|
|
6
|
+
expect(generateD2(fakeDiagram)).toMatchSnapshot()
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('generate D2 - fakeDiagram2', () => {
|
|
10
|
+
expect(generateD2(fakeDiagram2)).toMatchSnapshot()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('generate D2 - fakeComputedView 3 Levels', () => {
|
|
14
|
+
expect(generateD2(fakeComputedView3Levels)).toMatchSnapshot()
|
|
15
|
+
})
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ComputedEdge, ComputedNode, ComputedView, NodeId } from '@likec4/core'
|
|
2
|
+
import { CompositeGeneratorNode, joinToNode, NL, toString } from 'langium/generate'
|
|
3
|
+
import { isNullish as isNil } from 'remeda'
|
|
4
|
+
|
|
5
|
+
const capitalizeFirstLetter = (value: string) => value.charAt(0).toLocaleUpperCase() + value.slice(1)
|
|
6
|
+
|
|
7
|
+
const fqnName = (nodeId: string): string => nodeId.split('.').map(capitalizeFirstLetter).join('')
|
|
8
|
+
|
|
9
|
+
const nodeName = (node: ComputedNode): string => {
|
|
10
|
+
return fqnName(node.parent ? node.id.slice(node.parent.length + 1) : node.id)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const d2direction = ({ autoLayout }: ComputedView) => {
|
|
14
|
+
switch (autoLayout.direction) {
|
|
15
|
+
case 'TB': {
|
|
16
|
+
return 'down'
|
|
17
|
+
}
|
|
18
|
+
case 'BT': {
|
|
19
|
+
return 'up'
|
|
20
|
+
}
|
|
21
|
+
case 'LR': {
|
|
22
|
+
return 'right'
|
|
23
|
+
}
|
|
24
|
+
case 'RL': {
|
|
25
|
+
return 'left'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const d2shape = ({ shape }: ComputedNode) => {
|
|
31
|
+
switch (shape) {
|
|
32
|
+
case 'queue':
|
|
33
|
+
case 'cylinder':
|
|
34
|
+
case 'rectangle':
|
|
35
|
+
case 'person': {
|
|
36
|
+
return shape
|
|
37
|
+
}
|
|
38
|
+
case 'storage': {
|
|
39
|
+
return 'stored_data' as const
|
|
40
|
+
}
|
|
41
|
+
case 'mobile':
|
|
42
|
+
case 'browser': {
|
|
43
|
+
return 'rectangle' as const
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function generateD2<V extends ComputedView>(view: V) {
|
|
49
|
+
const { nodes, edges } = view
|
|
50
|
+
const names = new Map<NodeId, string>()
|
|
51
|
+
|
|
52
|
+
const printNode = (node: ComputedNode, parentName?: string): CompositeGeneratorNode => {
|
|
53
|
+
const name = nodeName(node)
|
|
54
|
+
const fqnName = (parentName ? parentName + '.' : '') + name
|
|
55
|
+
names.set(node.id, fqnName)
|
|
56
|
+
|
|
57
|
+
const label = JSON.stringify(node.title)
|
|
58
|
+
const shape = d2shape(node)
|
|
59
|
+
|
|
60
|
+
return new CompositeGeneratorNode()
|
|
61
|
+
.append(name, ': {', NL)
|
|
62
|
+
.indent({
|
|
63
|
+
indentedChildren: indent =>
|
|
64
|
+
indent
|
|
65
|
+
.append('label: ', label, NL)
|
|
66
|
+
.appendIf(shape !== 'rectangle', 'shape: ', shape, NL)
|
|
67
|
+
.appendIf(
|
|
68
|
+
node.children.length > 0,
|
|
69
|
+
NL,
|
|
70
|
+
joinToNode(
|
|
71
|
+
nodes.filter(n => n.parent === node.id),
|
|
72
|
+
n => printNode(n, fqnName)
|
|
73
|
+
)
|
|
74
|
+
),
|
|
75
|
+
indentation: 2
|
|
76
|
+
})
|
|
77
|
+
.append('}', NL)
|
|
78
|
+
}
|
|
79
|
+
// return `${names.get(edge.source)} -> ${names.get(edge.target)}${edge.label ? ': ' + edge.label : ''}`
|
|
80
|
+
const printEdge = (edge: ComputedEdge): CompositeGeneratorNode => {
|
|
81
|
+
return new CompositeGeneratorNode()
|
|
82
|
+
.append(names.get(edge.source), ' -> ', names.get(edge.target))
|
|
83
|
+
.append(out => edge.label && out.append(': ', JSON.stringify(edge.label)))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return toString(
|
|
87
|
+
new CompositeGeneratorNode()
|
|
88
|
+
.append('direction: ', d2direction(view), NL, NL)
|
|
89
|
+
.append(
|
|
90
|
+
joinToNode(
|
|
91
|
+
nodes.filter(n => isNil(n.parent)),
|
|
92
|
+
n => printNode(n),
|
|
93
|
+
{
|
|
94
|
+
appendNewLineIfNotEmpty: true
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
.appendIf(
|
|
99
|
+
edges.length > 0,
|
|
100
|
+
NL,
|
|
101
|
+
joinToNode(edges, e => printEdge(e), {
|
|
102
|
+
appendNewLineIfNotEmpty: true
|
|
103
|
+
})
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
}
|
package/src/d2/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generate-d2'
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { generateD2 } from './d2/generate-d2'
|
|
2
|
+
export { generateMermaid } from './mmd/generate-mmd'
|
|
3
|
+
export { generateLikeC4Model } from './model/generate-likec4-model'
|
|
4
|
+
export { generateReactNext } from './react-next/generate-react-next'
|
|
5
|
+
export { generateReactTypes } from './react/generate-react-types'
|
|
6
|
+
export { generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs } from './views-data-ts/generate-views-data'
|