feat: add JSON schema for quest

This commit is contained in:
Justin Lin committed 2025-04-23 17:40:55 +08:00
1 parent 52e9a13645
commit ab63595fba
6 files changed
+393 -8

No files matched your search

+6 -1
View File
@@ -7,10 +7,15 @@
},
"license": "MIT",
"scripts": {
"build": "tsc -b"
"build": "tsc -b",
"generate": "tsx src/cli.ts"
},
"dependencies": {
"@linux-odyssey/file-graph": "*",
"zod": "^3.23.8"
},
"devDependencies": {
"tsx": "^4.19.3",
"zod-to-json-schema": "^3.24.5"
}
}
+189
View File
@@ -0,0 +1,189 @@
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"title": {
"type": "string"
},
"image": {
"type": "string"
},
"instruction": {
"type": "string"
},
"requirements": {
"type": "array",
"items": {
"type": "string"
},
"default": []
},
"stages": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"pattern": "^[a-zA-Z0-9_-]+$"
},
"name": {
"type": "string"
},
"requirements": {
"$ref": "#/properties/requirements",
"default": []
},
"condition": {
"type": "object",
"properties": {
"command": {
"type": "string"
},
"output": {
"type": "string"
},
"error": {
"type": "string"
},
"pwd": {
"type": "string"
},
"files": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"file",
"folder"
]
},
"exists": {
"type": "boolean"
}
},
"required": [
"path",
"type",
"exists"
],
"additionalProperties": false
}
},
"or": {
"type": "array",
"items": {
"$ref": "#/properties/stages/items/properties/condition"
}
},
"not": {
"$ref": "#/properties/stages/items/properties/condition"
}
},
"additionalProperties": false
},
"response": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"narrative",
"dialogue"
],
"default": "narrative"
},
"content": {
"type": "string"
},
"hint": {
"type": "string"
}
},
"required": [
"content"
],
"additionalProperties": false
},
"exceptions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"condition": {
"$ref": "#/properties/stages/items/properties/condition"
},
"response": {
"$ref": "#/properties/stages/items/properties/response"
},
"catchAll": {
"type": "boolean",
"default": false
}
},
"required": [
"id",
"condition",
"response"
],
"additionalProperties": false
}
}
},
"required": [
"id",
"condition",
"response"
],
"additionalProperties": false
}
},
"exceptions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"$ref": "#/properties/stages/items/properties/exceptions/items/properties/id"
},
"condition": {
"$ref": "#/properties/stages/items/properties/condition"
},
"response": {
"$ref": "#/properties/stages/items/properties/response"
},
"requirements": {
"$ref": "#/properties/requirements",
"default": []
}
},
"required": [
"id",
"condition",
"response"
],
"additionalProperties": false
}
}
},
"required": [
"id",
"title",
"image",
"instruction",
"stages"
],
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#"
}
+8
View File
@@ -0,0 +1,8 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { zodToJsonSchema } from 'zod-to-json-schema'
import fs from 'fs'
import { questSchema } from './schema'
const jsonSchema = zodToJsonSchema(questSchema)
fs.writeFileSync('quest.json', JSON.stringify(jsonSchema, null, 2))