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