@likec4/generators 1.5.0 → 1.29.1
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/LICENSE +21 -0
- package/dist/d2/generate-d2.d.ts +1 -2
- package/dist/d2/generate-d2.js +70 -63
- package/dist/d2/index.d.ts +0 -1
- package/dist/d2/index.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -5
- package/dist/mmd/generate-mmd.d.ts +1 -2
- package/dist/mmd/generate-mmd.js +82 -63
- package/dist/mmd/index.d.ts +0 -1
- package/dist/mmd/index.js +1 -1
- package/dist/model/generate-likec4-model.d.ts +2 -0
- package/dist/model/generate-likec4-model.js +29 -0
- package/dist/model/generate-likec4.d.ts +2 -0
- package/dist/model/generate-likec4.js +2 -0
- package/dist/react/generate-react-types.d.ts +2 -0
- package/dist/react/generate-react-types.js +122 -0
- package/dist/react/index.d.ts +1 -2
- package/dist/react/index.js +1 -1
- package/dist/react-next/generate-react-next.d.ts +9 -7
- package/dist/react-next/generate-react-next.js +26 -26
- package/dist/react-next/index.d.ts +0 -1
- package/dist/react-next/index.js +1 -1
- package/dist/views-data-ts/generate-views-data.d.ts +3 -4
- package/dist/views-data-ts/generate-views-data.js +64 -54
- package/dist/views-data-ts/generateViewId.d.ts +1 -2
- package/dist/views-data-ts/generateViewId.js +5 -4
- package/dist/views-data-ts/index.d.ts +0 -1
- package/dist/views-data-ts/index.js +1 -1
- package/package.json +25 -27
- package/src/__mocks__/data.ts +463 -0
- package/src/d2/__snapshots__/generate-d2.spec.ts.snap +91 -0
- package/src/d2/generate-d2.spec.ts +15 -0
- package/src/d2/generate-d2.ts +106 -0
- package/src/d2/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/mmd/__snapshots__/generate-mmd.spec.ts.snap +55 -0
- package/src/mmd/generate-mmd.spec.ts +15 -0
- package/src/mmd/generate-mmd.ts +110 -0
- package/src/mmd/index.ts +1 -0
- package/src/model/__snapshots__/likec4-model.snap +990 -0
- package/src/model/generate-likec4-model.spec.ts +158 -0
- package/src/model/generate-likec4-model.ts +33 -0
- package/src/model/generate-likec4.ts +5 -0
- package/src/react/generate-react-types.ts +127 -0
- package/src/react/index.ts +1 -0
- package/src/react-next/generate-react-next.ts +111 -0
- package/src/react-next/index.ts +1 -0
- package/src/views-data-ts/__snapshots__/generate-views-data.spec.ts.snap +83 -0
- package/src/views-data-ts/generate-views-data.spec.ts +15 -0
- package/src/views-data-ts/generate-views-data.ts +147 -0
- package/src/views-data-ts/generateViewId.ts +9 -0
- package/src/views-data-ts/index.ts +1 -0
- package/dist/__mocks__/data.d.ts +0 -5
- package/dist/__mocks__/data.d.ts.map +0 -1
- package/dist/__mocks__/data.js +0 -456
- package/dist/d2/generate-d2.d.ts.map +0 -1
- package/dist/d2/generate-d2.spec.d.ts +0 -2
- package/dist/d2/generate-d2.spec.d.ts.map +0 -1
- package/dist/d2/generate-d2.spec.js +0 -12
- package/dist/d2/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mmd/generate-mmd.d.ts.map +0 -1
- package/dist/mmd/generate-mmd.spec.d.ts +0 -2
- package/dist/mmd/generate-mmd.spec.d.ts.map +0 -1
- package/dist/mmd/generate-mmd.spec.js +0 -12
- package/dist/mmd/index.d.ts.map +0 -1
- package/dist/react/generate-react.d.ts +0 -3
- package/dist/react/generate-react.d.ts.map +0 -1
- package/dist/react/generate-react.js +0 -97
- package/dist/react/generate-react.spec.d.ts +0 -2
- package/dist/react/generate-react.spec.d.ts.map +0 -1
- package/dist/react/generate-react.spec.js +0 -6
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react-next/generate-react-next.d.ts.map +0 -1
- package/dist/react-next/generate-react-next.spec.d.ts +0 -2
- package/dist/react-next/generate-react-next.spec.d.ts.map +0 -1
- package/dist/react-next/generate-react-next.spec.js +0 -9
- package/dist/react-next/index.d.ts.map +0 -1
- package/dist/views-data-ts/generate-views-data.d.ts.map +0 -1
- package/dist/views-data-ts/generate-views-data.spec.d.ts +0 -2
- package/dist/views-data-ts/generate-views-data.spec.d.ts.map +0 -1
- package/dist/views-data-ts/generate-views-data.spec.js +0 -12
- package/dist/views-data-ts/generateViewId.d.ts.map +0 -1
- package/dist/views-data-ts/index.d.ts.map +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { LikeC4Model } from '@likec4/core'
|
|
2
|
+
import { Builder } from '@likec4/core/builder'
|
|
3
|
+
import { computeViews, viewsWithReadableEdges } from '@likec4/core/compute-view'
|
|
4
|
+
import { describe, it } from 'vitest'
|
|
5
|
+
import { generateLikeC4Model } from './generate-likec4-model'
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
builder: b,
|
|
9
|
+
model: {
|
|
10
|
+
model,
|
|
11
|
+
person,
|
|
12
|
+
system,
|
|
13
|
+
component,
|
|
14
|
+
webapp,
|
|
15
|
+
mobile,
|
|
16
|
+
...$m
|
|
17
|
+
},
|
|
18
|
+
deployment: {
|
|
19
|
+
deployment,
|
|
20
|
+
env,
|
|
21
|
+
node,
|
|
22
|
+
zone,
|
|
23
|
+
instanceOf,
|
|
24
|
+
...$d
|
|
25
|
+
},
|
|
26
|
+
views: {
|
|
27
|
+
view,
|
|
28
|
+
views,
|
|
29
|
+
viewOf,
|
|
30
|
+
deploymentView,
|
|
31
|
+
$rules,
|
|
32
|
+
$include,
|
|
33
|
+
$exclude,
|
|
34
|
+
$style,
|
|
35
|
+
},
|
|
36
|
+
} = Builder.forSpecification({
|
|
37
|
+
elements: {
|
|
38
|
+
person: {
|
|
39
|
+
style: {
|
|
40
|
+
shape: 'person',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
system: {},
|
|
44
|
+
component: {},
|
|
45
|
+
webapp: {
|
|
46
|
+
style: {
|
|
47
|
+
shape: 'browser',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
mobile: {
|
|
51
|
+
style: {
|
|
52
|
+
shape: 'mobile',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
deployments: {
|
|
57
|
+
env: {},
|
|
58
|
+
zone: {},
|
|
59
|
+
node: {},
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const builder = b
|
|
64
|
+
.with(
|
|
65
|
+
model(
|
|
66
|
+
person('customer'),
|
|
67
|
+
system('cloud').with(
|
|
68
|
+
component('frontend').with(
|
|
69
|
+
webapp('dashboard'),
|
|
70
|
+
mobile('mobile'),
|
|
71
|
+
),
|
|
72
|
+
component('auth'),
|
|
73
|
+
component('backend').with(
|
|
74
|
+
component('api'),
|
|
75
|
+
component('graphql'),
|
|
76
|
+
),
|
|
77
|
+
component('media', {
|
|
78
|
+
shape: 'storage',
|
|
79
|
+
}),
|
|
80
|
+
),
|
|
81
|
+
system('aws').with(
|
|
82
|
+
component('rds', {
|
|
83
|
+
shape: 'storage',
|
|
84
|
+
}),
|
|
85
|
+
component('s3', {
|
|
86
|
+
shape: 'storage',
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
system('email'),
|
|
90
|
+
),
|
|
91
|
+
model(
|
|
92
|
+
$m.rel('customer', 'cloud', 'uses services'),
|
|
93
|
+
$m.rel('customer', 'cloud.frontend.mobile', 'opens mobile app'),
|
|
94
|
+
$m.rel('customer', 'cloud.frontend.dashboard', 'opens in browser'),
|
|
95
|
+
$m.rel('cloud.frontend.dashboard', 'cloud.auth', 'authenticates'),
|
|
96
|
+
$m.rel('cloud.frontend.dashboard', 'cloud.backend.api', 'fetches data'),
|
|
97
|
+
$m.rel('cloud.frontend.dashboard', 'cloud.media', 'fetches media'),
|
|
98
|
+
$m.rel('cloud.frontend.mobile', 'cloud.auth', 'authenticates'),
|
|
99
|
+
$m.rel('cloud.frontend.mobile', 'cloud.backend.api', 'fetches data'),
|
|
100
|
+
$m.rel('cloud.frontend.mobile', 'cloud.media', 'fetches media'),
|
|
101
|
+
$m.rel('cloud.backend.api', 'cloud.auth', 'authorizes'),
|
|
102
|
+
$m.rel('cloud.backend.api', 'cloud.media', 'uploads media'),
|
|
103
|
+
$m.rel('cloud.backend.api', 'aws.rds', 'reads/writes'),
|
|
104
|
+
$m.rel('cloud.backend.api', 'email', 'sends emails'),
|
|
105
|
+
$m.rel('cloud.media', 'aws.s3', 'uploads'),
|
|
106
|
+
$m.rel('email', 'customer', 'sends emails'),
|
|
107
|
+
),
|
|
108
|
+
deployment(
|
|
109
|
+
node('customer').with(
|
|
110
|
+
instanceOf('instance', 'customer'),
|
|
111
|
+
),
|
|
112
|
+
env('prod').with(
|
|
113
|
+
zone('eu').with(
|
|
114
|
+
zone('zone1').with(
|
|
115
|
+
instanceOf('ui', 'cloud.frontend.dashboard'),
|
|
116
|
+
instanceOf('api', 'cloud.backend.api'),
|
|
117
|
+
),
|
|
118
|
+
zone('zone2').with(
|
|
119
|
+
instanceOf('ui', 'cloud.frontend.dashboard'),
|
|
120
|
+
instanceOf('api', 'cloud.backend.api'),
|
|
121
|
+
),
|
|
122
|
+
instanceOf('media', 'cloud.media'),
|
|
123
|
+
instanceOf('db', 'aws.rds'),
|
|
124
|
+
),
|
|
125
|
+
zone('us').with(
|
|
126
|
+
instanceOf('db', 'aws.rds'),
|
|
127
|
+
),
|
|
128
|
+
),
|
|
129
|
+
$d.rel('prod.eu.db', 'prod.us.db', 'replicates'),
|
|
130
|
+
),
|
|
131
|
+
views(
|
|
132
|
+
view('index', $include('*')),
|
|
133
|
+
viewOf(
|
|
134
|
+
'cloud',
|
|
135
|
+
'cloud',
|
|
136
|
+
$rules(
|
|
137
|
+
$include('*'),
|
|
138
|
+
$include('cloud.frontend.dashboard'),
|
|
139
|
+
),
|
|
140
|
+
),
|
|
141
|
+
deploymentView(
|
|
142
|
+
'prod',
|
|
143
|
+
'prod',
|
|
144
|
+
$rules(
|
|
145
|
+
$include('customer.instance'),
|
|
146
|
+
$include('prod.eu.zone1.ui'),
|
|
147
|
+
),
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
)
|
|
151
|
+
const computed = viewsWithReadableEdges(computeViews(builder.build()))
|
|
152
|
+
const m = LikeC4Model.create(computed)
|
|
153
|
+
|
|
154
|
+
describe('generateLikeC4Model', () => {
|
|
155
|
+
it('should generate', async ({ expect }) => {
|
|
156
|
+
await expect(generateLikeC4Model(m)).toMatchFileSnapshot('__snapshots__/likec4-model.snap')
|
|
157
|
+
})
|
|
158
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type LikeC4Model } from '@likec4/core'
|
|
2
|
+
import JSON5 from 'json5'
|
|
3
|
+
import { CompositeGeneratorNode, toString } from 'langium/generate'
|
|
4
|
+
|
|
5
|
+
export function generateLikeC4Model(model: LikeC4Model) {
|
|
6
|
+
const out = new CompositeGeneratorNode()
|
|
7
|
+
out.appendTemplate`
|
|
8
|
+
/* prettier-ignore-start */
|
|
9
|
+
/* eslint-disable */
|
|
10
|
+
|
|
11
|
+
/******************************************************************************
|
|
12
|
+
* This file was generated
|
|
13
|
+
* DO NOT EDIT MANUALLY!
|
|
14
|
+
******************************************************************************/
|
|
15
|
+
|
|
16
|
+
import { LikeC4Model } from 'likec4/model'
|
|
17
|
+
|
|
18
|
+
export const likeC4Model = LikeC4Model.fromDump(${
|
|
19
|
+
JSON5.stringify(model.$model, {
|
|
20
|
+
space: 2,
|
|
21
|
+
quote: '\'',
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export type LikeC4ModelTypes = typeof likeC4Model.Aux
|
|
26
|
+
export type LikeC4ElementId = LikeC4ModelTypes['Fqn']
|
|
27
|
+
export type LikeC4DeploymentId = LikeC4ModelTypes['Deployment']
|
|
28
|
+
export type LikeC4ViewId = LikeC4ModelTypes['ViewId']
|
|
29
|
+
|
|
30
|
+
/* prettier-ignore-end */
|
|
31
|
+
`
|
|
32
|
+
return toString(out)
|
|
33
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { LikeC4Model } from '@likec4/core'
|
|
2
|
+
import { compareNatural, sortNaturalByFqn } from '@likec4/core'
|
|
3
|
+
|
|
4
|
+
function toUnion(unionset: string[] | Set<string>) {
|
|
5
|
+
if (unionset instanceof Set) {
|
|
6
|
+
unionset = [...unionset].sort(compareNatural)
|
|
7
|
+
}
|
|
8
|
+
const union = unionset.map(v => ` | ${JSON.stringify(v)}`)
|
|
9
|
+
if (union.length === 0) {
|
|
10
|
+
union.push(' never')
|
|
11
|
+
}
|
|
12
|
+
return union.join('\n') + ';'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function generateReactTypes(model: LikeC4Model.Layouted) {
|
|
16
|
+
const {
|
|
17
|
+
fqns,
|
|
18
|
+
tags,
|
|
19
|
+
kinds,
|
|
20
|
+
} = sortNaturalByFqn([...model.elements()]).reduce((acc, d) => {
|
|
21
|
+
acc.fqns.push(d.id)
|
|
22
|
+
acc.kinds.add(d.kind)
|
|
23
|
+
acc.tags.push(...d.tags)
|
|
24
|
+
return acc
|
|
25
|
+
}, {
|
|
26
|
+
fqns: [] as string[],
|
|
27
|
+
kinds: new Set<string>(),
|
|
28
|
+
tags: [] as string[],
|
|
29
|
+
})
|
|
30
|
+
const deploymentFqns = sortNaturalByFqn([...model.deployment.elements()]).map((e) => e.id)
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
viewIds,
|
|
34
|
+
} = [...model.views()].reduce((acc, d) => {
|
|
35
|
+
acc.viewIds.add(d.id)
|
|
36
|
+
acc.tags.push(...d.tags)
|
|
37
|
+
acc.tags.push(...d.includedTags)
|
|
38
|
+
return acc
|
|
39
|
+
}, {
|
|
40
|
+
viewIds: new Set<string>(),
|
|
41
|
+
tags,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return `
|
|
45
|
+
/* prettier-ignore-start */
|
|
46
|
+
/* eslint-disable */
|
|
47
|
+
|
|
48
|
+
/******************************************************************************
|
|
49
|
+
* This file was generated
|
|
50
|
+
* DO NOT EDIT MANUALLY!
|
|
51
|
+
******************************************************************************/
|
|
52
|
+
|
|
53
|
+
import type { PropsWithChildren } from 'react'
|
|
54
|
+
import type { JSX } from 'react/jsx-runtime'
|
|
55
|
+
import type {
|
|
56
|
+
DiagramView,
|
|
57
|
+
LikeC4Model as GenericLikeC4Model,
|
|
58
|
+
} from 'likec4/model'
|
|
59
|
+
import type {
|
|
60
|
+
LikeC4ViewProps as GenericLikeC4ViewProps,
|
|
61
|
+
ReactLikeC4Props as GenericReactLikeC4Props
|
|
62
|
+
} from 'likec4/react'
|
|
63
|
+
|
|
64
|
+
type LikeC4ElementId =
|
|
65
|
+
${toUnion(fqns)}
|
|
66
|
+
|
|
67
|
+
type LikeC4DeploymentId =
|
|
68
|
+
${toUnion(deploymentFqns)}
|
|
69
|
+
|
|
70
|
+
type LikeC4ViewId =
|
|
71
|
+
${toUnion(viewIds)}
|
|
72
|
+
|
|
73
|
+
type LikeC4ElementKind =
|
|
74
|
+
${toUnion(kinds)}
|
|
75
|
+
|
|
76
|
+
type LikeC4Tag =
|
|
77
|
+
${toUnion(new Set(tags))}
|
|
78
|
+
|
|
79
|
+
declare function isLikeC4ViewId(value: unknown): value is LikeC4ViewId;
|
|
80
|
+
|
|
81
|
+
type Aux = GenericLikeC4Model.Typed<LikeC4ElementId, LikeC4DeploymentId, LikeC4ViewId, DiagramView<LikeC4ViewId>>;
|
|
82
|
+
type LikeC4Model = GenericLikeC4Model<Aux>;
|
|
83
|
+
type LikeC4ViewModel = GenericLikeC4Model.View<Aux>;
|
|
84
|
+
|
|
85
|
+
declare const likeC4Model: LikeC4Model;
|
|
86
|
+
declare function useLikeC4Model(): LikeC4Model;
|
|
87
|
+
declare function useLikeC4View(viewId: LikeC4ViewId): DiagramView<LikeC4ViewId>;
|
|
88
|
+
|
|
89
|
+
declare function LikeC4ModelProvider(props: PropsWithChildren): JSX.Element;
|
|
90
|
+
|
|
91
|
+
type IconRendererProps = {
|
|
92
|
+
node: {
|
|
93
|
+
id: string
|
|
94
|
+
title: string
|
|
95
|
+
icon?: string | undefined
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
declare function RenderIcon(props: IconRendererProps): JSX.Element;
|
|
99
|
+
|
|
100
|
+
type LikeC4ViewProps = GenericLikeC4ViewProps<LikeC4ViewId, LikeC4Tag, LikeC4ElementKind>;
|
|
101
|
+
declare function LikeC4View({viewId, ...props}: LikeC4ViewProps): JSX.Element;
|
|
102
|
+
|
|
103
|
+
type ReactLikeC4Props = GenericReactLikeC4Props<LikeC4ViewId, LikeC4Tag, LikeC4ElementKind>
|
|
104
|
+
declare function ReactLikeC4({viewId, ...props}: ReactLikeC4Props): JSX.Element;
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
type LikeC4ElementId,
|
|
108
|
+
type LikeC4DeploymentId,
|
|
109
|
+
type LikeC4ViewId,
|
|
110
|
+
type LikeC4Tag,
|
|
111
|
+
type LikeC4ElementKind,
|
|
112
|
+
type LikeC4ViewProps,
|
|
113
|
+
type ReactLikeC4Props,
|
|
114
|
+
type LikeC4Model,
|
|
115
|
+
isLikeC4ViewId,
|
|
116
|
+
useLikeC4Model,
|
|
117
|
+
useLikeC4View,
|
|
118
|
+
useLikeC4ViewModel,
|
|
119
|
+
likeC4Model,
|
|
120
|
+
LikeC4ModelProvider,
|
|
121
|
+
LikeC4View,
|
|
122
|
+
RenderIcon,
|
|
123
|
+
ReactLikeC4
|
|
124
|
+
}
|
|
125
|
+
/* prettier-ignore-end */
|
|
126
|
+
`.trimStart()
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateReactTypes as default } from './generate-react-types'
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { DiagramView } from '@likec4/core'
|
|
2
|
+
import { CompositeGeneratorNode, toString } from 'langium/generate'
|
|
3
|
+
import { generateViewsDataDTs, generateViewsDataJs } from '../views-data-ts/generate-views-data'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated in favor packages/likec4/src/cli/codegen/react/index.ts
|
|
7
|
+
*/
|
|
8
|
+
export function generateReactNext(views: Iterable<DiagramView>) {
|
|
9
|
+
return {
|
|
10
|
+
viewsData: {
|
|
11
|
+
fileName: 'likec4-views-data',
|
|
12
|
+
js: generateViewsDataJs(views),
|
|
13
|
+
dts: generateViewsDataDTs(views),
|
|
14
|
+
},
|
|
15
|
+
components: {
|
|
16
|
+
fileName: 'likec4-components',
|
|
17
|
+
...generateComponents(),
|
|
18
|
+
},
|
|
19
|
+
index: generateIndex(),
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function generateComponents() {
|
|
24
|
+
const js = new CompositeGeneratorNode().appendTemplate`
|
|
25
|
+
/******************************************************************************
|
|
26
|
+
* This file was generated
|
|
27
|
+
* DO NOT EDIT MANUALLY!
|
|
28
|
+
******************************************************************************/
|
|
29
|
+
/* prettier-ignore-start */
|
|
30
|
+
/* eslint-disable */
|
|
31
|
+
import { createElement } from "react";
|
|
32
|
+
import { LikeC4Diagram, EmbeddedLikeC4Diagram } from "@likec4/diagram";
|
|
33
|
+
import { LikeC4Views } from "./likec4-views-data";
|
|
34
|
+
export function LikeC4View({ viewId, ...props }) {
|
|
35
|
+
const view = LikeC4Views[viewId];
|
|
36
|
+
if (!view) {
|
|
37
|
+
throw new Error(\`LikeC4View NotFound: "\${viewId}"\`);
|
|
38
|
+
}
|
|
39
|
+
return createElement(LikeC4Diagram, { view: view, ...props });
|
|
40
|
+
}
|
|
41
|
+
export function EmbeddedLikeC4View({ viewId, ...props }) {
|
|
42
|
+
return createElement(EmbeddedLikeC4Diagram, { viewId: viewId, views: LikeC4Views, ...props });
|
|
43
|
+
}
|
|
44
|
+
/* prettier-ignore-end */
|
|
45
|
+
`
|
|
46
|
+
|
|
47
|
+
const dts = new CompositeGeneratorNode().appendTemplate`
|
|
48
|
+
/// <reference types="react" />
|
|
49
|
+
/******************************************************************************
|
|
50
|
+
* This file was generated
|
|
51
|
+
* DO NOT EDIT MANUALLY!
|
|
52
|
+
******************************************************************************/
|
|
53
|
+
/* prettier-ignore-start */
|
|
54
|
+
/* eslint-disable */
|
|
55
|
+
|
|
56
|
+
import type { LikeC4DiagramProps, EmbeddedLikeC4DiagramProps } from "@likec4/diagram";
|
|
57
|
+
import type { LikeC4ViewId } from "./likec4-views-data";
|
|
58
|
+
|
|
59
|
+
export type LikeC4ViewProps = {
|
|
60
|
+
viewId: LikeC4ViewId;
|
|
61
|
+
} & Omit<LikeC4DiagramProps, "view">;
|
|
62
|
+
|
|
63
|
+
export declare function LikeC4View({ viewId, ...props }: LikeC4ViewProps): JSX.Element;
|
|
64
|
+
|
|
65
|
+
export type EmbeddedLikeC4ViewProps = {
|
|
66
|
+
viewId: LikeC4ViewId;
|
|
67
|
+
} & Omit<EmbeddedLikeC4DiagramProps, "viewId" | "views">;
|
|
68
|
+
|
|
69
|
+
export declare function EmbeddedLikeC4View({ viewId, ...props }: EmbeddedLikeC4ViewProps): JSX.Element;
|
|
70
|
+
/* prettier-ignore-end */
|
|
71
|
+
`
|
|
72
|
+
return {
|
|
73
|
+
js: toString(js),
|
|
74
|
+
dts: toString(dts),
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function generateIndex() {
|
|
79
|
+
const js = new CompositeGeneratorNode().appendTemplate`
|
|
80
|
+
/* prettier-ignore-start */
|
|
81
|
+
/* eslint-disable */
|
|
82
|
+
|
|
83
|
+
// You are safe to edit/move these style imports,
|
|
84
|
+
// but they are required
|
|
85
|
+
import "@mantine/core/styles.css";
|
|
86
|
+
import "@likec4/diagram/style.css";
|
|
87
|
+
|
|
88
|
+
export * from "./likec4-components";
|
|
89
|
+
|
|
90
|
+
// OR with lazy loading:
|
|
91
|
+
//
|
|
92
|
+
// import { lazy } from "react";
|
|
93
|
+
// export const LikeC4View = lazy(async () => await import("./likec4-components").then(m => ({default: m.LikeC4View})));
|
|
94
|
+
// export const EmbeddedLikeC4View = lazy(async () => await import("./likec4-components").then(m => ({default: m.EmbeddedLikeC4View})));
|
|
95
|
+
|
|
96
|
+
/* prettier-ignore-end */
|
|
97
|
+
`
|
|
98
|
+
|
|
99
|
+
const dts = new CompositeGeneratorNode().appendTemplate`
|
|
100
|
+
/* prettier-ignore-start */
|
|
101
|
+
/* eslint-disable */
|
|
102
|
+
|
|
103
|
+
export * from "./likec4-components";
|
|
104
|
+
|
|
105
|
+
/* prettier-ignore-end */
|
|
106
|
+
`
|
|
107
|
+
return {
|
|
108
|
+
js: toString(js),
|
|
109
|
+
dts: toString(dts),
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateReactNext as default } from './generate-react-next'
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`generate generateViewsDataDTs 1`] = `
|
|
4
|
+
"/******************************************************************************
|
|
5
|
+
* This file was generated
|
|
6
|
+
* DO NOT EDIT MANUALLY!
|
|
7
|
+
******************************************************************************/
|
|
8
|
+
/* prettier-ignore-start */
|
|
9
|
+
/* eslint-disable */
|
|
10
|
+
|
|
11
|
+
import type { DiagramView } from 'likec4'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export type LikeC4ViewId = 'fakeView' | '74f5364fa4b';
|
|
15
|
+
export type LikeC4Views = Record<LikeC4ViewId, DiagramView>
|
|
16
|
+
|
|
17
|
+
export declare const LikeC4Views: LikeC4Views
|
|
18
|
+
export declare function isLikeC4ViewId(value: unknown): value is LikeC4ViewId
|
|
19
|
+
|
|
20
|
+
/* prettier-ignore-end */
|
|
21
|
+
"
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
exports[`generate generateViewsDataJs 1`] = `
|
|
25
|
+
"/******************************************************************************
|
|
26
|
+
* This file was generated
|
|
27
|
+
* DO NOT EDIT MANUALLY!
|
|
28
|
+
******************************************************************************/
|
|
29
|
+
/* prettier-ignore-start */
|
|
30
|
+
/* eslint-disable */
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export const LikeC4Views = {
|
|
35
|
+
'fakeView': {edges:[{headArrow:[[294,487],[291,496],[288,487]],id:'cloud.frontend:cloud.backend',label:'requests',labelBox:{align:'left',width:62,x:295,y:459},points:[[291,406],[291,432],[291,461],[291,487]],relations:['cloud.frontend.dashboard:cloud.backend.graphql','cloud.frontend.adminPanel:cloud.backend.graphql'],source:'cloud.frontend',target:'cloud.backend'},{headArrow:[[294,701],[291,711],[288,701]],id:'cloud.backend:amazon',label:null,labelBox:null,points:[[291,641],[291,660],[291,681],[291,702]],relations:['cloud.backend.storage:amazon.s3'],source:'cloud.backend',target:'amazon'},{headArrow:[[344,257],[336,263],[338,253]],id:'support:cloud.frontend',label:null,labelBox:null,points:[[413,141],[391,176],[364,218],[342,255]],relations:['support:cloud.frontend.adminPanel'],source:'support',target:'cloud.frontend'},{headArrow:[[244,253],[246,263],[239,257]],id:'customer:cloud.frontend',label:'opens',labelBox:{align:'left',width:44,x:208,y:193},points:[[169,141],[191,176],[218,218],[241,255]],relations:['customer:cloud.frontend.dashboard'],source:'customer',target:'cloud.frontend'}],height:855,id:'fakeView',nodes:[{children:[],color:'primary',id:'amazon',parent:null,position:[165,715],relative:[165,715],shape:'rectangle',size:{height:140,width:251},title:'amazon'},{children:['cloud.backend','cloud.frontend'],color:'primary',id:'cloud',parent:null,position:[139,210],relative:[139,210],shape:'rectangle',size:{height:457,width:304},title:'cloud'},{children:[],color:'primary',id:'customer',parent:null,position:[0,0],relative:[0,0],shape:'rectangle',size:{height:140,width:251},title:'customer'},{children:[],color:'primary',id:'support',parent:null,position:[330,0],relative:[330,0],shape:'rectangle',size:{height:140,width:251},title:'support'},{children:[],color:'primary',id:'cloud.backend',parent:'cloud',position:[165,500],relative:[26,290],shape:'rectangle',size:{height:140,width:251},title:'backend'},{children:[],color:'primary',id:'cloud.frontend',parent:'cloud',position:[165,266],relative:[26,56],shape:'rectangle',size:{height:140,width:251},title:'frontend'}],autoLayout:{direction:'TB'},rules:[{exprs:[{wildcard:true}],isInclude:true}],title:'',viewOf:'cloud',width:582},
|
|
36
|
+
'74f5364fa4b': {edges:[{headArrow:[[129,456],[126,465],[123,456]],id:'system.frontend:system.backend',label:'requests',labelBox:{align:'left',width:62,x:130,y:428},points:[[126,375],[126,400],[126,429],[126,456]],relations:['671e3db5eb605d5f245f247d95925bd0953e0e4c'],source:'system.frontend',target:'system.backend'},{headArrow:[[129,221],[126,231],[123,221]],id:'client:system.frontend',label:'opens',labelBox:{align:'left',width:44,x:130,y:193},points:[[126,141],[126,166],[126,195],[126,221]],relations:['99bffdfd5c78e024393e6223cd9b19225321a5e3'],source:'client',target:'system.frontend'}],height:609,id:'74f5364fa4b',nodes:[{children:[],color:'primary',id:'client',parent:null,position:[0,0],relative:[0,0],shape:'rectangle',size:{height:140,width:251},title:'client'},{children:[],color:'primary',id:'system.backend',parent:null,position:[0,469],relative:[0,469],shape:'rectangle',size:{height:140,width:251},title:'backend'},{children:[],color:'primary',id:'system.frontend',parent:null,position:[0,235],relative:[0,235],shape:'rectangle',size:{height:140,width:251},title:'frontend'}],autoLayout:{direction:'TB'},rules:[{exprs:[{wildcard:true}],isInclude:true}],title:'frontend',viewOf:'system.frontend',width:251}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
export function isLikeC4ViewId(value) {
|
|
41
|
+
return (
|
|
42
|
+
value != null &&
|
|
43
|
+
typeof value === 'string' &&
|
|
44
|
+
!!LikeC4Views[value]
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* prettier-ignore-end */
|
|
49
|
+
"
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
exports[`generate generateViewsDataTs 1`] = `
|
|
53
|
+
"/******************************************************************************
|
|
54
|
+
* This file was generated
|
|
55
|
+
* DO NOT EDIT MANUALLY!
|
|
56
|
+
******************************************************************************/
|
|
57
|
+
/* prettier-ignore-start */
|
|
58
|
+
/* eslint-disable */
|
|
59
|
+
|
|
60
|
+
// @ts-nocheck
|
|
61
|
+
|
|
62
|
+
import type { DiagramView } from 'likec4'
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
export type LikeC4ViewId = 'fakeView' | '74f5364fa4b';
|
|
66
|
+
export const LikeC4Views = {
|
|
67
|
+
'fakeView': ({edges:[{headArrow:[[294,487],[291,496],[288,487]],id:'cloud.frontend:cloud.backend',label:'requests',labelBox:{align:'left',width:62,x:295,y:459},points:[[291,406],[291,432],[291,461],[291,487]],relations:['cloud.frontend.dashboard:cloud.backend.graphql','cloud.frontend.adminPanel:cloud.backend.graphql'],source:'cloud.frontend',target:'cloud.backend'},{headArrow:[[294,701],[291,711],[288,701]],id:'cloud.backend:amazon',label:null,labelBox:null,points:[[291,641],[291,660],[291,681],[291,702]],relations:['cloud.backend.storage:amazon.s3'],source:'cloud.backend',target:'amazon'},{headArrow:[[344,257],[336,263],[338,253]],id:'support:cloud.frontend',label:null,labelBox:null,points:[[413,141],[391,176],[364,218],[342,255]],relations:['support:cloud.frontend.adminPanel'],source:'support',target:'cloud.frontend'},{headArrow:[[244,253],[246,263],[239,257]],id:'customer:cloud.frontend',label:'opens',labelBox:{align:'left',width:44,x:208,y:193},points:[[169,141],[191,176],[218,218],[241,255]],relations:['customer:cloud.frontend.dashboard'],source:'customer',target:'cloud.frontend'}],height:855,id:'fakeView',nodes:[{children:[],color:'primary',id:'amazon',parent:null,position:[165,715],relative:[165,715],shape:'rectangle',size:{height:140,width:251},title:'amazon'},{children:['cloud.backend','cloud.frontend'],color:'primary',id:'cloud',parent:null,position:[139,210],relative:[139,210],shape:'rectangle',size:{height:457,width:304},title:'cloud'},{children:[],color:'primary',id:'customer',parent:null,position:[0,0],relative:[0,0],shape:'rectangle',size:{height:140,width:251},title:'customer'},{children:[],color:'primary',id:'support',parent:null,position:[330,0],relative:[330,0],shape:'rectangle',size:{height:140,width:251},title:'support'},{children:[],color:'primary',id:'cloud.backend',parent:'cloud',position:[165,500],relative:[26,290],shape:'rectangle',size:{height:140,width:251},title:'backend'},{children:[],color:'primary',id:'cloud.frontend',parent:'cloud',position:[165,266],relative:[26,56],shape:'rectangle',size:{height:140,width:251},title:'frontend'}],autoLayout:{direction:'TB'},rules:[{exprs:[{wildcard:true}],isInclude:true}],title:'',viewOf:'cloud',width:582} as unknown) as DiagramView,
|
|
68
|
+
'74f5364fa4b': ({edges:[{headArrow:[[129,456],[126,465],[123,456]],id:'system.frontend:system.backend',label:'requests',labelBox:{align:'left',width:62,x:130,y:428},points:[[126,375],[126,400],[126,429],[126,456]],relations:['671e3db5eb605d5f245f247d95925bd0953e0e4c'],source:'system.frontend',target:'system.backend'},{headArrow:[[129,221],[126,231],[123,221]],id:'client:system.frontend',label:'opens',labelBox:{align:'left',width:44,x:130,y:193},points:[[126,141],[126,166],[126,195],[126,221]],relations:['99bffdfd5c78e024393e6223cd9b19225321a5e3'],source:'client',target:'system.frontend'}],height:609,id:'74f5364fa4b',nodes:[{children:[],color:'primary',id:'client',parent:null,position:[0,0],relative:[0,0],shape:'rectangle',size:{height:140,width:251},title:'client'},{children:[],color:'primary',id:'system.backend',parent:null,position:[0,469],relative:[0,469],shape:'rectangle',size:{height:140,width:251},title:'backend'},{children:[],color:'primary',id:'system.frontend',parent:null,position:[0,235],relative:[0,235],shape:'rectangle',size:{height:140,width:251},title:'frontend'}],autoLayout:{direction:'TB'},rules:[{exprs:[{wildcard:true}],isInclude:true}],title:'frontend',viewOf:'system.frontend',width:251} as unknown) as DiagramView
|
|
69
|
+
} as const satisfies Record<LikeC4ViewId, DiagramView>
|
|
70
|
+
|
|
71
|
+
export type LikeC4Views = typeof LikeC4Views
|
|
72
|
+
|
|
73
|
+
export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
|
|
74
|
+
return (
|
|
75
|
+
value != null &&
|
|
76
|
+
typeof value === 'string' &&
|
|
77
|
+
!!LikeC4Views[value]
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* prettier-ignore-end */
|
|
82
|
+
"
|
|
83
|
+
`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect, test } from 'vitest'
|
|
2
|
+
import { fakeDiagram, fakeDiagram2 } from '../__mocks__/data'
|
|
3
|
+
import { generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs } from './generate-views-data'
|
|
4
|
+
|
|
5
|
+
test('generate generateViewsDataJs', () => {
|
|
6
|
+
expect(generateViewsDataJs([fakeDiagram, fakeDiagram2])).toMatchSnapshot()
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('generate generateViewsDataTs', () => {
|
|
10
|
+
expect(generateViewsDataTs([fakeDiagram, fakeDiagram2])).toMatchSnapshot()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('generate generateViewsDataDTs', () => {
|
|
14
|
+
expect(generateViewsDataDTs([fakeDiagram, fakeDiagram2])).toMatchSnapshot()
|
|
15
|
+
})
|