@likec4/generators 1.41.0 → 1.42.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,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RichText
|
|
3
|
-
} from "@likec4/core/types";
|
|
1
|
+
import { RichText } from "@likec4/core/types";
|
|
4
2
|
import { CompositeGeneratorNode, joinToNode, NL, toString } from "langium/generate";
|
|
5
3
|
import { isNullish as isNil } from "remeda";
|
|
6
4
|
const capitalizeFirstLetter = (value) => value.charAt(0).toLocaleUpperCase() + value.slice(1);
|
|
@@ -9,41 +7,10 @@ const nodeName = (node) => {
|
|
|
9
7
|
return fqnName(node.parent ? node.id.slice(node.parent.length + 1) : node.id);
|
|
10
8
|
};
|
|
11
9
|
const pumlColor = (color, customColorProvider, defaultColor = "#3b82f6") => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
case "primary": {
|
|
15
|
-
return "#3b82f6";
|
|
16
|
-
}
|
|
17
|
-
case "amber": {
|
|
18
|
-
return "#a35829";
|
|
19
|
-
}
|
|
20
|
-
case "gray": {
|
|
21
|
-
return "#737373";
|
|
22
|
-
}
|
|
23
|
-
case "green": {
|
|
24
|
-
return "#428a4f";
|
|
25
|
-
}
|
|
26
|
-
case "indigo": {
|
|
27
|
-
return "#6366f1";
|
|
28
|
-
}
|
|
29
|
-
case "slate":
|
|
30
|
-
case "muted": {
|
|
31
|
-
return "#64748b";
|
|
32
|
-
}
|
|
33
|
-
case "red": {
|
|
34
|
-
return "#ac4d39";
|
|
35
|
-
}
|
|
36
|
-
case "sky":
|
|
37
|
-
case "secondary": {
|
|
38
|
-
return "#0284c7";
|
|
39
|
-
}
|
|
40
|
-
case null:
|
|
41
|
-
case void 0: {
|
|
42
|
-
return defaultColor;
|
|
43
|
-
}
|
|
44
|
-
default:
|
|
45
|
-
return customColorProvider(color) || color;
|
|
10
|
+
if (color) {
|
|
11
|
+
return customColorProvider(color) ?? defaultColor;
|
|
46
12
|
}
|
|
13
|
+
return defaultColor;
|
|
47
14
|
};
|
|
48
15
|
const pumlDirection = ({ autoLayout }) => {
|
|
49
16
|
switch (autoLayout.direction) {
|
|
@@ -83,11 +50,10 @@ const pumlShape = ({ shape }) => {
|
|
|
83
50
|
const escapeLabel = (label) => isNil(label) ? null : JSON.stringify(label).slice(1, -1);
|
|
84
51
|
export function generatePuml(viewmodel) {
|
|
85
52
|
const view = viewmodel.$view;
|
|
86
|
-
const
|
|
53
|
+
const colors = viewmodel.$model.$styles.theme.colors;
|
|
87
54
|
const { nodes, edges } = view;
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const relationshipsColorProvider = (key) => (colorKey) => customColors.get(colorKey)?.relationships[key];
|
|
55
|
+
const elemntColorProvider = (key) => (colorKey) => colorKey in colors ? colors[colorKey].elements[key] : void 0;
|
|
56
|
+
const relationshipsColorProvider = (key) => (colorKey) => colorKey in colors ? colors[colorKey].relationships[key] : void 0;
|
|
91
57
|
const names = /* @__PURE__ */ new Map();
|
|
92
58
|
const printHeader = () => {
|
|
93
59
|
return new CompositeGeneratorNode().append('title "', view.title || view.id, '"', NL).append(pumlDirection(view), " direction", NL);
|
|
@@ -104,7 +70,7 @@ export function generatePuml(viewmodel) {
|
|
|
104
70
|
return new CompositeGeneratorNode().append("skinparam ", shape, "<<", fqn, ">>", "{", NL).indent({
|
|
105
71
|
indentedChildren: (indent) => indent.append("BackgroundColor ", pumlColor(node.color, elemntColorProvider("fill")), NL).append(
|
|
106
72
|
"FontColor ",
|
|
107
|
-
|
|
73
|
+
pumlColor(node.color, elemntColorProvider("hiContrast"), "#FFFFFF"),
|
|
108
74
|
NL
|
|
109
75
|
).append("BorderColor ", pumlColor(node.color, elemntColorProvider("stroke")), NL),
|
|
110
76
|
indentation: 2
|
|
@@ -148,7 +114,7 @@ export function generatePuml(viewmodel) {
|
|
|
148
114
|
const printEdge = (edge) => {
|
|
149
115
|
const tech = escapeLabel(edge.technology) || "";
|
|
150
116
|
const label = escapeLabel(edge.label) || "";
|
|
151
|
-
const color = pumlColor(edge.color, relationshipsColorProvider("
|
|
117
|
+
const color = pumlColor(edge.color, relationshipsColorProvider("line"), "#777777");
|
|
152
118
|
const colorTag = (color2) => `<color:${color2}>`;
|
|
153
119
|
return new CompositeGeneratorNode().append(names.get(edge.source), " .[", color, ",thickness=2].> ", names.get(edge.target)).appendIf(!!(label || tech), ' : "', colorTag(color)).appendIf(!!label, label, colorTag(color)).appendIf(!!(label && tech), "\\n").appendIf(!!tech, colorTag(color), "<size:8>[", tech, "]</size>").appendIf(!!(label || tech), '"').append(NL);
|
|
154
120
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/generators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.42.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
@@ -38,22 +38,25 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"json5": "^2.2.3",
|
|
40
40
|
"langium": "3.5.0",
|
|
41
|
-
"remeda": "^2.
|
|
42
|
-
"@likec4/core": "1.
|
|
41
|
+
"remeda": "^2.31.1",
|
|
42
|
+
"@likec4/core": "1.42.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/node": "~20.19.11",
|
|
46
46
|
"typescript": "5.9.2",
|
|
47
47
|
"unbuild": "3.5.0",
|
|
48
48
|
"vitest": "3.2.4",
|
|
49
|
-
"@likec4/tsconfig": "1.
|
|
49
|
+
"@likec4/tsconfig": "1.42.0",
|
|
50
|
+
"@likec4/devops": "1.42.0"
|
|
50
51
|
},
|
|
51
52
|
"scripts": {
|
|
52
53
|
"typecheck": "tsc -b --verbose",
|
|
53
54
|
"build": "unbuild",
|
|
54
55
|
"lint": "run -T eslint src/ --fix",
|
|
55
|
-
"clean": "
|
|
56
|
+
"clean": "likec4ops clean",
|
|
56
57
|
"test": "vitest run --no-isolate",
|
|
57
58
|
"test:watch": "vitest"
|
|
58
|
-
}
|
|
59
|
+
},
|
|
60
|
+
"types": "dist/index.d.ts",
|
|
61
|
+
"module": "dist/index.js"
|
|
59
62
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import type { LikeC4ViewModel } from '@likec4/core/model'
|
|
2
|
+
import type {
|
|
3
|
+
aux,
|
|
4
|
+
Color,
|
|
5
|
+
ComputedEdge,
|
|
6
|
+
ComputedNode,
|
|
7
|
+
ElementColorValues,
|
|
8
|
+
KeysOf,
|
|
9
|
+
NodeId,
|
|
10
|
+
ProcessedView,
|
|
11
|
+
RelationshipColorValues,
|
|
12
|
+
ThemeColor,
|
|
12
13
|
} from '@likec4/core/types'
|
|
14
|
+
import { RichText } from '@likec4/core/types'
|
|
13
15
|
import { CompositeGeneratorNode, joinToNode, NL, toString } from 'langium/generate'
|
|
14
16
|
import { isNullish as isNil } from 'remeda'
|
|
15
17
|
|
|
@@ -22,45 +24,14 @@ const nodeName = (node: ComputedNode): string => {
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
const pumlColor = (
|
|
25
|
-
color:
|
|
26
|
-
customColorProvider: (colorKey:
|
|
27
|
+
color: Color | undefined,
|
|
28
|
+
customColorProvider: (colorKey: Color) => string | undefined,
|
|
27
29
|
defaultColor: string = '#3b82f6',
|
|
28
30
|
) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case 'primary': {
|
|
32
|
-
return '#3b82f6'
|
|
33
|
-
}
|
|
34
|
-
case 'amber': {
|
|
35
|
-
return '#a35829'
|
|
36
|
-
}
|
|
37
|
-
case 'gray': {
|
|
38
|
-
return '#737373'
|
|
39
|
-
}
|
|
40
|
-
case 'green': {
|
|
41
|
-
return '#428a4f'
|
|
42
|
-
}
|
|
43
|
-
case 'indigo': {
|
|
44
|
-
return '#6366f1'
|
|
45
|
-
}
|
|
46
|
-
case 'slate':
|
|
47
|
-
case 'muted': {
|
|
48
|
-
return '#64748b'
|
|
49
|
-
}
|
|
50
|
-
case 'red': {
|
|
51
|
-
return '#ac4d39'
|
|
52
|
-
}
|
|
53
|
-
case 'sky':
|
|
54
|
-
case 'secondary': {
|
|
55
|
-
return '#0284c7'
|
|
56
|
-
}
|
|
57
|
-
case null:
|
|
58
|
-
case undefined: {
|
|
59
|
-
return defaultColor
|
|
60
|
-
}
|
|
61
|
-
default:
|
|
62
|
-
return customColorProvider(color) || color
|
|
31
|
+
if (color) {
|
|
32
|
+
return customColorProvider(color) ?? defaultColor
|
|
63
33
|
}
|
|
34
|
+
return defaultColor
|
|
64
35
|
}
|
|
65
36
|
|
|
66
37
|
const pumlDirection = ({ autoLayout }: ProcessedView) => {
|
|
@@ -104,13 +75,14 @@ const escapeLabel = (label: string | null | undefined) => isNil(label) ? null :
|
|
|
104
75
|
|
|
105
76
|
export function generatePuml(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
106
77
|
const view = viewmodel.$view
|
|
107
|
-
const
|
|
78
|
+
const colors = viewmodel.$model.$styles.theme.colors
|
|
108
79
|
const { nodes, edges } = view
|
|
109
|
-
|
|
110
|
-
const elemntColorProvider = (key: KeysOf<
|
|
111
|
-
|
|
112
|
-
const relationshipsColorProvider = (key: KeysOf<
|
|
113
|
-
|
|
80
|
+
|
|
81
|
+
const elemntColorProvider = (key: KeysOf<ElementColorValues>) => (colorKey: Color) =>
|
|
82
|
+
colorKey in colors ? colors[colorKey as ThemeColor].elements[key] : undefined
|
|
83
|
+
const relationshipsColorProvider = (key: KeysOf<RelationshipColorValues>) => (colorKey: Color) =>
|
|
84
|
+
colorKey in colors ? colors[colorKey as ThemeColor].relationships[key] : undefined
|
|
85
|
+
|
|
114
86
|
const names = new Map<NodeId, string>()
|
|
115
87
|
|
|
116
88
|
const printHeader = () => {
|
|
@@ -150,9 +122,7 @@ export function generatePuml(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
|
150
122
|
.append('BackgroundColor ', pumlColor(node.color, elemntColorProvider('fill')), NL)
|
|
151
123
|
.append(
|
|
152
124
|
'FontColor ',
|
|
153
|
-
|
|
154
|
-
? pumlColor(node.color, elemntColorProvider('hiContrast'))
|
|
155
|
-
: '#FFFFFF',
|
|
125
|
+
pumlColor(node.color, elemntColorProvider('hiContrast'), '#FFFFFF'),
|
|
156
126
|
NL,
|
|
157
127
|
)
|
|
158
128
|
.append('BorderColor ', pumlColor(node.color, elemntColorProvider('stroke')), NL),
|
|
@@ -218,7 +188,7 @@ export function generatePuml(viewmodel: LikeC4ViewModel<aux.Unknown>) {
|
|
|
218
188
|
const printEdge = (edge: ComputedEdge): CompositeGeneratorNode => {
|
|
219
189
|
const tech = escapeLabel(edge.technology) || ''
|
|
220
190
|
const label = escapeLabel(edge.label) || ''
|
|
221
|
-
const color = pumlColor(edge.color, relationshipsColorProvider('
|
|
191
|
+
const color = pumlColor(edge.color, relationshipsColorProvider('line'), '#777777')
|
|
222
192
|
|
|
223
193
|
const colorTag = (color: string) => `<color:${color}>`
|
|
224
194
|
|