feat: add cli command to export configs as json schema
This commit is contained in:
parent
b0a9cf1bcd
commit
b83f388096
4 changed files with 42 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -84,3 +84,4 @@ npm-audit.txt
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
config-errors.txt
|
config-errors.txt
|
||||||
|
/config-schema.json
|
||||||
|
|
18
backend/package-lock.json
generated
18
backend/package-lock.json
generated
|
@ -75,7 +75,8 @@
|
||||||
"@types/uuid": "^9.0.2",
|
"@types/uuid": "^9.0.2",
|
||||||
"ava": "^5.3.1",
|
"ava": "^5.3.1",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"source-map-support": "^0.5.16"
|
"source-map-support": "^0.5.16",
|
||||||
|
"zod-to-json-schema": "^3.22.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@assemblyscript/loader": {
|
"node_modules/@assemblyscript/loader": {
|
||||||
|
@ -10192,12 +10193,21 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/zod": {
|
"node_modules/zod": {
|
||||||
"version": "3.21.4",
|
"version": "3.22.4",
|
||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz",
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz",
|
||||||
"integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==",
|
"integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==",
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/zod-to-json-schema": {
|
||||||
|
"version": "3.22.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.22.3.tgz",
|
||||||
|
"integrity": "sha512-9isG8SqRe07p+Aio2ruBZmLm2Q6Sq4EqmXOiNpDxp+7f0LV6Q/LX65fs5Nn+FV/CzfF3NLBoksXbS2jNYIfpKw==",
|
||||||
|
"dev": true,
|
||||||
|
"peerDependencies": {
|
||||||
|
"zod": "^3.22.4"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"migrate-rollback-prod": "cross-env NODE_ENV=production npm run migrate",
|
"migrate-rollback-prod": "cross-env NODE_ENV=production npm run migrate",
|
||||||
"migrate-rollback-dev": "cross-env NODE_ENV=development npm run build && npm run migrate",
|
"migrate-rollback-dev": "cross-env NODE_ENV=development npm run build && npm run migrate",
|
||||||
"validate-active-configs": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps dist/backend/src/validateActiveConfigs.js > ../config-errors.txt",
|
"validate-active-configs": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps dist/backend/src/validateActiveConfigs.js > ../config-errors.txt",
|
||||||
|
"export-config-json-schema": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps dist/backend/src/exportSchemas.js > ../config-schema.json",
|
||||||
"test": "npm run build && npm run run-tests",
|
"test": "npm run build && npm run run-tests",
|
||||||
"run-tests": "ava",
|
"run-tests": "ava",
|
||||||
"test-watch": "tsc-watch --onSuccess \"npx ava\""
|
"test-watch": "tsc-watch --onSuccess \"npx ava\""
|
||||||
|
@ -97,7 +98,8 @@
|
||||||
"@types/uuid": "^9.0.2",
|
"@types/uuid": "^9.0.2",
|
||||||
"ava": "^5.3.1",
|
"ava": "^5.3.1",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"source-map-support": "^0.5.16"
|
"source-map-support": "^0.5.16",
|
||||||
|
"zod-to-json-schema": "^3.22.3"
|
||||||
},
|
},
|
||||||
"ava": {
|
"ava": {
|
||||||
"files": [
|
"files": [
|
||||||
|
|
24
backend/src/exportSchemas.ts
Normal file
24
backend/src/exportSchemas.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
import { guildPlugins } from "./plugins/availablePlugins";
|
||||||
|
import zodToJsonSchema from "zod-to-json-schema";
|
||||||
|
import { zZeppelinGuildConfig } from "./types";
|
||||||
|
|
||||||
|
const pluginSchemaMap = guildPlugins.reduce((map, plugin) => {
|
||||||
|
if (! plugin.info) {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
map[plugin.name] = plugin.info.configSchema;
|
||||||
|
return map;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const fullSchema = zZeppelinGuildConfig
|
||||||
|
.omit({ plugins: true })
|
||||||
|
.merge(z.strictObject({
|
||||||
|
plugins: z.strictObject(pluginSchemaMap).partial(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const jsonSchema = zodToJsonSchema(fullSchema);
|
||||||
|
|
||||||
|
console.log(JSON.stringify(jsonSchema, null, 2));
|
||||||
|
|
||||||
|
process.exit(0);
|
Loading…
Add table
Reference in a new issue