@likec4/config 1.48.0 → 1.49.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 +4 -0
- package/dist/THIRD-PARTY-LICENSES.md +41 -0
- package/dist/_chunks/libs/defu.mjs +39 -0
- package/dist/_chunks/libs/remeda.mjs +25 -18
- package/dist/index.d.mts +223 -138
- package/dist/index.mjs +72 -242
- package/dist/node/index.d.mts +224 -139
- package/dist/node/index.mjs +168 -304
- package/package.json +13 -10
- package/schema.json +155 -143
- package/src/filenames.ts +6 -14
- 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 +52 -35
package/dist/index.mjs
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
import { t } from "./_chunks/libs/remeda.mjs";
|
|
2
1
|
import JSON5 from "json5";
|
|
3
2
|
import z from "zod/v4";
|
|
4
3
|
import { BorderStyles, ElementShapes, IconPositions, RelationshipArrowTypes, Sizes, ThemeColors, computeColorValues } from "@likec4/core/styles";
|
|
5
4
|
import { exact } from "@likec4/core/types";
|
|
6
|
-
|
|
7
|
-
//#region src/schema.image-alias.ts
|
|
5
|
+
import { basename } from "pathe";
|
|
8
6
|
const IMAGE_ALIAS_KEY_REGEX = /^@[A-Za-z0-9_-]*$/;
|
|
9
7
|
const IMAGE_ALIAS_VALUE_REGEX = /^(?!\/|[A-Za-z]:[\\\/])(?!.*:\/\/).*$/;
|
|
8
|
+
const ImageAliasKey = z.string().min(1, "Image alias key cannot be empty").regex(IMAGE_ALIAS_KEY_REGEX, "Image alias key must match /^@\\w+$/");
|
|
10
9
|
const ImageAliasValue = z.string().min(1, "Image alias value cannot be empty").regex(IMAGE_ALIAS_VALUE_REGEX, "Image alias value must be a relative path (no leading slash or protocol)");
|
|
11
|
-
const ImageAliasesSchema = z.record(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
if (invalidKeys.length || invalidValues.length) {
|
|
20
|
-
const parts = [];
|
|
21
|
-
if (invalidKeys.length) parts.push(`Invalid image alias key(s): ${invalidKeys.map((k) => JSON.stringify(k)).join(", ")} (must match ${IMAGE_ALIAS_KEY_REGEX})`);
|
|
22
|
-
if (invalidValues.length) parts.push(`Invalid image alias value(s): ${invalidValues.map((kv) => JSON.stringify(kv)).join(", ")} (must match ${IMAGE_ALIAS_VALUE_REGEX})`);
|
|
23
|
-
throw new Error(parts.join(" | "));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/schema.include.ts
|
|
29
|
-
const RELATIVE_PATH_REGEX = /^(?!\/|[A-Za-z]:[\\\/])(?!.*:\/\/).*$/;
|
|
30
|
-
const IncludePathValue = z.string().min(1, "Include path cannot be empty").regex(RELATIVE_PATH_REGEX, "Include path must be a relative path (no leading slash, drive letter, or protocol)");
|
|
31
|
-
const IncludeConfigSchema = z.strictObject({
|
|
32
|
-
paths: z.array(IncludePathValue).min(1, "Include paths cannot be empty").meta({ description: [
|
|
10
|
+
const ImageAliasesSchema = z.record(ImageAliasKey, ImageAliasValue).meta({
|
|
11
|
+
id: "ImageAliases",
|
|
12
|
+
description: "Map of image alias prefixes to relative paths (keys must match /^@\\w+$/; values must be relative paths without protocol or leading slash)."
|
|
13
|
+
});
|
|
14
|
+
const IncludePathValue = z.string().min(1, "Include path cannot be empty").regex(/^(?!\/|[A-Za-z]:[\\\/])(?!.*:\/\/).*$/, "Include path must be a relative path (no leading slash, drive letter, or protocol)");
|
|
15
|
+
const IncludeSchema = z.strictObject({
|
|
16
|
+
paths: z.array(IncludePathValue).meta({ description: [
|
|
33
17
|
"Additional relative directory paths to include LikeC4 source files from, searched recursively.",
|
|
34
18
|
"Paths are relative to the project folder (the folder containing this config file).",
|
|
35
19
|
"Example: [\"../shared\", \"../common/specs\"]"
|
|
@@ -39,54 +23,33 @@ const IncludeConfigSchema = z.strictObject({
|
|
|
39
23
|
"Prevents excessive scanning of deeply nested directories.",
|
|
40
24
|
"Default: 3"
|
|
41
25
|
].join("\n") }),
|
|
42
|
-
fileThreshold: z.number().int().min(1).default(30).meta({ description: [
|
|
26
|
+
fileThreshold: z.number().int().min(1).max(1e4).default(30).meta({ description: [
|
|
43
27
|
"Maximum number of files to load from include paths before warning.",
|
|
44
28
|
"Helps identify performance issues from accidentally including large directories.",
|
|
45
29
|
"Default: 30"
|
|
46
30
|
].join("\n") })
|
|
47
31
|
}).meta({
|
|
48
32
|
id: "include-config",
|
|
49
|
-
description: "Configuration for including additional LikeC4 source files"
|
|
33
|
+
description: ["Configuration for including additional LikeC4 source files from other directories.", "Example: { \"paths\": [\"../shared\", \"../common/specs\"], \"maxDepth\": 5, \"fileThreshold\": 50 }"].join("\n")
|
|
50
34
|
});
|
|
51
|
-
const IncludeSchema = IncludeConfigSchema.optional().meta({ description: ["Configuration for including additional LikeC4 source files from other directories.", "Example: { \"paths\": [\"../shared\", \"../common/specs\"], \"maxDepth\": 5, \"fileThreshold\": 50 }"].join("\n") });
|
|
52
|
-
function normalizeIncludeConfig(include) {
|
|
53
|
-
if (!include) return {
|
|
54
|
-
paths: [],
|
|
55
|
-
maxDepth: 3,
|
|
56
|
-
fileThreshold: 30
|
|
57
|
-
};
|
|
58
|
-
return include;
|
|
59
|
-
}
|
|
60
|
-
function validateIncludePaths(include) {
|
|
61
|
-
if (!include?.paths) return;
|
|
62
|
-
const invalidPaths = [];
|
|
63
|
-
for (const path of include.paths) if (!RELATIVE_PATH_REGEX.test(path)) invalidPaths.push(path);
|
|
64
|
-
if (invalidPaths.length > 0) throw new Error(`Invalid include path(s): ${invalidPaths.map((p) => JSON.stringify(p)).join(", ")} (must be relative paths without leading slash, drive letter, or protocol)`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
68
|
-
//#region src/schema.theme.ts
|
|
69
35
|
const opacity = z.int().min(0, "Opacity must be between 0 and 100").max(100, "Opacity must be between 0 and 100").meta({
|
|
70
36
|
id: "Opacity",
|
|
71
37
|
description: "Opacity 0-100%"
|
|
72
38
|
});
|
|
73
|
-
const shape = z.
|
|
74
|
-
const border = z.
|
|
75
|
-
const size = z.
|
|
76
|
-
const iconPosition = z.
|
|
77
|
-
const arrow = z.
|
|
78
|
-
const line = z.
|
|
39
|
+
const shape = z.enum(ElementShapes).meta({ id: "ElementShape" });
|
|
40
|
+
const border = z.enum(BorderStyles).meta({ id: "BorderStyle" });
|
|
41
|
+
const size = z.enum(Sizes).meta({ id: "ElementSize" });
|
|
42
|
+
const iconPosition = z.enum(IconPositions).meta({ id: "IconPosition" });
|
|
43
|
+
const arrow = z.enum(RelationshipArrowTypes).meta({ id: "ArrowType" });
|
|
44
|
+
const line = z.enum([
|
|
79
45
|
"dashed",
|
|
80
46
|
"solid",
|
|
81
47
|
"dotted"
|
|
82
48
|
]).meta({ id: "LineType" });
|
|
83
|
-
const themeColor = z.
|
|
84
|
-
const customColor = z.
|
|
85
|
-
const color =
|
|
86
|
-
const colorSchema = z.string().min(1, "Color value cannot be empty").
|
|
87
|
-
id: "ColorLiteral",
|
|
88
|
-
description: "Color value in any valid CSS format: hex, rgb, rgba, hsl, hsla ..."
|
|
89
|
-
});
|
|
49
|
+
const themeColor = z.enum(ThemeColors).meta({ id: "ThemeColorName" });
|
|
50
|
+
const customColor = z.custom().refine((v) => typeof v === "string", "Custom color name must be a string").transform((value) => value).meta({ id: "CustomColorName" });
|
|
51
|
+
const color = themeColor.or(customColor).transform((value) => value).meta({ id: "ColorName" });
|
|
52
|
+
const colorSchema = z.string().min(1, "Color value cannot be empty").meta({ id: "ColorLiteral" });
|
|
90
53
|
const ElementColorValuesSchema = z.strictObject({
|
|
91
54
|
fill: colorSchema.meta({ description: "Background color" }),
|
|
92
55
|
stroke: colorSchema.meta({ description: "Stroke color (border, paths above background)" }),
|
|
@@ -98,44 +61,31 @@ const RelationshipColorValuesSchema = z.strictObject({
|
|
|
98
61
|
label: colorSchema.meta({ description: "Label text color" }),
|
|
99
62
|
labelBg: colorSchema.optional().default("rgba(0, 0, 0, 0.5)").meta({ description: "Label background color" })
|
|
100
63
|
}).meta({ id: "RelationshipColorValues" }).transform((value) => value);
|
|
101
|
-
const
|
|
102
|
-
elements:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return value;
|
|
109
|
-
})
|
|
110
|
-
}).meta({ id: "StrictThemeColorValues" });
|
|
111
|
-
const ThemeColorValuesSchema = z.union([colorSchema, StrictThemeColorValuesSchema]).meta({
|
|
64
|
+
const ThemeColorValuesSchema = z.strictObject({
|
|
65
|
+
elements: ElementColorValuesSchema.or(colorSchema.transform((v) => computeColorValues(v).elements)).meta({ description: "Exact color value (hex, rgb, rgba, hsl, hsla ...) or break down of specific color values" }),
|
|
66
|
+
relationships: RelationshipColorValuesSchema.or(colorSchema.transform((v) => computeColorValues(v).relationships)).meta({ description: "Exact color value (hex, rgb, rgba, hsl, hsla ...) or break down of specific color values" })
|
|
67
|
+
}).transform((value) => value).meta({
|
|
68
|
+
id: "StrictThemeColorValues",
|
|
69
|
+
description: "Exact color value (hex, rgb, rgba, hsl, hsla ...) or break down of specific color value"
|
|
70
|
+
}).or(colorSchema.transform((v) => computeColorValues(v))).transform((value) => value).meta({
|
|
112
71
|
id: "ThemeColorValues",
|
|
113
72
|
description: "Exact value (hex, rgb, rgba, hsl, hsla ...) or break down of specific color values"
|
|
114
|
-
}).transform((value) => {
|
|
115
|
-
if (typeof value === "string") return computeColorValues(value);
|
|
116
|
-
return value;
|
|
117
73
|
});
|
|
118
|
-
const ThemeColorsSchema = z.
|
|
119
|
-
id: "ThemeColors",
|
|
120
|
-
description: "Override theme colors"
|
|
121
|
-
}).transform((value) => value);
|
|
74
|
+
const ThemeColorsSchema = z.partialRecord(color, ThemeColorValuesSchema).transform((value) => value);
|
|
122
75
|
const DimensionsSchema = z.strictObject({
|
|
123
76
|
width: z.number().min(50),
|
|
124
77
|
height: z.number().min(50)
|
|
125
78
|
}).meta({
|
|
126
79
|
id: "Dimensions",
|
|
127
|
-
description: "
|
|
128
|
-
});
|
|
129
|
-
const LikeC4Config_Styles_Theme_Sizes = z.strictObject(t(Sizes, () => DimensionsSchema.optional())).meta({
|
|
130
|
-
id: "ThemeSizes",
|
|
131
|
-
description: "Override theme sizes"
|
|
80
|
+
description: "Defines dimensions for theme size"
|
|
132
81
|
});
|
|
82
|
+
const LikeC4Config_Styles_Theme_Sizes = z.partialRecord(size, DimensionsSchema);
|
|
133
83
|
const LikeC4Config_Styles_Theme = z.strictObject({
|
|
134
|
-
colors: ThemeColorsSchema.optional(),
|
|
135
|
-
sizes: LikeC4Config_Styles_Theme_Sizes.optional()
|
|
84
|
+
colors: ThemeColorsSchema.optional().meta({ description: "Override theme colors" }),
|
|
85
|
+
sizes: LikeC4Config_Styles_Theme_Sizes.optional().meta({ description: "Override theme sizes" })
|
|
136
86
|
}).meta({
|
|
137
87
|
id: "ThemeCustomization",
|
|
138
|
-
description: "
|
|
88
|
+
description: "Customize theme colors and sizes"
|
|
139
89
|
}).transform(({ colors, sizes }) => {
|
|
140
90
|
return exact({
|
|
141
91
|
colors: colors ? exact(colors) : void 0,
|
|
@@ -146,10 +96,7 @@ const LikeC4Config_Styles_Defaults_Group = z.strictObject({
|
|
|
146
96
|
color: color.optional().meta({ description: "Default color for groups\n(must be a valid color name from the theme)" }),
|
|
147
97
|
opacity: opacity.optional().meta({ description: "Default opacity for groups" }),
|
|
148
98
|
border: border.optional().meta({ description: "Default border for groups" })
|
|
149
|
-
}).meta({
|
|
150
|
-
id: "GroupDefaultStyleValues",
|
|
151
|
-
description: "Override default values for group style properties\nThese values will be used if such property is not defined"
|
|
152
|
-
});
|
|
99
|
+
}).meta({ id: "GroupDefaultStyleValues" });
|
|
153
100
|
const LikeC4Config_Styles_Defaults_Relationship = z.strictObject({
|
|
154
101
|
color: color.optional().meta({ description: "Default color for relationships\n(must be a valid color name from the theme)" }),
|
|
155
102
|
line: line.optional().meta({ description: "Default line style for relationships" }),
|
|
@@ -165,23 +112,14 @@ const LikeC4Config_Styles_Defaults = z.strictObject({
|
|
|
165
112
|
size: size.optional().meta({ description: "Default size for elements" }),
|
|
166
113
|
shape: shape.optional().meta({ description: "Default shape for elements" }),
|
|
167
114
|
iconPosition: iconPosition.optional().meta({ description: "Default icon position for elements" }),
|
|
168
|
-
group: LikeC4Config_Styles_Defaults_Group.optional().meta({ description: "
|
|
169
|
-
relationship: LikeC4Config_Styles_Defaults_Relationship.optional().meta({ description: "
|
|
170
|
-
}).meta({
|
|
171
|
-
|
|
172
|
-
description: "Override default values for style properties\nThese values will be used if such property is not defined"
|
|
173
|
-
});
|
|
174
|
-
const LikeC4Config_Styles_CustomStylesheets = z.union([z.string().min(1, "Custom CSS file path cannot be empty"), z.array(z.string().min(1, "Custom CSS file path cannot be empty"))]).meta({
|
|
175
|
-
id: "CustomStylesheets",
|
|
176
|
-
description: "Custom CSS (or list of CSS files) to be included in the generated diagrams"
|
|
177
|
-
});
|
|
115
|
+
group: LikeC4Config_Styles_Defaults_Group.optional().meta({ description: "Override default values for group style properties\nThese values will be used if such property is not defined" }),
|
|
116
|
+
relationship: LikeC4Config_Styles_Defaults_Relationship.optional().meta({ description: "Override default values for relationship style properties\nThese values will be used if such property is not defined" })
|
|
117
|
+
}).meta({ id: "DefaultStyleValues" });
|
|
118
|
+
const LikeC4Config_Styles_CustomStylesheets = z.union([z.string().min(1, "Custom CSS file path cannot be empty"), z.array(z.string().min(1, "Custom CSS file path cannot be empty"))]).meta({ id: "CustomStylesheets" });
|
|
178
119
|
const LikeC4StylesConfigSchema = z.strictObject({
|
|
179
|
-
theme: LikeC4Config_Styles_Theme.optional(),
|
|
180
|
-
defaults: LikeC4Config_Styles_Defaults.optional(),
|
|
181
|
-
customCss: LikeC4Config_Styles_CustomStylesheets.optional()
|
|
182
|
-
}).meta({
|
|
183
|
-
id: "StylesConfiguration",
|
|
184
|
-
description: "Project styles customization"
|
|
120
|
+
theme: LikeC4Config_Styles_Theme.optional().meta({ description: "Project theme customization" }),
|
|
121
|
+
defaults: LikeC4Config_Styles_Defaults.optional().meta({ description: "Override default values for style properties\nThese values will be used if such property is not defined" }),
|
|
122
|
+
customCss: LikeC4Config_Styles_CustomStylesheets.optional().meta({ description: "Custom CSS (or list of CSS files) to be included in the generated diagrams" })
|
|
185
123
|
}).transform(({ theme, defaults, customCss }) => exact({
|
|
186
124
|
defaults: normalizeDefaults(defaults),
|
|
187
125
|
customCss: normalizeStylesheets(customCss),
|
|
@@ -205,16 +143,13 @@ function normalizeStylesheets(stylesheets) {
|
|
|
205
143
|
content: ""
|
|
206
144
|
};
|
|
207
145
|
}
|
|
208
|
-
|
|
209
|
-
//#endregion
|
|
210
|
-
//#region src/schema.ts
|
|
211
146
|
const ManualLayoutsConfigSchema = z.strictObject({ outDir: z.string().default(".likec4").meta({ description: [
|
|
212
147
|
"Path to the directory where manual layouts will be stored,",
|
|
213
148
|
"relative to the folder containing the project config. ",
|
|
214
149
|
"",
|
|
215
150
|
"Defaults to '.likec4'."
|
|
216
151
|
].join("\n") }) }).meta({
|
|
217
|
-
id: "
|
|
152
|
+
id: "ManualLayoutsConfig",
|
|
218
153
|
description: "Configuration for manual layouts"
|
|
219
154
|
});
|
|
220
155
|
const LikeC4ProjectJsonConfigSchema = z.object({
|
|
@@ -225,30 +160,42 @@ const LikeC4ProjectJsonConfigSchema = z.object({
|
|
|
225
160
|
abort: true,
|
|
226
161
|
error: "Project name cannot contain \".\", \"@\" or \"#\", try to use A-z, 0-9, _ and -"
|
|
227
162
|
}).meta({ description: "Project name, must be unique in the workspace" }),
|
|
163
|
+
extends: z.union([z.string().min(1, "Extend path cannot be empty"), z.array(z.string().min(1, "Extend path cannot be empty")).min(1, "Extend list cannot be empty")]).optional().meta({ description: "Extend styles from other config files" }),
|
|
228
164
|
title: z.string().nonempty("Project title cannot be empty if specified").optional().meta({ description: "A human readable title for the project" }),
|
|
229
165
|
contactPerson: z.string().nonempty("Contact person cannot be empty if specified").optional().meta({ description: "A person who has been involved in creating or maintaining this project" }),
|
|
166
|
+
styles: LikeC4StylesConfigSchema.optional().meta({ description: "Project styles customization" }),
|
|
230
167
|
imageAliases: ImageAliasesSchema.optional(),
|
|
231
|
-
include: IncludeSchema,
|
|
232
|
-
styles: LikeC4StylesConfigSchema.optional(),
|
|
168
|
+
include: IncludeSchema.optional(),
|
|
233
169
|
exclude: z.array(z.string()).optional().meta({ description: "List of file patterns to exclude from the project, default is [\"**/node_modules/**\"]" }),
|
|
234
170
|
manualLayouts: ManualLayoutsConfigSchema.optional()
|
|
235
|
-
}).meta({
|
|
171
|
+
}).meta({
|
|
172
|
+
id: "LikeC4ProjectConfig",
|
|
173
|
+
description: "LikeC4 Project Configuration"
|
|
174
|
+
});
|
|
236
175
|
const FunctionType = z.instanceof(Function);
|
|
237
176
|
const GeneratorsSchema = z.record(z.string(), FunctionType);
|
|
238
177
|
const LikeC4ProjectConfigSchema = LikeC4ProjectJsonConfigSchema.extend({ generators: GeneratorsSchema.optional() });
|
|
239
|
-
/**
|
|
240
|
-
* Validates JSON string or JSON object into a LikeC4ProjectConfig object.
|
|
241
|
-
*/
|
|
242
178
|
function validateProjectConfig(config) {
|
|
243
|
-
const parsed = LikeC4ProjectConfigSchema.safeParse(
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
-
if (parsed.data.include) validateIncludePaths(parsed.data.include);
|
|
247
|
-
return parsed.data;
|
|
179
|
+
const parsed = LikeC4ProjectConfigSchema.safeParse(config);
|
|
180
|
+
if (parsed.success) return parsed.data;
|
|
181
|
+
throw new Error("Config validation failed:\n" + z.prettifyError(parsed.error));
|
|
248
182
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
183
|
+
function parseProjectConfigJSON(config) {
|
|
184
|
+
return validateProjectConfig(JSON5.parse(config.trim() || "{}"));
|
|
185
|
+
}
|
|
186
|
+
const LikeC4ProjectConfigOps = {
|
|
187
|
+
parse: parseProjectConfigJSON,
|
|
188
|
+
validate: validateProjectConfig,
|
|
189
|
+
normalizeInclude: (include) => {
|
|
190
|
+
const parsed = IncludeSchema.safeParse(include);
|
|
191
|
+
if (parsed.success) return parsed.data;
|
|
192
|
+
return {
|
|
193
|
+
paths: [],
|
|
194
|
+
maxDepth: 3,
|
|
195
|
+
fileThreshold: 30
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
};
|
|
252
199
|
const configJsonFilenames = [
|
|
253
200
|
".likec4rc",
|
|
254
201
|
".likec4.config.json",
|
|
@@ -263,145 +210,28 @@ const configNonJsonFilenames = [
|
|
|
263
210
|
"likec4.config.mts"
|
|
264
211
|
];
|
|
265
212
|
const ConfigFilenames = [...configJsonFilenames, ...configNonJsonFilenames];
|
|
266
|
-
/**
|
|
267
|
-
* Checks if the given filename is a LikeC4 JSON config file (JSON, RC).
|
|
268
|
-
*/
|
|
269
213
|
function isLikeC4JsonConfig(filename) {
|
|
270
|
-
|
|
271
|
-
return false;
|
|
214
|
+
return configJsonFilenames.includes(basename(filename));
|
|
272
215
|
}
|
|
273
|
-
/**
|
|
274
|
-
* Checks if the given filename is a LikeC4 non-JSON config file (JS, MJS, TS, MTS)
|
|
275
|
-
*/
|
|
276
216
|
function isLikeC4NonJsonConfig(filename) {
|
|
277
|
-
|
|
278
|
-
return false;
|
|
217
|
+
return configNonJsonFilenames.includes(basename(filename));
|
|
279
218
|
}
|
|
280
|
-
/**
|
|
281
|
-
* Checks if the given filename is a LikeC4 config file (JSON or non-JSON)
|
|
282
|
-
*/
|
|
283
219
|
function isLikeC4Config(filename) {
|
|
284
220
|
return isLikeC4JsonConfig(filename) || isLikeC4NonJsonConfig(filename);
|
|
285
221
|
}
|
|
286
|
-
|
|
287
|
-
//#endregion
|
|
288
|
-
//#region src/define-config.ts
|
|
289
|
-
/**
|
|
290
|
-
* Defines LikeC4 Project, allows custom generators that can be executed using CLI:
|
|
291
|
-
*
|
|
292
|
-
* `$ likec4 gen <generator-name>`
|
|
293
|
-
*
|
|
294
|
-
* or VSCode command `LikeC4: Run code generator`
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```ts
|
|
298
|
-
* export default defineConfig({
|
|
299
|
-
* name: 'my-project',
|
|
300
|
-
* title: 'My Project',
|
|
301
|
-
*
|
|
302
|
-
* exclude: ['picomatch pattern'],
|
|
303
|
-
* generators: {
|
|
304
|
-
* '<generator-name>': async ({ likec4model, ctx }) => {
|
|
305
|
-
* await ctx.write('my-generator.txt', likec4model.project.id)
|
|
306
|
-
* }
|
|
307
|
-
* }
|
|
308
|
-
* })
|
|
309
|
-
* ```
|
|
310
|
-
*/
|
|
311
222
|
function defineConfig(config) {
|
|
312
223
|
return LikeC4ProjectConfigSchema.parse(config);
|
|
313
224
|
}
|
|
314
|
-
/**
|
|
315
|
-
* Define reusable custom generators
|
|
316
|
-
*
|
|
317
|
-
* @example
|
|
318
|
-
* ```ts
|
|
319
|
-
* // generators.ts
|
|
320
|
-
* export default defineGenerators({
|
|
321
|
-
* 'my-generator': async ({ likec4model, ctx }) => {
|
|
322
|
-
* await ctx.write('my-generator.txt', likec4model.project.id)
|
|
323
|
-
* }
|
|
324
|
-
* })
|
|
325
|
-
*
|
|
326
|
-
* // likec4.config.ts
|
|
327
|
-
* import generators from './generators'
|
|
328
|
-
*
|
|
329
|
-
* export default defineConfig({
|
|
330
|
-
* name: 'my-project',
|
|
331
|
-
* generators,
|
|
332
|
-
* })
|
|
333
|
-
* ```
|
|
334
|
-
*/
|
|
335
225
|
function defineGenerators(generators) {
|
|
336
226
|
return GeneratorsSchema.parse(generators);
|
|
337
227
|
}
|
|
338
|
-
/**
|
|
339
|
-
* Define reusable custom theme color
|
|
340
|
-
* @example
|
|
341
|
-
* ```ts
|
|
342
|
-
* export default defineThemeColor({
|
|
343
|
-
* element: {
|
|
344
|
-
* fill: 'red'
|
|
345
|
-
* }
|
|
346
|
-
* })
|
|
347
|
-
* ```
|
|
348
|
-
*/
|
|
349
228
|
function defineThemeColor(colors) {
|
|
350
229
|
return ThemeColorValuesSchema.parse(colors);
|
|
351
230
|
}
|
|
352
|
-
/**
|
|
353
|
-
* Define reusable custom theme
|
|
354
|
-
* @example
|
|
355
|
-
* ```ts
|
|
356
|
-
* import { defineThemeColor, defineTheme } from 'likec4/config'
|
|
357
|
-
*
|
|
358
|
-
* export default defineTheme({
|
|
359
|
-
* colors: {
|
|
360
|
-
* primary: '#FF0000',
|
|
361
|
-
* // Or use defineThemeColor
|
|
362
|
-
* red: defineThemeColor({
|
|
363
|
-
* elements: {
|
|
364
|
-
* fill: 'red'
|
|
365
|
-
* }
|
|
366
|
-
* })
|
|
367
|
-
* }
|
|
368
|
-
* })
|
|
369
|
-
* ```
|
|
370
|
-
*/
|
|
371
231
|
function defineTheme(theme) {
|
|
372
232
|
return LikeC4Config_Styles_Theme.parse(theme);
|
|
373
233
|
}
|
|
374
|
-
/**
|
|
375
|
-
* Define reusable custom style
|
|
376
|
-
* @example
|
|
377
|
-
* ```ts
|
|
378
|
-
* import { defineStyle, defineThemeColor } from 'likec4/config'
|
|
379
|
-
*
|
|
380
|
-
* export default defineStyle({
|
|
381
|
-
* theme: {
|
|
382
|
-
* colors: {
|
|
383
|
-
* red: defineThemeColor({
|
|
384
|
-
* elements: {
|
|
385
|
-
* fill: 'red'
|
|
386
|
-
* }
|
|
387
|
-
* })
|
|
388
|
-
* }
|
|
389
|
-
* },
|
|
390
|
-
* defaults: {
|
|
391
|
-
* color: 'red',
|
|
392
|
-
* opacity: 50,
|
|
393
|
-
* border: 'solid',
|
|
394
|
-
* size: 'sm',
|
|
395
|
-
* relationship: {
|
|
396
|
-
* color: 'grey',
|
|
397
|
-
* line: 'solid',
|
|
398
|
-
* }
|
|
399
|
-
* }
|
|
400
|
-
* })
|
|
401
|
-
*/
|
|
402
234
|
function defineStyle(styles) {
|
|
403
235
|
return LikeC4StylesConfigSchema.parse(styles);
|
|
404
236
|
}
|
|
405
|
-
|
|
406
|
-
//#endregion
|
|
407
|
-
export { ConfigFilenames, defineConfig, defineGenerators, defineStyle, defineTheme, defineThemeColor, isLikeC4Config, isLikeC4JsonConfig, isLikeC4NonJsonConfig, normalizeIncludeConfig, validateIncludePaths, validateProjectConfig };
|
|
237
|
+
export { ConfigFilenames, LikeC4ProjectConfigOps, defineConfig, defineGenerators, defineStyle, defineTheme, defineThemeColor, isLikeC4Config, isLikeC4JsonConfig, isLikeC4NonJsonConfig };
|