Przeglądaj źródła

ci: generate config schema as part of build

Dax Raad 7 miesięcy temu
rodzic
commit
5c626e0a2f

+ 3 - 1
packages/opencode/script/schema.ts

@@ -4,6 +4,8 @@ import "zod-openapi/extend"
 import { Config } from "../src/config/config"
 import { Config } from "../src/config/config"
 import { zodToJsonSchema } from "zod-to-json-schema"
 import { zodToJsonSchema } from "zod-to-json-schema"
 
 
+const file = process.argv[2]
+
 const result = zodToJsonSchema(Config.Info, {
 const result = zodToJsonSchema(Config.Info, {
   /**
   /**
    * We'll use the `default` values of the field as the only value in `examples`.
    * We'll use the `default` values of the field as the only value in `examples`.
@@ -30,4 +32,4 @@ const result = zodToJsonSchema(Config.Info, {
     return jsonSchema
     return jsonSchema
   },
   },
 })
 })
-await Bun.write("config.schema.json", JSON.stringify(result, null, 2))
+await Bun.write(file, JSON.stringify(result, null, 2))

+ 15 - 0
packages/web/astro.config.mjs

@@ -7,6 +7,7 @@ import theme from "toolbeam-docs-theme"
 import config from "./config.mjs"
 import config from "./config.mjs"
 import { rehypeHeadingIds } from "@astrojs/markdown-remark"
 import { rehypeHeadingIds } from "@astrojs/markdown-remark"
 import rehypeAutolinkHeadings from "rehype-autolink-headings"
 import rehypeAutolinkHeadings from "rehype-autolink-headings"
+import { spawnSync } from "child_process"
 
 
 const github = "https://github.com/sst/opencode"
 const github = "https://github.com/sst/opencode"
 
 
@@ -26,7 +27,9 @@ export default defineConfig({
   markdown: {
   markdown: {
     rehypePlugins: [rehypeHeadingIds, [rehypeAutolinkHeadings, { behavior: "wrap" }]],
     rehypePlugins: [rehypeHeadingIds, [rehypeAutolinkHeadings, { behavior: "wrap" }]],
   },
   },
+  build: {},
   integrations: [
   integrations: [
+    configSchema(),
     solidJs(),
     solidJs(),
     starlight({
     starlight({
       title: "opencode",
       title: "opencode",
@@ -83,3 +86,15 @@ export default defineConfig({
     "/discord": "https://discord.com/invite/opencode",
     "/discord": "https://discord.com/invite/opencode",
   },
   },
 })
 })
+
+function configSchema() {
+  return {
+    name: "configSchema",
+    hooks: {
+      "astro:build:done": async () => {
+        console.log("generating config schema")
+        spawnSync("../opencode/script/schema.ts", ["./dist/config.json"])
+      },
+    },
+  }
+}