/[sudobot]/branches/6.x/scripts/generate-config-schema.ts
ViewVC logotype

Annotation of /branches/6.x/scripts/generate-config-schema.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 1860 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 #!/usr/bin/env ts-node
2    
3     /*
4     * This file is part of SudoBot.
5     *
6     * Copyright (C) 2021-2023 OSN Developers.
7     *
8     * SudoBot is free software; you can redistribute it and/or modify it
9     * under the terms of the GNU Affero General Public License as published by
10     * the Free Software Foundation, either version 3 of the License, or
11     * (at your option) any later version.
12     *
13     * SudoBot is distributed in the hope that it will be useful, but
14     * WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU Affero General Public License for more details.
17     *
18     * You should have received a copy of the GNU Affero General Public License
19     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
20     */
21     import "reflect-metadata";
22    
23     import { existsSync } from "fs";
24     import fs from "fs/promises";
25     import path from "path";
26     import { z } from "zod";
27     import { zodToJsonSchema } from "zod-to-json-schema";
28     import { GuildConfigSchema } from "../src/services/ConfigManager";
29     import { SystemConfigSchema } from "../src/types/SystemConfigSchema";
30    
31     (async () => {
32     const SCHEMA_DIR = path.join(__dirname, "../config/schema");
33     const GUILD_CONFIG_SCHEMA_FILE = path.join(SCHEMA_DIR, "config.json");
34     const SYSTEM_CONFIG_SCHEMA_FILE = path.join(SCHEMA_DIR, "system.json");
35    
36     console.info("Generating schemas...");
37    
38     const guildConfigSchema = zodToJsonSchema(z.record(z.string(), GuildConfigSchema.or(z.string())));
39     const systemConfigSchema = zodToJsonSchema(SystemConfigSchema);
40    
41     console.info("Writing schemas...");
42    
43     if (!existsSync(SCHEMA_DIR)) {
44     await fs.mkdir(SCHEMA_DIR);
45     }
46    
47     await fs.writeFile(GUILD_CONFIG_SCHEMA_FILE, JSON.stringify(guildConfigSchema, null, 4));
48     await fs.writeFile(SYSTEM_CONFIG_SCHEMA_FILE, JSON.stringify(systemConfigSchema, null, 4));
49     })();

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26