Add Zod schemas for project config and secrets types
This commit is contained in:
parent
5dbca049b6
commit
cfce62195d
122
src/types/config.ts
Normal file
122
src/types/config.ts
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
// region ModrinthDependency — config 中的 Modrinth 依赖项(比 VersionDependency 简化)
|
||||||
|
export const ModrinthDependencySchema = z.object({
|
||||||
|
/** 依赖类型 */
|
||||||
|
dependency_type: z.enum([
|
||||||
|
"required",
|
||||||
|
"optional",
|
||||||
|
"incompatible",
|
||||||
|
"embedded",
|
||||||
|
]),
|
||||||
|
/** 依赖的项目 ID(8 位 base62) */
|
||||||
|
project_id: z.string().min(1),
|
||||||
|
});
|
||||||
|
export type ModrinthDependency = z.infer<typeof ModrinthDependencySchema>;
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region ModrinthConfig — config 中 modrinth 字段
|
||||||
|
export const ModrinthConfigSchema = z.object({
|
||||||
|
/** Modrinth 项目 ID(8 位 base62) */
|
||||||
|
project_id: z.string().min(1),
|
||||||
|
/** 版本名称模板,支持 ${version}、${mc_version_range} 等占位符 */
|
||||||
|
version_name: z.string().min(1),
|
||||||
|
/** 版本号模板,支持 ${version}、${mc_version} 等占位符 */
|
||||||
|
version: z.string().min(1),
|
||||||
|
/** 加载器列表 */
|
||||||
|
loaders: z.array(z.string().min(1)),
|
||||||
|
/** 运行环境 */
|
||||||
|
environment: z.enum([
|
||||||
|
"unknown",
|
||||||
|
"client_only",
|
||||||
|
"server_only",
|
||||||
|
"dedicated_server_only",
|
||||||
|
"client_and_server",
|
||||||
|
"server_only_client_optional",
|
||||||
|
"client_only_server_optional",
|
||||||
|
"client_or_server_prefers_both",
|
||||||
|
"client_or_server",
|
||||||
|
"singleplayer_only",
|
||||||
|
]),
|
||||||
|
/** 依赖列表,无依赖填 [] */
|
||||||
|
dependencies: z.array(ModrinthDependencySchema),
|
||||||
|
});
|
||||||
|
export type ModrinthConfig = z.infer<typeof ModrinthConfigSchema>;
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region CurseForgeRelationProject — config 中 CurseForge 关联项目
|
||||||
|
export const CurseForgeRelationProjectSchema = z.object({
|
||||||
|
/** 关联项目的 slug */
|
||||||
|
slug: z.string().min(1),
|
||||||
|
/** 关联项目的 ID(精确匹配),可选 */
|
||||||
|
projectID: z.string().optional(),
|
||||||
|
/** 关联类型 */
|
||||||
|
type: z.enum([
|
||||||
|
"embeddedLibrary",
|
||||||
|
"incompatible",
|
||||||
|
"optionalDependency",
|
||||||
|
"requiredDependency",
|
||||||
|
"tool",
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
export type CurseForgeRelationProject = z.infer<
|
||||||
|
typeof CurseForgeRelationProjectSchema
|
||||||
|
>;
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region CurseForgeRelations — config 中 CurseForge 关联项目集合
|
||||||
|
export const CurseForgeRelationsSchema = z.object({
|
||||||
|
projects: z.array(CurseForgeRelationProjectSchema),
|
||||||
|
});
|
||||||
|
export type CurseForgeRelations = z.infer<typeof CurseForgeRelationsSchema>;
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region CurseForgeConfig — config 中 curseforge 字段
|
||||||
|
export const CurseForgeConfigSchema = z.object({
|
||||||
|
/** CurseForge 项目 ID(数字) */
|
||||||
|
project_id: z.number().int().positive(),
|
||||||
|
/** 版本名称模板,支持 ${filename_format} 等占位符 */
|
||||||
|
version_name: z.string().min(1),
|
||||||
|
/** 运行环境 */
|
||||||
|
environment: z.array(z.string().min(1)),
|
||||||
|
/** 加载器列表 */
|
||||||
|
loaders: z.array(z.string().min(1)),
|
||||||
|
/** 关联项目 */
|
||||||
|
relations: CurseForgeRelationsSchema,
|
||||||
|
});
|
||||||
|
export type CurseForgeConfig = z.infer<typeof CurseForgeConfigSchema>;
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Config — configs/{name}.json 完整结构
|
||||||
|
export const ConfigSchema = z.object({
|
||||||
|
/** 配置文件显示名称(模组名称) */
|
||||||
|
name: z.string().min(1),
|
||||||
|
/** Modrinth 配置 */
|
||||||
|
modrinth: ModrinthConfigSchema,
|
||||||
|
/** CurseForge 配置 */
|
||||||
|
curseforge: CurseForgeConfigSchema,
|
||||||
|
/** 项目目录绝对路径 */
|
||||||
|
project_dir: z.string().min(1),
|
||||||
|
/** 相对 project_dir 的 MC 版本配置目录,默认 ./properties */
|
||||||
|
minecraft_properties_dir: z.string().min(1),
|
||||||
|
/** 相对 project_dir 的项目版本配置文件路径,默认 ./gradle.properties */
|
||||||
|
project_properties_path: z.string().min(1),
|
||||||
|
/** 版本号在 project_properties_path 文件中的键名,默认 "mod_version" */
|
||||||
|
mod_version_field: z.string().min(1),
|
||||||
|
/** 构建产物文件名模板,支持 ${version}、${mc_version} 占位符 */
|
||||||
|
filename_format: z.string().min(1),
|
||||||
|
/** 源码 jar 文件名模板,支持 ${version}、${mc_version} 占位符 */
|
||||||
|
source_filename_format: z.string().min(1),
|
||||||
|
});
|
||||||
|
export type Config = z.infer<typeof ConfigSchema>;
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Secrets — secrets.json 结构
|
||||||
|
export const SecretsSchema = z.object({
|
||||||
|
/** CurseForge API Token */
|
||||||
|
curseforge: z.string().min(1),
|
||||||
|
/** Modrinth Personal Access Token */
|
||||||
|
modrinth: z.string().min(1),
|
||||||
|
});
|
||||||
|
export type Secrets = z.infer<typeof SecretsSchema>;
|
||||||
|
// endregion
|
||||||
@ -1,3 +1,3 @@
|
|||||||
|
export * from "./config";
|
||||||
export * from "./modrinth";
|
export * from "./modrinth";
|
||||||
export * from "./curseforge";
|
export * from "./curseforge";
|
||||||
// export * from "./config"; // TODO
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user