feat: zod 라이브러리 업데이트 및 JSON 스키마 정의 개선
This commit is contained in:
@@ -2,32 +2,31 @@ import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import type { ZodTypeAny } from 'zod';
|
||||
import { zodToJsonSchema } from 'zod-to-json-schema';
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
MapResourceSchema,
|
||||
ScenarioResourceSchema,
|
||||
TurnCommandProfileInputSchema,
|
||||
UnitSetDefinitionInputSchema,
|
||||
} from '@sammo-ts/logic';
|
||||
} from '@sammo-ts/logic/resources';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
|
||||
const RESOURCE_ROOT = path.join(REPO_ROOT, 'resources');
|
||||
|
||||
const writeSchema = async (relativePath: string, schema: ZodTypeAny, name: string): Promise<void> => {
|
||||
const writeSchema = async (relativePath: string, schema: unknown): Promise<void> => {
|
||||
const outputPath = path.join(RESOURCE_ROOT, relativePath);
|
||||
const jsonSchema = zodToJsonSchema(schema, { name, target: 'jsonSchema7' });
|
||||
const jsonSchema = z.toJSONSchema(schema, { target: 'draft-07' });
|
||||
const serialized = `${JSON.stringify(jsonSchema, null, 4)}\n`;
|
||||
await fs.writeFile(outputPath, serialized, 'utf8');
|
||||
};
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
await writeSchema(path.join('map', 'schema.json'), MapResourceSchema, 'MapResource');
|
||||
await writeSchema(path.join('scenario', 'schema.json'), ScenarioResourceSchema, 'ScenarioResource');
|
||||
await writeSchema(path.join('unitset', 'schema.json'), UnitSetDefinitionInputSchema, 'UnitSetDefinition');
|
||||
await writeSchema(path.join('turn-commands', 'schema.json'), TurnCommandProfileInputSchema, 'TurnCommandProfile');
|
||||
await writeSchema(path.join('map', 'schema.json'), MapResourceSchema);
|
||||
await writeSchema(path.join('scenario', 'schema.json'), ScenarioResourceSchema);
|
||||
await writeSchema(path.join('unitset', 'schema.json'), UnitSetDefinitionInputSchema);
|
||||
await writeSchema(path.join('turn-commands', 'schema.json'), TurnCommandProfileInputSchema);
|
||||
};
|
||||
|
||||
main().catch((error) => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
ScenarioResourceSchema,
|
||||
TurnCommandProfileInputSchema,
|
||||
UnitSetDefinitionInputSchema,
|
||||
} from '@sammo-ts/logic';
|
||||
} from '@sammo-ts/logic/resources';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
Reference in New Issue
Block a user