/[sudobot]/trunk/scripts/generate-config-schema.js
ViewVC logotype

Contents of /trunk/scripts/generate-config-schema.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 575 - (show annotations)
Mon Jul 29 17:59:26 2024 UTC (8 months ago) by rakinar2
File MIME type: text/javascript
File size: 1903 byte(s)
chore: add trunk
1 #!/usr/bin/env 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
22 const { existsSync } = require("fs");
23 const fs = require("fs/promises");
24 const path = require("path");
25 const { z } = require("zod");
26 const { zodToJsonSchema } = require("zod-to-json-schema");
27
28 require("../build/core/Client");
29 const { GuildConfigSchema } = require("../build/services/ConfigManager");
30 const { SystemConfigSchema } = require("../build/types/SystemConfigSchema");
31
32 (async () => {
33 const SCHEMA_DIR = path.join(__dirname, "../config/schema");
34 const GUILD_CONFIG_SCHEMA_FILE = path.join(SCHEMA_DIR, "config.json");
35 const SYSTEM_CONFIG_SCHEMA_FILE = path.join(SCHEMA_DIR, "system.json");
36
37 console.info("Generating schemas...");
38
39 const guildConfigSchema = zodToJsonSchema(z.record(z.string(), GuildConfigSchema.or(z.string())));
40 const systemConfigSchema = zodToJsonSchema(SystemConfigSchema);
41
42 console.info("Writing schemas...");
43
44 if (!existsSync(SCHEMA_DIR)) {
45 await fs.mkdir(SCHEMA_DIR);
46 }
47
48 await fs.writeFile(GUILD_CONFIG_SCHEMA_FILE, JSON.stringify(guildConfigSchema, null, 4));
49 await fs.writeFile(SYSTEM_CONFIG_SCHEMA_FILE, JSON.stringify(systemConfigSchema, null, 4));
50 })();

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26