@likec4/config 1.48.0 → 1.50.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/README.md +5 -0
- package/dist/THIRD-PARTY-LICENSES.md +41 -0
- package/dist/_chunks/libs/defu.mjs +39 -0
- package/dist/_chunks/libs/remeda.mjs +32 -19
- package/dist/index.d.mts +233 -148
- package/dist/index.mjs +106 -136
- package/dist/node/index.d.mts +234 -149
- package/dist/node/index.mjs +208 -194
- package/package.json +11 -9
- package/schema.json +169 -141
- package/src/filenames.ts +33 -22
- package/src/index.ts +6 -5
- package/src/node/index.ts +1 -38
- package/src/node/load-config.ts +121 -51
- package/src/schema.image-alias.ts +10 -46
- package/src/schema.include.ts +36 -74
- package/src/schema.theme.ts +87 -83
- package/src/schema.ts +76 -35
package/src/schema.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
//
|
|
3
|
+
// Copyright (c) 2023-2026 Denis Davydkov
|
|
4
|
+
// Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// Portions of this file have been modified by NVIDIA CORPORATION & AFFILIATES.
|
|
7
|
+
|
|
1
8
|
import type {
|
|
2
9
|
DeploymentElementModel,
|
|
3
10
|
DeploymentRelationModel,
|
|
@@ -11,10 +18,9 @@ import type {
|
|
|
11
18
|
ProjectId,
|
|
12
19
|
} from '@likec4/core/types'
|
|
13
20
|
import JSON5 from 'json5'
|
|
14
|
-
import type { SimplifyDeep } from 'type-fest'
|
|
15
21
|
import z from 'zod/v4'
|
|
16
|
-
import { ImageAliasesSchema
|
|
17
|
-
import {
|
|
22
|
+
import { ImageAliasesSchema } from './schema.image-alias'
|
|
23
|
+
import { type IncludeConfig, IncludeSchema } from './schema.include'
|
|
18
24
|
import { LikeC4StylesConfigSchema } from './schema.theme'
|
|
19
25
|
|
|
20
26
|
export interface VscodeURI {
|
|
@@ -41,7 +47,7 @@ export const ManualLayoutsConfigSchema = z
|
|
|
41
47
|
}),
|
|
42
48
|
})
|
|
43
49
|
.meta({
|
|
44
|
-
id: '
|
|
50
|
+
id: 'ManualLayoutsConfig',
|
|
45
51
|
description: 'Configuration for manual layouts',
|
|
46
52
|
})
|
|
47
53
|
|
|
@@ -59,6 +65,12 @@ export const LikeC4ProjectJsonConfigSchema = z.object({
|
|
|
59
65
|
error: 'Project name cannot contain ".", "@" or "#", try to use A-z, 0-9, _ and -',
|
|
60
66
|
})
|
|
61
67
|
.meta({ description: 'Project name, must be unique in the workspace' }),
|
|
68
|
+
extends: z.union([
|
|
69
|
+
z.string().min(1, 'Extend path cannot be empty'),
|
|
70
|
+
z.array(z.string().min(1, 'Extend path cannot be empty')).min(1, 'Extend list cannot be empty'),
|
|
71
|
+
])
|
|
72
|
+
.optional()
|
|
73
|
+
.meta({ description: 'Extend styles from other config files' }),
|
|
62
74
|
title: z.string()
|
|
63
75
|
.nonempty('Project title cannot be empty if specified')
|
|
64
76
|
.optional()
|
|
@@ -67,22 +79,39 @@ export const LikeC4ProjectJsonConfigSchema = z.object({
|
|
|
67
79
|
.nonempty('Contact person cannot be empty if specified')
|
|
68
80
|
.optional()
|
|
69
81
|
.meta({ description: 'A person who has been involved in creating or maintaining this project' }),
|
|
70
|
-
|
|
71
|
-
.optional()
|
|
72
|
-
|
|
73
|
-
styles: LikeC4StylesConfigSchema
|
|
74
|
-
|
|
82
|
+
metadata: z.record(z.string(), z.any())
|
|
83
|
+
.optional()
|
|
84
|
+
.meta({ description: 'Arbitrary metadata as key-value pairs for custom project information' }),
|
|
85
|
+
styles: LikeC4StylesConfigSchema.optional().meta({
|
|
86
|
+
description: 'Project styles customization',
|
|
87
|
+
}),
|
|
88
|
+
imageAliases: ImageAliasesSchema.optional(),
|
|
89
|
+
include: IncludeSchema.optional(),
|
|
75
90
|
exclude: z.array(z.string())
|
|
76
91
|
.optional()
|
|
77
92
|
.meta({ description: 'List of file patterns to exclude from the project, default is ["**/node_modules/**"]' }),
|
|
78
|
-
manualLayouts: ManualLayoutsConfigSchema
|
|
79
|
-
|
|
93
|
+
manualLayouts: ManualLayoutsConfigSchema.optional(),
|
|
94
|
+
inferTechnologyFromIcon: z.boolean()
|
|
95
|
+
.optional()
|
|
96
|
+
.meta({
|
|
97
|
+
description: [
|
|
98
|
+
'Automatically derive element technology from icon name when technology is not set explicitly.',
|
|
99
|
+
'Applies to aws:, azure:, gcp:, and tech: icons. Bootstrap icons are excluded.',
|
|
100
|
+
'Defaults to true.',
|
|
101
|
+
].join('\n'),
|
|
102
|
+
}),
|
|
103
|
+
implicitViews: z.boolean()
|
|
104
|
+
.optional()
|
|
105
|
+
.meta({
|
|
106
|
+
description: 'Auto-generate scoped views for elements without explicit views. Defaults to true.',
|
|
107
|
+
}),
|
|
80
108
|
})
|
|
81
109
|
.meta({
|
|
82
|
-
|
|
110
|
+
id: 'LikeC4ProjectConfig',
|
|
111
|
+
description: 'LikeC4 Project Configuration',
|
|
83
112
|
})
|
|
84
113
|
|
|
85
|
-
export type LikeC4ProjectJsonConfig =
|
|
114
|
+
export type LikeC4ProjectJsonConfig = z.input<typeof LikeC4ProjectJsonConfigSchema>
|
|
86
115
|
|
|
87
116
|
const FunctionType = z.instanceof(Function)
|
|
88
117
|
export const GeneratorsSchema = z.record(z.string(), FunctionType)
|
|
@@ -236,30 +265,42 @@ export type LikeC4ProjectConfig = z.infer<typeof LikeC4ProjectJsonConfigSchema>
|
|
|
236
265
|
generators?: Record<string, GeneratorFn> | undefined
|
|
237
266
|
}
|
|
238
267
|
|
|
239
|
-
export type LikeC4ProjectConfigInput =
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
>
|
|
268
|
+
export type LikeC4ProjectConfigInput = LikeC4ProjectJsonConfig & {
|
|
269
|
+
generators?: Record<string, GeneratorFn> | undefined
|
|
270
|
+
}
|
|
244
271
|
|
|
245
272
|
/**
|
|
246
|
-
* Validates
|
|
273
|
+
* Validates Object into a LikeC4ProjectConfig object.
|
|
247
274
|
*/
|
|
248
|
-
export function validateProjectConfig<C extends
|
|
249
|
-
config
|
|
250
|
-
)
|
|
251
|
-
|
|
252
|
-
typeof config === 'string' ? JSON5.parse(config) : config,
|
|
253
|
-
)
|
|
254
|
-
if (!parsed.success) {
|
|
255
|
-
throw new Error('Config validation failed:\n' + z.prettifyError(parsed.error))
|
|
256
|
-
}
|
|
257
|
-
// TODO: rewrite with zod refine
|
|
258
|
-
if (parsed.data.imageAliases) {
|
|
259
|
-
validateImageAliases(parsed.data.imageAliases)
|
|
275
|
+
export function validateProjectConfig<C extends Record<string, unknown>>(config: C): LikeC4ProjectConfig {
|
|
276
|
+
const parsed = LikeC4ProjectConfigSchema.safeParse(config)
|
|
277
|
+
if (parsed.success) {
|
|
278
|
+
return parsed.data as unknown as LikeC4ProjectConfig
|
|
260
279
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
280
|
+
throw new Error('Config validation failed:\n' + z.prettifyError(parsed.error))
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Parses JSON string into a LikeC4ProjectConfig object.
|
|
285
|
+
* Does not process "extends" - use `loadConfig` function instead
|
|
286
|
+
*/
|
|
287
|
+
export function parseProjectConfigJSON(config: string): LikeC4ProjectConfig {
|
|
288
|
+
const parsed = JSON5.parse(config.trim() || '{}')
|
|
289
|
+
return validateProjectConfig(parsed)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export const LikeC4ProjectConfigOps = {
|
|
293
|
+
parse: parseProjectConfigJSON,
|
|
294
|
+
validate: validateProjectConfig,
|
|
295
|
+
normalizeInclude: (include: z.input<typeof IncludeSchema> | undefined): IncludeConfig => {
|
|
296
|
+
const parsed = IncludeSchema.safeParse(include)
|
|
297
|
+
if (parsed.success) {
|
|
298
|
+
return parsed.data
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
paths: [],
|
|
302
|
+
maxDepth: 3,
|
|
303
|
+
fileThreshold: 30,
|
|
304
|
+
}
|
|
305
|
+
},
|
|
265
306
|
}
|