@likec4/generators 0.4.0 → 0.6.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.js +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/react/generate-react.js +6 -9
- package/dist/views-data-ts/generate-views-data.d.ts +2 -0
- package/dist/views-data-ts/generate-views-data.js +33 -0
- package/dist/views-data-ts/index.d.ts +1 -0
- package/dist/views-data-ts/index.js +1 -0
- package/package.json +18 -34
- package/dist/util.d.ts +0 -7
- package/dist/util.js +0 -11
package/dist/d2/generate-d2.js
CHANGED
|
@@ -32,7 +32,7 @@ export function generateD2({ nodes, edges }) {
|
|
|
32
32
|
return new CompositeGeneratorNode()
|
|
33
33
|
.append(name, ': {', NL)
|
|
34
34
|
.indent({
|
|
35
|
-
indentedChildren:
|
|
35
|
+
indentedChildren: indent => indent
|
|
36
36
|
.append('label: "', label, '"', NL)
|
|
37
37
|
.append('shape: ', shape, NL)
|
|
38
38
|
.appendIf(node.children.length > 0, NL, joinToNode(nodes.filter(n => n.parent === node.id), n => printNode(n, fqnName))),
|
|
@@ -48,9 +48,9 @@ export function generateD2({ nodes, edges }) {
|
|
|
48
48
|
};
|
|
49
49
|
return toString(new CompositeGeneratorNode()
|
|
50
50
|
.append(joinToNode(nodes.filter(n => isNil(n.parent)), n => printNode(n), {
|
|
51
|
-
appendNewLineIfNotEmpty: true
|
|
51
|
+
appendNewLineIfNotEmpty: true
|
|
52
52
|
}))
|
|
53
53
|
.appendIf(edges.length > 0, NL, joinToNode(edges, e => printEdge(e), {
|
|
54
|
-
appendNewLineIfNotEmpty: true
|
|
54
|
+
appendNewLineIfNotEmpty: true
|
|
55
55
|
})));
|
|
56
56
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -11,12 +11,11 @@ export function generateReact(views) {
|
|
|
11
11
|
const components = views.map(({ id }) => {
|
|
12
12
|
return {
|
|
13
13
|
id,
|
|
14
|
-
name: componentName(id)
|
|
14
|
+
name: componentName(id)
|
|
15
15
|
};
|
|
16
16
|
});
|
|
17
17
|
const out = new CompositeGeneratorNode();
|
|
18
|
-
out
|
|
19
|
-
.appendTemplate `
|
|
18
|
+
out.appendTemplate `
|
|
20
19
|
/******************************************************************************
|
|
21
20
|
* This file was generated
|
|
22
21
|
* DO NOT EDIT MANUALLY!
|
|
@@ -26,8 +25,7 @@ export function generateReact(views) {
|
|
|
26
25
|
import type { DiagramView, EmbeddedDiagramProps } from '@likec4/diagrams'
|
|
27
26
|
import { EmbeddedDiagram } from '@likec4/diagrams'
|
|
28
27
|
import '@likec4/diagrams/dist/index.css'
|
|
29
|
-
|
|
30
|
-
.append(NL, NL);
|
|
28
|
+
`.append(NL, NL);
|
|
31
29
|
if (components.length == 0) {
|
|
32
30
|
out.append('export {}', NL);
|
|
33
31
|
return toString(out);
|
|
@@ -37,14 +35,13 @@ export function generateReact(views) {
|
|
|
37
35
|
.indent({
|
|
38
36
|
indentation: 2,
|
|
39
37
|
indentedChildren: indent => {
|
|
40
|
-
indent.append(joinToNode(views, view => expandToNode `'${view.id}': (${JSON5.stringify(view)} as
|
|
38
|
+
indent.append(joinToNode(views, view => expandToNode `'${view.id}': (${JSON5.stringify(view)} as unknown) as DiagramView`, {
|
|
41
39
|
separator: ',',
|
|
42
40
|
appendNewLineIfNotEmpty: true
|
|
43
41
|
}));
|
|
44
|
-
}
|
|
42
|
+
}
|
|
45
43
|
})
|
|
46
|
-
.append('} as const', NL, NL)
|
|
47
|
-
.appendTemplate `
|
|
44
|
+
.append('} as const', NL, NL).appendTemplate `
|
|
48
45
|
export type LikeC4ViewsData = typeof LikeC4ViewsData
|
|
49
46
|
export type ViewId = keyof LikeC4ViewsData
|
|
50
47
|
export function isViewId(value: unknown): value is ViewId {
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generate-views-data';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generate-views-data';
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/generators",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
5
6
|
"homepage": "https://like-c4.dev",
|
|
6
7
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
@@ -9,49 +10,24 @@
|
|
|
9
10
|
],
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/likec4/likec4.git"
|
|
13
|
+
"url": "https://github.com/likec4/likec4.git",
|
|
14
|
+
"directory": "packages/generators"
|
|
13
15
|
},
|
|
14
16
|
"main": "./dist/index.js",
|
|
15
17
|
"types": "./dist/index.d.ts",
|
|
16
18
|
"type": "module",
|
|
17
19
|
"sideEffects": false,
|
|
18
|
-
"exports": {
|
|
19
|
-
".": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
|
-
"import": "./dist/index.js",
|
|
22
|
-
"require": "./dist/index.cjs"
|
|
23
|
-
},
|
|
24
|
-
"./react": {
|
|
25
|
-
"types": "./dist/react/index.d.ts",
|
|
26
|
-
"import": "./dist/react/index.js",
|
|
27
|
-
"require": "./dist/react/index.cjs"
|
|
28
|
-
},
|
|
29
|
-
"./d2": {
|
|
30
|
-
"types": "./dist/d2/index.d.ts",
|
|
31
|
-
"import": "./dist/d2/index.js",
|
|
32
|
-
"require": "./dist/d2/index.cjs"
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
20
|
"publishConfig": {
|
|
36
21
|
"registry": "https://registry.npmjs.org",
|
|
37
22
|
"access": "public",
|
|
38
23
|
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.js",
|
|
39
25
|
"types": "./dist/index.d.ts",
|
|
40
26
|
"exports": {
|
|
41
27
|
".": {
|
|
42
28
|
"types": "./dist/index.d.ts",
|
|
43
29
|
"import": "./dist/index.js",
|
|
44
|
-
"
|
|
45
|
-
},
|
|
46
|
-
"./react": {
|
|
47
|
-
"types": "./dist/react/index.d.ts",
|
|
48
|
-
"import": "./dist/react/index.js",
|
|
49
|
-
"require": "./dist/react/index.cjs"
|
|
50
|
-
},
|
|
51
|
-
"./d2": {
|
|
52
|
-
"types": "./dist/d2/index.d.ts",
|
|
53
|
-
"import": "./dist/d2/index.js",
|
|
54
|
-
"require": "./dist/d2/index.cjs"
|
|
30
|
+
"default": "./dist/index.js"
|
|
55
31
|
}
|
|
56
32
|
}
|
|
57
33
|
},
|
|
@@ -61,20 +37,28 @@
|
|
|
61
37
|
"build": "tsc",
|
|
62
38
|
"dev": "tsc --watch",
|
|
63
39
|
"lint": "run -T eslint src/ --fix",
|
|
64
|
-
"clean": "rimraf dist",
|
|
40
|
+
"clean": "run -T rimraf dist",
|
|
65
41
|
"test": "vitest run",
|
|
66
42
|
"test:watch": "vitest"
|
|
67
43
|
},
|
|
68
44
|
"dependencies": {
|
|
69
|
-
"@likec4/core": "0.
|
|
45
|
+
"@likec4/core": "0.6.0",
|
|
70
46
|
"json5": "^2.2.3",
|
|
71
47
|
"langium": "^1.1.0",
|
|
72
48
|
"rambdax": "^9.1.0"
|
|
73
49
|
},
|
|
74
50
|
"devDependencies": {
|
|
75
51
|
"@types/node": "^18.15.11",
|
|
76
|
-
"typescript": "^5.0.
|
|
77
|
-
"vite": "^4.2.
|
|
52
|
+
"typescript": "^5.0.4",
|
|
53
|
+
"vite": "^4.2.2",
|
|
78
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
|
+
}
|
|
79
63
|
}
|
|
80
64
|
}
|
package/dist/util.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/******************************************************************************
|
|
2
|
-
* Copyright 2021 TypeFox GmbH
|
|
3
|
-
* This program and the accompanying materials are made available under the
|
|
4
|
-
* terms of the MIT License, which is available in the project root.
|
|
5
|
-
******************************************************************************/
|
|
6
|
-
import type { GeneratorNode } from 'langium';
|
|
7
|
-
export declare function generatedHeader(): GeneratorNode;
|
package/dist/util.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/******************************************************************************
|
|
2
|
-
* Copyright 2021 TypeFox GmbH
|
|
3
|
-
* This program and the accompanying materials are made available under the
|
|
4
|
-
* terms of the MIT License, which is available in the project root.
|
|
5
|
-
******************************************************************************/
|
|
6
|
-
import { CompositeGeneratorNode, NL } from 'langium';
|
|
7
|
-
export function generatedHeader() {
|
|
8
|
-
const node = new CompositeGeneratorNode();
|
|
9
|
-
node.contents.push('/******************************************************************************', NL, ' * This file was generated', NL, ' * DO NOT EDIT MANUALLY!', NL, ' ******************************************************************************/', NL, NL, '/* eslint-disable */', NL);
|
|
10
|
-
return node;
|
|
11
|
-
}
|