@likec4/generators 0.6.1 → 0.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likec4/generators",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "license": "MIT",
5
5
  "bugs": "https://github.com/likec4/likec4/issues",
6
6
  "homepage": "https://like-c4.dev",
@@ -32,8 +32,8 @@
32
32
  }
33
33
  },
34
34
  "scripts": {
35
- "compile": "",
36
- "release:build": "tsc -p tsconfig.esm.json",
35
+ "compile": "tsc --emitDeclarationOnly",
36
+ "build:release": "tsc -p tsconfig.esm.json",
37
37
  "build": "tsc",
38
38
  "dev": "tsc --watch",
39
39
  "lint": "run -T eslint src/ --fix",
@@ -42,7 +42,7 @@
42
42
  "test:watch": "vitest"
43
43
  },
44
44
  "dependencies": {
45
- "@likec4/core": "0.6.1",
45
+ "@likec4/core": "0.6.2",
46
46
  "json5": "^2.2.3",
47
47
  "langium": "^1.1.0",
48
48
  "rambdax": "^9.1.0"
@@ -1,4 +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;
@@ -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
- import type { ComputedView } from '@likec4/core/types';
2
- export declare function generateD2<V extends ComputedView>({ nodes, edges }: V): string;
@@ -1,56 +0,0 @@
1
- import { CompositeGeneratorNode, NL, joinToNode, toString } from 'langium';
2
- import { isNil } from 'rambdax';
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 d2shape = ({ shape }) => {
9
- switch (shape) {
10
- case 'queue':
11
- case 'cylinder':
12
- case 'rectangle':
13
- case 'person': {
14
- return shape;
15
- }
16
- case 'storage': {
17
- return 'stored_data';
18
- }
19
- case 'browser': {
20
- return 'rectangle';
21
- }
22
- }
23
- };
24
- export function generateD2({ nodes, edges }) {
25
- const names = new Map();
26
- const printNode = (node, parentName) => {
27
- const name = nodeName(node);
28
- const fqnName = (parentName ? parentName + '.' : '') + name;
29
- names.set(node.id, fqnName);
30
- const label = node.title.replaceAll('\n', '\\n');
31
- const shape = d2shape(node);
32
- return new CompositeGeneratorNode()
33
- .append(name, ': {', NL)
34
- .indent({
35
- indentedChildren: indent => indent
36
- .append('label: "', label, '"', NL)
37
- .append('shape: ', shape, NL)
38
- .appendIf(node.children.length > 0, NL, joinToNode(nodes.filter(n => n.parent === node.id), n => printNode(n, fqnName))),
39
- indentation: 2
40
- })
41
- .append('}', NL);
42
- };
43
- // return `${names.get(edge.source)} -> ${names.get(edge.target)}${edge.label ? ': ' + edge.label : ''}`
44
- const printEdge = (edge) => {
45
- return new CompositeGeneratorNode()
46
- .append(names.get(edge.source), ' -> ', names.get(edge.target))
47
- .append(out => edge.label && out.append(': ', edge.label.replaceAll('\n', '\\n')));
48
- };
49
- return toString(new CompositeGeneratorNode()
50
- .append(joinToNode(nodes.filter(n => isNil(n.parent)), n => printNode(n), {
51
- appendNewLineIfNotEmpty: true
52
- }))
53
- .appendIf(edges.length > 0, NL, joinToNode(edges, e => printEdge(e), {
54
- appendNewLineIfNotEmpty: true
55
- })));
56
- }
@@ -1 +0,0 @@
1
- export {};
@@ -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 +0,0 @@
1
- export * from './generate-d2';
package/dist/d2/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './generate-d2';
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { generateReact } from './react/generate-react';
2
- export { generateD2 } from './d2/generate-d2';
3
- export { generateViewsDataTs } from './views-data-ts/generate-views-data';
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { generateReact } from './react/generate-react';
2
- export { generateD2 } from './d2/generate-d2';
3
- export { generateViewsDataTs } from './views-data-ts/generate-views-data';
@@ -1,2 +0,0 @@
1
- import type { DiagramView } from '@likec4/core/types';
2
- export declare function generateReact(views: DiagramView[]): string;
@@ -1,79 +0,0 @@
1
- import JSON5 from 'json5';
2
- import { CompositeGeneratorNode, NL, expandToNode, joinToNode, toString } from 'langium';
3
- const componentName = (value) => {
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
- };
10
- export function generateReact(views) {
11
- const components = views.map(({ id }) => {
12
- return {
13
- id,
14
- name: componentName(id)
15
- };
16
- });
17
- const out = new CompositeGeneratorNode();
18
- out.appendTemplate `
19
- /******************************************************************************
20
- * This file was generated
21
- * DO NOT EDIT MANUALLY!
22
- ******************************************************************************/
23
- /* eslint-disable */
24
-
25
- import type { DiagramView, EmbeddedDiagramProps } from '@likec4/diagrams'
26
- import { EmbeddedDiagram } from '@likec4/diagrams'
27
- import '@likec4/diagrams/dist/index.css'
28
- `.append(NL, NL);
29
- if (components.length == 0) {
30
- out.append('export {}', NL);
31
- return toString(out);
32
- }
33
- out
34
- .append('export const LikeC4ViewsData = {', NL)
35
- .indent({
36
- indentation: 2,
37
- indentedChildren: indent => {
38
- indent.append(joinToNode(views, view => expandToNode `'${view.id}': (${JSON5.stringify(view)} as unknown) as DiagramView`, {
39
- separator: ',',
40
- appendNewLineIfNotEmpty: true
41
- }));
42
- }
43
- })
44
- .append('} as const', NL, NL).appendTemplate `
45
- export type LikeC4ViewsData = typeof LikeC4ViewsData
46
- export type ViewId = keyof LikeC4ViewsData
47
- export function isViewId(value: unknown): value is ViewId {
48
- return typeof value === 'string' && value in LikeC4ViewsData
49
- }
50
-
51
- export type LikeC4ViewProps = Omit<EmbeddedDiagramProps<LikeC4ViewsData, ViewId>, 'views'>;
52
- export function LikeC4View(props: LikeC4ViewProps) {
53
- return <EmbeddedDiagram views={LikeC4ViewsData} {...props}/>
54
- }
55
-
56
- type LikeC4ViewsProps = Omit<EmbeddedDiagramProps<LikeC4ViewsData, ViewId>, 'views' | 'viewId'>
57
- export const LikeC4Views = {
58
- `
59
- .append(NL)
60
- .indent({
61
- indentation: 2,
62
- indentedChildren: components.map(({ id, name }) => expandToNode `
63
- ['${name}']: (props: LikeC4ViewsProps) => <LikeC4View viewId={'${id}'} {...props}/>,
64
- `.append(NL))
65
- // indentedChildren: [joinToNode(
66
- // components,
67
- // ({ id, name }) =>
68
- // expandToNode`
69
- // ['${name}']: (props: NamedViewProps) => <EmbeddedDiagram views={LikeC4ViewsData} viewId={'${id}'} {...props}/>
70
- // `,
71
- // {
72
- // separator: ',',
73
- // appendNewLineIfNotEmpty: true
74
- // }
75
- // )],
76
- })
77
- .append('} as const', NL, NL);
78
- return toString(out);
79
- }
@@ -1 +0,0 @@
1
- export {};
@@ -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 +0,0 @@
1
- export * from './generate-react';
@@ -1 +0,0 @@
1
- export * from './generate-react';
@@ -1,2 +0,0 @@
1
- import type { DiagramView } from '@likec4/core/types';
2
- export declare function generateViewsDataTs(views: DiagramView[]): string;
@@ -1,33 +0,0 @@
1
- import JSON5 from 'json5';
2
- import { CompositeGeneratorNode, NL, expandToNode, joinToNode, toString } from 'langium';
3
- export function generateViewsDataTs(views) {
4
- const out = new CompositeGeneratorNode();
5
- out.appendTemplate `
6
- /******************************************************************************
7
- * This file was generated
8
- * DO NOT EDIT MANUALLY!
9
- ******************************************************************************/
10
- /* eslint-disable */
11
-
12
- import type { DiagramView } from '@likec4/diagrams'
13
- `.append(NL, NL);
14
- out
15
- .append('export const LikeC4ViewsData = {', NL)
16
- .indent({
17
- indentation: 2,
18
- indentedChildren: indent => {
19
- indent.append(joinToNode(views, view => expandToNode `'${view.id}': (${JSON5.stringify(view)} as unknown) as DiagramView`, {
20
- separator: ',',
21
- appendNewLineIfNotEmpty: true
22
- }));
23
- }
24
- })
25
- .append('} as const', NL, NL).appendTemplate `
26
- export type LikeC4ViewsData = typeof LikeC4ViewsData
27
- export type ViewId = keyof LikeC4ViewsData
28
- export function isViewId(value: unknown): value is ViewId {
29
- return typeof value === 'string' && value in LikeC4ViewsData
30
- }
31
- `.append(NL);
32
- return toString(out);
33
- }
@@ -1 +0,0 @@
1
- export {};
@@ -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
- });
@@ -1 +0,0 @@
1
- export * from './generate-views-data';
@@ -1 +0,0 @@
1
- export * from './generate-views-data';