build: always run openapi and schema generation, use build mode
This commit is contained in:
parent
d0a83d65e1
commit
251eaf9519
Binary file not shown.
Binary file not shown.
@ -9,7 +9,8 @@
|
|||||||
"start:api": "node dist/api/start.js",
|
"start:api": "node dist/api/start.js",
|
||||||
"start:cdn": "node dist/cdn/start.js",
|
"start:cdn": "node dist/cdn/start.js",
|
||||||
"start:gateway": "node dist/gateway/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 .",
|
"watch": "tsc -w -b .",
|
||||||
"test": "node scripts/test.js",
|
"test": "node scripts/test.js",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
|
|||||||
@ -23,7 +23,7 @@ const fs = require("fs");
|
|||||||
const {
|
const {
|
||||||
NO_AUTHORIZATION_ROUTES,
|
NO_AUTHORIZATION_ROUTES,
|
||||||
} = require("../dist/api/middlewares/Authentication");
|
} = require("../dist/api/middlewares/Authentication");
|
||||||
require("missing-native-js-functions");
|
require("../dist/util/util/extensions");
|
||||||
|
|
||||||
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
|
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
|
||||||
const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json");
|
const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json");
|
||||||
@ -84,7 +84,7 @@ function combineSchemas(schemas) {
|
|||||||
|
|
||||||
for (const key in definitions) {
|
for (const key in definitions) {
|
||||||
if (!schemaRegEx.test(key)) {
|
if (!schemaRegEx.test(key)) {
|
||||||
console.error(`Invalid schema name: ${key}`);
|
console.error(`Invalid schema name: ${key}, context:`, definitions[key]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
specification.components = specification.components || {};
|
specification.components = specification.components || {};
|
||||||
@ -121,7 +121,7 @@ function apiRoutes(missingRoutes) {
|
|||||||
const tags = Array.from(routes.keys())
|
const tags = Array.from(routes.keys())
|
||||||
.map((x) => getTag(x))
|
.map((x) => getTag(x))
|
||||||
.sort((a, b) => a.localeCompare(b));
|
.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) => {
|
routes.forEach((route, pathAndMethod) => {
|
||||||
const [p, method] = pathAndMethod.split("|");
|
const [p, method] = pathAndMethod.split("|");
|
||||||
@ -213,7 +213,7 @@ function apiRoutes(missingRoutes) {
|
|||||||
obj.parameters = [...(obj.parameters || []), ...query];
|
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(/\/$/, ""))) {
|
if (missingRoutes.additional.includes(path.replace(/\/$/, ""))) {
|
||||||
obj["x-badges"] = [
|
obj["x-badges"] = [
|
||||||
@ -255,6 +255,14 @@ async function main() {
|
|||||||
.replaceAll("#/definitions", "#/components/schemas")
|
.replaceAll("#/definitions", "#/components/schemas")
|
||||||
.replaceAll("bigint", "number"),
|
.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();
|
main();
|
||||||
|
|||||||
@ -115,6 +115,7 @@ function main() {
|
|||||||
deleteOneOfKindUndefinedRecursive(definitions, "$");
|
deleteOneOfKindUndefinedRecursive(definitions, "$");
|
||||||
|
|
||||||
fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4));
|
fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4));
|
||||||
|
console.log("Successfully wrote", Object.keys(definitions).length, "schemas to", schemaPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteOneOfKindUndefinedRecursive(obj, path) {
|
function deleteOneOfKindUndefinedRecursive(obj, path) {
|
||||||
|
|||||||
@ -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
|
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);
|
const opts = args.find((x) => x?.prototype?.OPTS_MARKER == true);
|
||||||
if (!opts)
|
if (!opts)
|
||||||
return console.error(
|
return console.error(
|
||||||
`${file} has route without route() description middleware`,
|
`${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");
|
opts.file = file.replace("/dist/", "/src/").replace(".js", ".ts");
|
||||||
routes.set(prefix + path + "|" + method, opts());
|
routes.set(prefix + path + "|" + method, opts());
|
||||||
};
|
}
|
||||||
|
|
||||||
express.Router = () => {
|
express.Router = () => {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
|
|||||||
Reference in New Issue
Block a user