@likec4/generators 0.6.3 → 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.
- package/dist/d2/generate-d2.d.ts +2 -1
- package/dist/d2/generate-d2.js +22 -3
- package/dist/d2/index.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/react/generate-react.d.ts +1 -0
- package/dist/react/generate-react.js +5 -6
- package/dist/react/index.d.ts +1 -0
- package/dist/views-data-ts/generate-views-data.d.ts +1 -0
- package/dist/views-data-ts/generate-views-data.js +3 -3
- package/dist/views-data-ts/index.d.ts +1 -0
- package/package.json +15 -29
package/dist/d2/generate-d2.d.ts
CHANGED
package/dist/d2/generate-d2.js
CHANGED
|
@@ -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(
|
|
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);
|
|
@@ -34,7 +52,7 @@ export function generateD2({ nodes, edges }) {
|
|
|
34
52
|
.indent({
|
|
35
53
|
indentedChildren: indent => indent
|
|
36
54
|
.append('label: "', label, '"', NL)
|
|
37
|
-
.
|
|
55
|
+
.appendIf(shape !== 'rectangle', 'shape: ', shape, NL)
|
|
38
56
|
.appendIf(node.children.length > 0, NL, joinToNode(nodes.filter(n => n.parent === node.id), n => printNode(n, fqnName))),
|
|
39
57
|
indentation: 2
|
|
40
58
|
})
|
|
@@ -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
|
}))
|
package/dist/d2/index.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -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;
|
|
@@ -24,7 +24,6 @@ export function generateReact(views) {
|
|
|
24
24
|
|
|
25
25
|
import type { DiagramView, EmbeddedDiagramProps } from '@likec4/diagrams'
|
|
26
26
|
import { EmbeddedDiagram } from '@likec4/diagrams'
|
|
27
|
-
import '@likec4/diagrams/dist/index.css'
|
|
28
27
|
`.append(NL, NL);
|
|
29
28
|
if (components.length == 0) {
|
|
30
29
|
out.append('export {}', NL);
|
|
@@ -43,17 +42,17 @@ export function generateReact(views) {
|
|
|
43
42
|
})
|
|
44
43
|
.append('} as const', NL, NL).appendTemplate `
|
|
45
44
|
export type LikeC4ViewsData = typeof LikeC4ViewsData
|
|
46
|
-
export type
|
|
47
|
-
export function
|
|
45
|
+
export type LikeC4ViewId = keyof LikeC4ViewsData
|
|
46
|
+
export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
|
|
48
47
|
return typeof value === 'string' && value in LikeC4ViewsData
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
export type LikeC4ViewProps = Omit<EmbeddedDiagramProps<LikeC4ViewsData,
|
|
50
|
+
export type LikeC4ViewProps = Omit<EmbeddedDiagramProps<LikeC4ViewsData, LikeC4ViewId>, 'views'>;
|
|
52
51
|
export function LikeC4View(props: LikeC4ViewProps) {
|
|
53
52
|
return <EmbeddedDiagram views={LikeC4ViewsData} {...props}/>
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
type LikeC4ViewsProps = Omit<EmbeddedDiagramProps<LikeC4ViewsData,
|
|
55
|
+
type LikeC4ViewsProps = Omit<EmbeddedDiagramProps<LikeC4ViewsData, LikeC4ViewId>, 'views' | 'viewId'>
|
|
57
56
|
export const LikeC4Views = {
|
|
58
57
|
`
|
|
59
58
|
.append(NL)
|
package/dist/react/index.d.ts
CHANGED
|
@@ -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 `
|
|
@@ -24,8 +24,8 @@ export function generateViewsDataTs(views) {
|
|
|
24
24
|
})
|
|
25
25
|
.append('} as const', NL, NL).appendTemplate `
|
|
26
26
|
export type LikeC4ViewsData = typeof LikeC4ViewsData
|
|
27
|
-
export type
|
|
28
|
-
export function
|
|
27
|
+
export type LikeC4ViewId = keyof LikeC4ViewsData
|
|
28
|
+
export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
|
|
29
29
|
return typeof value === 'string' && value in LikeC4ViewsData
|
|
30
30
|
}
|
|
31
31
|
`.append(NL);
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/generators",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
|
-
"homepage": "https://
|
|
6
|
+
"homepage": "https://likec4.dev",
|
|
7
7
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"!dist/__mocks__/**",
|
|
11
|
+
"!**/*.spec.*",
|
|
12
|
+
"!**/*.map"
|
|
10
13
|
],
|
|
11
14
|
"repository": {
|
|
12
15
|
"type": "git",
|
|
@@ -14,6 +17,7 @@
|
|
|
14
17
|
"directory": "packages/generators"
|
|
15
18
|
},
|
|
16
19
|
"main": "./dist/index.js",
|
|
20
|
+
"module": "./dist/index.js",
|
|
17
21
|
"types": "./dist/index.d.ts",
|
|
18
22
|
"type": "module",
|
|
19
23
|
"sideEffects": false,
|
|
@@ -22,43 +26,25 @@
|
|
|
22
26
|
"access": "public",
|
|
23
27
|
"main": "./dist/index.js",
|
|
24
28
|
"module": "./dist/index.js",
|
|
25
|
-
"types": "./dist/index.d.ts"
|
|
26
|
-
"exports": {
|
|
27
|
-
".": {
|
|
28
|
-
"types": "./dist/index.d.ts",
|
|
29
|
-
"import": "./dist/index.js",
|
|
30
|
-
"default": "./dist/index.js"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
29
|
+
"types": "./dist/index.d.ts"
|
|
33
30
|
},
|
|
34
31
|
"scripts": {
|
|
35
|
-
"compile": "tsc --
|
|
36
|
-
"build:release": "tsc -p tsconfig.esm.json",
|
|
32
|
+
"compile": "tsc --noEmit",
|
|
37
33
|
"build": "tsc",
|
|
38
34
|
"dev": "tsc --watch",
|
|
39
35
|
"lint": "run -T eslint src/ --fix",
|
|
40
36
|
"clean": "run -T rimraf dist",
|
|
41
|
-
"test": "vitest run",
|
|
42
|
-
"test:watch": "vitest"
|
|
37
|
+
"test": "run -T vitest run",
|
|
38
|
+
"test:watch": "run -T vitest"
|
|
43
39
|
},
|
|
44
40
|
"dependencies": {
|
|
45
|
-
"@likec4/core": "0.
|
|
41
|
+
"@likec4/core": "0.18.0",
|
|
46
42
|
"json5": "^2.2.3",
|
|
47
|
-
"langium": "^1.
|
|
48
|
-
"rambdax": "^9.1.
|
|
43
|
+
"langium": "^1.2.0",
|
|
44
|
+
"rambdax": "^9.1.1"
|
|
49
45
|
},
|
|
50
46
|
"devDependencies": {
|
|
51
47
|
"@types/node": "^18.15.11",
|
|
52
|
-
"typescript": "^5.
|
|
53
|
-
"vite": "^4.2.2",
|
|
54
|
-
"vitest": "^0.30.1"
|
|
55
|
-
},
|
|
56
|
-
"module": "./dist/index.js",
|
|
57
|
-
"exports": {
|
|
58
|
-
".": {
|
|
59
|
-
"types": "./dist/index.d.ts",
|
|
60
|
-
"import": "./dist/index.js",
|
|
61
|
-
"default": "./dist/index.js"
|
|
62
|
-
}
|
|
48
|
+
"typescript": "^5.1.3"
|
|
63
49
|
}
|
|
64
50
|
}
|