build: always run openapi and schema generation, use build mode

This commit is contained in:
Rory& 2025-10-07 15:08:48 +02:00
parent d0a83d65e1
commit 251eaf9519
6 changed files with 25 additions and 8 deletions

Binary file not shown.

Binary file not shown.

View File

@ -9,7 +9,8 @@
"start:api": "node dist/api/start.js",
"start:cdn": "node dist/cdn/start.js",
"start:gateway": "node dist/gateway/start.js",
"build": "tsc -b .",
"build": "npm run build:src && npm run generate:schema && npm run generate:openapi",
"build:src": "tsc -b -v",
"watch": "tsc -w -b .",
"test": "node scripts/test.js",
"lint": "eslint .",

View File

@ -23,7 +23,7 @@ const fs = require("fs");
const {
NO_AUTHORIZATION_ROUTES,
} = require("../dist/api/middlewares/Authentication");
require("missing-native-js-functions");
require("../dist/util/util/extensions");
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json");
@ -84,7 +84,7 @@ function combineSchemas(schemas) {
for (const key in definitions) {
if (!schemaRegEx.test(key)) {
console.error(`Invalid schema name: ${key}`);
console.error(`Invalid schema name: ${key}, context:`, definitions[key]);
continue;
}
specification.components = specification.components || {};
@ -121,7 +121,7 @@ function apiRoutes(missingRoutes) {
const tags = Array.from(routes.keys())
.map((x) => getTag(x))
.sort((a, b) => a.localeCompare(b));
specification.tags = tags.unique().map((x) => ({ name: x }));
specification.tags = tags.distinct().map((x) => ({ name: x }));
routes.forEach((route, pathAndMethod) => {
const [p, method] = pathAndMethod.split("|");
@ -213,7 +213,7 @@ function apiRoutes(missingRoutes) {
obj.parameters = [...(obj.parameters || []), ...query];
}
obj.tags = [...(obj.tags || []), getTag(p)].unique();
obj.tags = [...(obj.tags || []), getTag(p)].distinct();
if (missingRoutes.additional.includes(path.replace(/\/$/, ""))) {
obj["x-badges"] = [
@ -255,6 +255,14 @@ async function main() {
.replaceAll("#/definitions", "#/components/schemas")
.replaceAll("bigint", "number"),
);
console.log("Wrote OpenAPI specification to", openapiPath);
console.log(
"Specification contains",
Object.keys(specification.paths).length,
"paths and",
Object.keys(specification.components.schemas).length,
"schemas.",
);
}
main();

View File

@ -115,6 +115,7 @@ function main() {
deleteOneOfKindUndefinedRecursive(definitions, "$");
fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4));
console.log("Successfully wrote", Object.keys(definitions).length, "schemas to", schemaPath);
}
function deleteOneOfKindUndefinedRecursive(obj, path) {

View File

@ -13,17 +13,24 @@ let currentPath = "";
If someone could fix that I'd really appreciate it, but for now just, don't do that :p
*/
const proxy = (file, method, prefix, path, ...args) => {
/**
* @param {string} file
* @param {string} method
* @param {string} prefix
* @param {string} path
* @param args
*/
function proxy(file, method, prefix, path, ...args) {
const opts = args.find((x) => x?.prototype?.OPTS_MARKER == true);
if (!opts)
return console.error(
`${file} has route without route() description middleware`,
);
console.log(prefix + path + " - " + method);
console.log(`${method.toUpperCase().padStart("OPTIONS".length)} ${prefix + path}`);
opts.file = file.replace("/dist/", "/src/").replace(".js", ".ts");
routes.set(prefix + path + "|" + method, opts());
};
}
express.Router = () => {
return Object.fromEntries(