@zpress/config 0.1.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 +413 -0
- package/dist/index.d.ts +2310 -0
- package/dist/index.mjs +287 -0
- package/package.json +61 -0
- package/schemas/schema.json +582 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { loadConfig } from "c12";
|
|
2
|
+
import { z } from "zod/v3";
|
|
3
|
+
function defineConfig(config) {
|
|
4
|
+
return config;
|
|
5
|
+
}
|
|
6
|
+
function configError(type, message) {
|
|
7
|
+
return {
|
|
8
|
+
_tag: 'ConfigError',
|
|
9
|
+
type,
|
|
10
|
+
message
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function configErrorFromZod(zodError) {
|
|
14
|
+
return {
|
|
15
|
+
_tag: 'ConfigError',
|
|
16
|
+
type: 'validation_failed',
|
|
17
|
+
message: 'Configuration validation failed',
|
|
18
|
+
errors: zodError.issues.map((err)=>({
|
|
19
|
+
path: err.path.filter((p)=>'string' == typeof p || 'number' == typeof p),
|
|
20
|
+
message: err.message
|
|
21
|
+
}))
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const frontmatterSchema = z.object({
|
|
25
|
+
title: z.string().optional(),
|
|
26
|
+
titleTemplate: z.union([
|
|
27
|
+
z.string(),
|
|
28
|
+
z.boolean()
|
|
29
|
+
]).optional(),
|
|
30
|
+
description: z.string().optional(),
|
|
31
|
+
layout: z.string().optional(),
|
|
32
|
+
sidebar: z.boolean().optional(),
|
|
33
|
+
aside: z.union([
|
|
34
|
+
z.boolean(),
|
|
35
|
+
z.literal('left')
|
|
36
|
+
]).optional(),
|
|
37
|
+
outline: z.union([
|
|
38
|
+
z.literal(false),
|
|
39
|
+
z.number(),
|
|
40
|
+
z.tuple([
|
|
41
|
+
z.number(),
|
|
42
|
+
z.number()
|
|
43
|
+
]),
|
|
44
|
+
z.literal('deep')
|
|
45
|
+
]).optional(),
|
|
46
|
+
navbar: z.boolean().optional(),
|
|
47
|
+
editLink: z.boolean().optional(),
|
|
48
|
+
lastUpdated: z.boolean().optional(),
|
|
49
|
+
footer: z.boolean().optional(),
|
|
50
|
+
pageClass: z.string().optional(),
|
|
51
|
+
head: z.array(z.tuple([
|
|
52
|
+
z.string(),
|
|
53
|
+
z.record(z.string(), z.string())
|
|
54
|
+
])).optional()
|
|
55
|
+
}).passthrough();
|
|
56
|
+
const navItemSchema = z.lazy(()=>z.object({
|
|
57
|
+
text: z.string(),
|
|
58
|
+
link: z.string().optional(),
|
|
59
|
+
items: z.array(navItemSchema).optional(),
|
|
60
|
+
activeMatch: z.string().optional()
|
|
61
|
+
}).strict());
|
|
62
|
+
const titleConfigSchema = z.union([
|
|
63
|
+
z.string(),
|
|
64
|
+
z.object({
|
|
65
|
+
from: z["enum"]([
|
|
66
|
+
'auto',
|
|
67
|
+
'filename',
|
|
68
|
+
'heading',
|
|
69
|
+
'frontmatter'
|
|
70
|
+
]),
|
|
71
|
+
transform: z["function"]().optional()
|
|
72
|
+
}).strict()
|
|
73
|
+
]);
|
|
74
|
+
const discoverySchema = z.object({
|
|
75
|
+
from: z.string().optional(),
|
|
76
|
+
title: titleConfigSchema.optional(),
|
|
77
|
+
sort: z.union([
|
|
78
|
+
z["enum"]([
|
|
79
|
+
'alpha',
|
|
80
|
+
'filename'
|
|
81
|
+
]),
|
|
82
|
+
z["function"]()
|
|
83
|
+
]).optional(),
|
|
84
|
+
exclude: z.array(z.string()).optional(),
|
|
85
|
+
frontmatter: frontmatterSchema.optional(),
|
|
86
|
+
recursive: z.boolean().optional(),
|
|
87
|
+
indexFile: z.string().optional()
|
|
88
|
+
}).strict();
|
|
89
|
+
const cardConfigSchema = z.object({
|
|
90
|
+
icon: z.string().optional(),
|
|
91
|
+
iconColor: z.string().optional(),
|
|
92
|
+
scope: z.string().optional(),
|
|
93
|
+
description: z.string().optional(),
|
|
94
|
+
tags: z.array(z.string()).optional(),
|
|
95
|
+
badge: z.object({
|
|
96
|
+
src: z.string(),
|
|
97
|
+
alt: z.string()
|
|
98
|
+
}).strict().optional()
|
|
99
|
+
}).strict();
|
|
100
|
+
const entrySchema = z.lazy(()=>z.object({
|
|
101
|
+
title: titleConfigSchema,
|
|
102
|
+
link: z.string().optional(),
|
|
103
|
+
from: z.string().optional(),
|
|
104
|
+
prefix: z.string().optional(),
|
|
105
|
+
content: z.union([
|
|
106
|
+
z.string(),
|
|
107
|
+
z["function"]()
|
|
108
|
+
]).optional(),
|
|
109
|
+
items: z.array(entrySchema).optional(),
|
|
110
|
+
landing: z.union([
|
|
111
|
+
z["enum"]([
|
|
112
|
+
'auto',
|
|
113
|
+
'cards',
|
|
114
|
+
'overview'
|
|
115
|
+
]),
|
|
116
|
+
z.literal(false)
|
|
117
|
+
]).optional(),
|
|
118
|
+
collapsible: z.boolean().optional(),
|
|
119
|
+
exclude: z.array(z.string()).optional(),
|
|
120
|
+
hidden: z.boolean().optional(),
|
|
121
|
+
frontmatter: frontmatterSchema.optional(),
|
|
122
|
+
sort: z.union([
|
|
123
|
+
z["enum"]([
|
|
124
|
+
'alpha',
|
|
125
|
+
'filename'
|
|
126
|
+
]),
|
|
127
|
+
z["function"]()
|
|
128
|
+
]).optional(),
|
|
129
|
+
recursive: z.boolean().optional(),
|
|
130
|
+
indexFile: z.string().optional(),
|
|
131
|
+
icon: z.string().optional(),
|
|
132
|
+
iconColor: z.string().optional(),
|
|
133
|
+
card: cardConfigSchema.optional(),
|
|
134
|
+
isolated: z.boolean().optional(),
|
|
135
|
+
titleFrom: z["enum"]([
|
|
136
|
+
'filename',
|
|
137
|
+
'heading',
|
|
138
|
+
'frontmatter',
|
|
139
|
+
'auto'
|
|
140
|
+
]).optional(),
|
|
141
|
+
titleTransform: z["function"]().optional()
|
|
142
|
+
}).strict());
|
|
143
|
+
const workspaceItemSchema = z.object({
|
|
144
|
+
title: titleConfigSchema,
|
|
145
|
+
icon: z.string().optional(),
|
|
146
|
+
iconColor: z.string().optional(),
|
|
147
|
+
description: z.string(),
|
|
148
|
+
tags: z.array(z.string()).optional(),
|
|
149
|
+
badge: z.object({
|
|
150
|
+
src: z.string(),
|
|
151
|
+
alt: z.string()
|
|
152
|
+
}).strict().optional(),
|
|
153
|
+
prefix: z.string(),
|
|
154
|
+
discovery: discoverySchema.optional(),
|
|
155
|
+
items: z.array(entrySchema).optional()
|
|
156
|
+
}).strict();
|
|
157
|
+
const workspaceGroupSchema = z.object({
|
|
158
|
+
title: titleConfigSchema,
|
|
159
|
+
description: z.string(),
|
|
160
|
+
icon: z.string(),
|
|
161
|
+
items: z.array(workspaceItemSchema).min(1),
|
|
162
|
+
link: z.string().optional()
|
|
163
|
+
}).strict();
|
|
164
|
+
const featureSchema = z.object({
|
|
165
|
+
title: titleConfigSchema,
|
|
166
|
+
description: z.string(),
|
|
167
|
+
link: z.string().optional(),
|
|
168
|
+
icon: z.string().optional()
|
|
169
|
+
}).strict();
|
|
170
|
+
const openapiConfigSchema = z.object({
|
|
171
|
+
spec: z.string(),
|
|
172
|
+
prefix: z.string(),
|
|
173
|
+
title: z.string().optional()
|
|
174
|
+
}).strict();
|
|
175
|
+
const themeColorsSchema = z.object({
|
|
176
|
+
brand: z.string().optional(),
|
|
177
|
+
brandLight: z.string().optional(),
|
|
178
|
+
brandDark: z.string().optional(),
|
|
179
|
+
brandSoft: z.string().optional(),
|
|
180
|
+
bg: z.string().optional(),
|
|
181
|
+
bgAlt: z.string().optional(),
|
|
182
|
+
bgElv: z.string().optional(),
|
|
183
|
+
bgSoft: z.string().optional(),
|
|
184
|
+
text1: z.string().optional(),
|
|
185
|
+
text2: z.string().optional(),
|
|
186
|
+
text3: z.string().optional(),
|
|
187
|
+
divider: z.string().optional(),
|
|
188
|
+
border: z.string().optional(),
|
|
189
|
+
homeBg: z.string().optional()
|
|
190
|
+
}).strict();
|
|
191
|
+
const themeConfigSchema = z.object({
|
|
192
|
+
name: z.string().default('base'),
|
|
193
|
+
colorMode: z["enum"]([
|
|
194
|
+
'dark',
|
|
195
|
+
'light',
|
|
196
|
+
'toggle'
|
|
197
|
+
]).optional(),
|
|
198
|
+
switcher: z.boolean().optional(),
|
|
199
|
+
colors: themeColorsSchema.optional(),
|
|
200
|
+
darkColors: themeColorsSchema.optional()
|
|
201
|
+
}).strict();
|
|
202
|
+
const zpressConfigSchema = z.object({
|
|
203
|
+
title: z.string().optional(),
|
|
204
|
+
description: z.string().optional(),
|
|
205
|
+
theme: themeConfigSchema.optional(),
|
|
206
|
+
icon: z.string().optional(),
|
|
207
|
+
tagline: z.string().optional(),
|
|
208
|
+
apps: z.array(workspaceItemSchema).optional(),
|
|
209
|
+
packages: z.array(workspaceItemSchema).optional(),
|
|
210
|
+
workspaces: z.array(workspaceGroupSchema).optional(),
|
|
211
|
+
features: z.array(featureSchema).optional(),
|
|
212
|
+
sections: z.array(entrySchema).min(1, 'config.sections must have at least one entry'),
|
|
213
|
+
nav: z.union([
|
|
214
|
+
z.literal('auto'),
|
|
215
|
+
z.array(navItemSchema)
|
|
216
|
+
]).optional(),
|
|
217
|
+
exclude: z.array(z.string()).optional(),
|
|
218
|
+
openapi: openapiConfigSchema.optional()
|
|
219
|
+
}).strict();
|
|
220
|
+
const pathsSchema = z.object({
|
|
221
|
+
repoRoot: z.string(),
|
|
222
|
+
outputRoot: z.string(),
|
|
223
|
+
contentDir: z.string(),
|
|
224
|
+
publicDir: z.string(),
|
|
225
|
+
distDir: z.string(),
|
|
226
|
+
cacheDir: z.string()
|
|
227
|
+
}).strict();
|
|
228
|
+
function validateConfig(config) {
|
|
229
|
+
const result = zpressConfigSchema.safeParse(config);
|
|
230
|
+
if (result.success) return [
|
|
231
|
+
null,
|
|
232
|
+
result.data
|
|
233
|
+
];
|
|
234
|
+
return [
|
|
235
|
+
configErrorFromZod(result.error),
|
|
236
|
+
null
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
async function loader_loadConfig(dirOrOptions = {}) {
|
|
240
|
+
const options = resolveOptions(dirOrOptions);
|
|
241
|
+
const { cwd, configFile } = options;
|
|
242
|
+
return await loadAndValidateConfig({
|
|
243
|
+
cwd,
|
|
244
|
+
configFile
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
async function loadAndValidateConfig(options) {
|
|
248
|
+
const { cwd, configFile } = options;
|
|
249
|
+
try {
|
|
250
|
+
const result = await loadConfig({
|
|
251
|
+
cwd,
|
|
252
|
+
configFile,
|
|
253
|
+
name: 'zpress',
|
|
254
|
+
rcFile: false,
|
|
255
|
+
packageJson: false,
|
|
256
|
+
globalRc: false,
|
|
257
|
+
dotenv: false
|
|
258
|
+
});
|
|
259
|
+
const { config } = result;
|
|
260
|
+
if (!config) return [
|
|
261
|
+
configError('not_found', 'Failed to load zpress.config — no config file found'),
|
|
262
|
+
null
|
|
263
|
+
];
|
|
264
|
+
if (!config.sections || Array.isArray(config.sections) && 0 === config.sections.length) return [
|
|
265
|
+
configError('empty_sections', 'Failed to load zpress.config — no sections found'),
|
|
266
|
+
null
|
|
267
|
+
];
|
|
268
|
+
return validateConfig(config);
|
|
269
|
+
} catch (error) {
|
|
270
|
+
return [
|
|
271
|
+
configError('parse_error', `Failed to parse config file: ${getErrorMessage(error)}`),
|
|
272
|
+
null
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function resolveOptions(dirOrOptions) {
|
|
277
|
+
if ('string' == typeof dirOrOptions) return {
|
|
278
|
+
cwd: dirOrOptions
|
|
279
|
+
};
|
|
280
|
+
return dirOrOptions;
|
|
281
|
+
}
|
|
282
|
+
function getErrorMessage(error) {
|
|
283
|
+
if (error instanceof Error) return error.message;
|
|
284
|
+
return String(error);
|
|
285
|
+
}
|
|
286
|
+
export { COLOR_MODES, ICON_COLORS, THEME_NAMES, isBuiltInIconColor, isBuiltInTheme, resolveDefaultColorMode } from "@zpress/theme";
|
|
287
|
+
export { configError, configErrorFromZod, defineConfig, loader_loadConfig as loadConfig, pathsSchema, validateConfig, zpressConfigSchema };
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zpress/config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Configuration loading and validation for zpress",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"config",
|
|
7
|
+
"schema",
|
|
8
|
+
"validation",
|
|
9
|
+
"zpress"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/joggrdocs/zpress/tree/main/packages/config#readme",
|
|
12
|
+
"bugs": "https://github.com/joggrdocs/zpress/issues",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/joggrdocs/zpress.git",
|
|
17
|
+
"directory": "packages/config"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"schemas"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./schema": {
|
|
30
|
+
"default": "./schemas/schema.json"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"provenance": true
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsx scripts/generate-schema.ts && rslib build",
|
|
39
|
+
"dev": "rslib build --watch --no-clean",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"generate:schema": "tsx scripts/generate-schema.ts"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@zpress/theme": "workspace:*",
|
|
45
|
+
"c12": "4.0.0-beta.3",
|
|
46
|
+
"es-toolkit": "catalog:",
|
|
47
|
+
"ts-pattern": "catalog:",
|
|
48
|
+
"type-fest": "catalog:",
|
|
49
|
+
"zod": "catalog:"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@rslib/core": "catalog:",
|
|
53
|
+
"@types/node": "^25.5.0",
|
|
54
|
+
"tsx": "^4.21.0",
|
|
55
|
+
"typescript": "catalog:",
|
|
56
|
+
"zod-to-json-schema": "^3.25.1"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=24.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|