@zpress/config 0.2.2 → 0.4.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/index.mjs CHANGED
@@ -21,6 +21,9 @@ function configErrorFromZod(zodError) {
21
21
  }))
22
22
  };
23
23
  }
24
+ const titleTransformSchema = z.custom(isFunction);
25
+ const sortFnSchema = z.custom(isFunction);
26
+ const contentFnSchema = z.custom(isFunction);
24
27
  const frontmatterSchema = z.object({
25
28
  title: z.string().optional(),
26
29
  titleTemplate: z.union([
@@ -54,7 +57,7 @@ const frontmatterSchema = z.object({
54
57
  ])).optional()
55
58
  }).passthrough();
56
59
  const navItemSchema = z.lazy(()=>z.object({
57
- text: z.string(),
60
+ title: z.string(),
58
61
  link: z.string().optional(),
59
62
  items: z.array(navItemSchema).optional(),
60
63
  activeMatch: z.string().optional()
@@ -68,27 +71,23 @@ const titleConfigSchema = z.union([
68
71
  'heading',
69
72
  'frontmatter'
70
73
  ]),
71
- transform: z["function"]().optional()
74
+ transform: titleTransformSchema.optional()
75
+ }).strict()
76
+ ]);
77
+ const includeSchema = z.union([
78
+ z.string(),
79
+ z.array(z.string())
80
+ ]);
81
+ const iconIdSchema = z.string().refine((v)=>v.includes(':'));
82
+ const iconConfigSchema = z.union([
83
+ iconIdSchema,
84
+ z.object({
85
+ id: iconIdSchema,
86
+ color: z.string()
72
87
  }).strict()
73
88
  ]);
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
89
  const cardConfigSchema = z.object({
90
- icon: z.string().optional(),
91
- iconColor: z.string().optional(),
90
+ icon: iconConfigSchema.optional(),
92
91
  scope: z.string().optional(),
93
92
  description: z.string().optional(),
94
93
  tags: z.array(z.string()).optional(),
@@ -99,65 +98,72 @@ const cardConfigSchema = z.object({
99
98
  }).strict();
100
99
  const entrySchema = z.lazy(()=>z.object({
101
100
  title: titleConfigSchema,
102
- link: z.string().optional(),
103
- from: z.string().optional(),
104
- prefix: z.string().optional(),
101
+ description: z.string().optional(),
102
+ path: z.string().optional(),
103
+ include: includeSchema.optional(),
105
104
  content: z.union([
106
105
  z.string(),
107
- z["function"]()
106
+ contentFnSchema
108
107
  ]).optional(),
109
108
  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(),
109
+ landing: z.boolean().optional(),
118
110
  collapsible: z.boolean().optional(),
119
111
  exclude: z.array(z.string()).optional(),
120
112
  hidden: z.boolean().optional(),
121
113
  frontmatter: frontmatterSchema.optional(),
122
114
  sort: z.union([
123
115
  z["enum"]([
116
+ 'default',
124
117
  'alpha',
125
118
  'filename'
126
119
  ]),
127
- z["function"]()
120
+ sortFnSchema
128
121
  ]).optional(),
129
122
  recursive: z.boolean().optional(),
130
- indexFile: z.string().optional(),
131
- icon: z.string().optional(),
132
- iconColor: z.string().optional(),
123
+ entryFile: z.string().optional(),
124
+ icon: iconConfigSchema.optional(),
133
125
  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()
126
+ standalone: z.boolean().optional()
142
127
  }).strict());
128
+ const openapiConfigSchema = z.object({
129
+ spec: z.string(),
130
+ path: z.string(),
131
+ title: z.string().optional(),
132
+ sidebarLayout: z["enum"]([
133
+ 'method-path',
134
+ 'title'
135
+ ]).optional()
136
+ }).strict();
143
137
  const workspaceItemSchema = z.object({
144
138
  title: titleConfigSchema,
145
- icon: z.string().optional(),
146
- iconColor: z.string().optional(),
139
+ icon: iconConfigSchema.optional(),
147
140
  description: z.string(),
148
141
  tags: z.array(z.string()).optional(),
149
142
  badge: z.object({
150
143
  src: z.string(),
151
144
  alt: z.string()
152
145
  }).strict().optional(),
153
- prefix: z.string(),
154
- discovery: discoverySchema.optional(),
155
- items: z.array(entrySchema).optional()
146
+ path: z.string(),
147
+ include: includeSchema.optional(),
148
+ items: z.array(entrySchema).optional(),
149
+ sort: z.union([
150
+ z["enum"]([
151
+ 'default',
152
+ 'alpha',
153
+ 'filename'
154
+ ]),
155
+ sortFnSchema
156
+ ]).optional(),
157
+ exclude: z.array(z.string()).optional(),
158
+ recursive: z.boolean().optional(),
159
+ entryFile: z.string().optional(),
160
+ frontmatter: frontmatterSchema.optional(),
161
+ openapi: openapiConfigSchema.optional()
156
162
  }).strict();
157
163
  const workspaceGroupSchema = z.object({
158
164
  title: titleConfigSchema,
159
- description: z.string(),
160
- icon: z.string(),
165
+ description: z.string().optional(),
166
+ icon: iconIdSchema,
161
167
  items: z.array(workspaceItemSchema).min(1),
162
168
  link: z.string().optional()
163
169
  }).strict();
@@ -165,12 +171,7 @@ const featureSchema = z.object({
165
171
  title: titleConfigSchema,
166
172
  description: z.string(),
167
173
  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
+ icon: iconConfigSchema.optional()
174
175
  }).strict();
175
176
  const themeColorsSchema = z.object({
176
177
  brand: z.string().optional(),
@@ -199,22 +200,109 @@ const themeConfigSchema = z.object({
199
200
  colors: themeColorsSchema.optional(),
200
201
  darkColors: themeColorsSchema.optional()
201
202
  }).strict();
203
+ const sidebarLinkSchema = z.object({
204
+ text: z.string(),
205
+ link: z.string(),
206
+ icon: iconConfigSchema.optional(),
207
+ style: z["enum"]([
208
+ 'brand',
209
+ 'alt',
210
+ 'ghost'
211
+ ]).optional(),
212
+ shape: z["enum"]([
213
+ 'square',
214
+ 'rounded',
215
+ 'circle'
216
+ ]).optional()
217
+ }).strict();
218
+ const sidebarConfigSchema = z.object({
219
+ above: z.array(sidebarLinkSchema).optional(),
220
+ below: z.array(sidebarLinkSchema).optional()
221
+ }).strict();
222
+ const truncateConfigSchema = z.object({
223
+ title: z.number().int().min(1).optional(),
224
+ description: z.number().int().min(1).optional()
225
+ }).strict();
226
+ const homeGridConfigSchema = z.object({
227
+ columns: z.union([
228
+ z.literal(1),
229
+ z.literal(2),
230
+ z.literal(3),
231
+ z.literal(4)
232
+ ]).optional(),
233
+ truncate: truncateConfigSchema.optional()
234
+ }).strict();
235
+ const homeConfigSchema = z.object({
236
+ features: homeGridConfigSchema.optional(),
237
+ workspaces: homeGridConfigSchema.optional()
238
+ }).strict();
239
+ const heroActionSchema = z.object({
240
+ theme: z["enum"]([
241
+ 'brand',
242
+ 'alt'
243
+ ]),
244
+ text: z.string(),
245
+ link: z.string()
246
+ }).strict();
247
+ const socialLinkSchema = z.object({
248
+ icon: z.union([
249
+ z["enum"]([
250
+ 'lark',
251
+ 'discord',
252
+ 'facebook',
253
+ 'github',
254
+ 'instagram',
255
+ 'linkedin',
256
+ 'slack',
257
+ 'x',
258
+ 'youtube',
259
+ 'wechat',
260
+ 'qq',
261
+ 'juejin',
262
+ 'zhihu',
263
+ 'bilibili',
264
+ 'weibo',
265
+ 'gitlab',
266
+ 'X',
267
+ 'bluesky',
268
+ 'npm'
269
+ ]),
270
+ z.object({
271
+ svg: z.string()
272
+ }).strict()
273
+ ]),
274
+ mode: z["enum"]([
275
+ 'link',
276
+ 'text',
277
+ 'img',
278
+ 'dom'
279
+ ]),
280
+ content: z.string()
281
+ }).strict();
282
+ const footerConfigSchema = z.object({
283
+ message: z.string().optional(),
284
+ copyright: z.string().optional(),
285
+ socials: z.boolean().optional()
286
+ }).strict();
202
287
  const zpressConfigSchema = z.object({
203
288
  title: z.string().optional(),
204
289
  description: z.string().optional(),
205
290
  theme: themeConfigSchema.optional(),
206
- icon: z.string().optional(),
291
+ icon: iconIdSchema.optional(),
207
292
  tagline: z.string().optional(),
208
- apps: z.array(workspaceItemSchema).optional(),
209
- packages: z.array(workspaceItemSchema).optional(),
210
293
  workspaces: z.array(workspaceGroupSchema).optional(),
211
294
  features: z.array(featureSchema).optional(),
295
+ actions: z.array(heroActionSchema).optional(),
296
+ sidebar: sidebarConfigSchema.optional(),
212
297
  sections: z.array(entrySchema).min(1, 'config.sections must have at least one entry'),
213
298
  nav: z.union([
214
299
  z.literal('auto'),
215
300
  z.array(navItemSchema)
216
301
  ]).optional(),
217
302
  exclude: z.array(z.string()).optional(),
303
+ home: homeConfigSchema.optional(),
304
+ socialLinks: z.array(socialLinkSchema).optional(),
305
+ footer: footerConfigSchema.optional(),
218
306
  openapi: openapiConfigSchema.optional()
219
307
  }).strict();
220
308
  const pathsSchema = z.object({
@@ -225,6 +313,9 @@ const pathsSchema = z.object({
225
313
  distDir: z.string(),
226
314
  cacheDir: z.string()
227
315
  }).strict();
316
+ function isFunction(val) {
317
+ return 'function' == typeof val;
318
+ }
228
319
  function validateConfig(config) {
229
320
  const result = zpressConfigSchema.safeParse(config);
230
321
  if (result.success) return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zpress/config",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "Configuration loading and validation for zpress",
5
5
  "keywords": [
6
6
  "config",
@@ -35,28 +35,29 @@
35
35
  "provenance": true
36
36
  },
37
37
  "dependencies": {
38
- "c12": "4.0.0-beta.3",
38
+ "c12": "4.0.0-beta.4",
39
39
  "es-toolkit": "^1.45.1",
40
40
  "ts-pattern": "^5.9.0",
41
- "type-fest": "^5.4.4",
41
+ "type-fest": "^5.5.0",
42
42
  "zod": "^4.3.6",
43
- "@zpress/theme": "0.3.0"
43
+ "@zpress/theme": "0.3.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@rslib/core": "^0.20.0",
47
47
  "@types/node": "^25.5.0",
48
48
  "tsx": "^4.21.0",
49
49
  "typescript": "^5.9.3",
50
+ "vitest": "^4.1.0",
50
51
  "zod-to-json-schema": "^3.25.1"
51
52
  },
52
53
  "engines": {
53
54
  "node": ">=24.0.0"
54
55
  },
55
56
  "scripts": {
56
- "build": "tsx scripts/generate-schema.ts && rslib build",
57
+ "build": "rslib build",
57
58
  "dev": "rslib build --watch --no-clean",
58
59
  "test": "vitest run",
59
- "typecheck": "tsc --noEmit",
60
+ "typecheck": "tsgo --noEmit",
60
61
  "generate:schema": "tsx scripts/generate-schema.ts"
61
62
  }
62
63
  }