summary refs log tree commit diff
path: root/scripts/util
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-11-29 22:22:41 +0100
committerRory& <root@rory.gay>2025-11-29 22:22:41 +0100
commit2ebe2a57fbbe177512b77b0ca6b8cca6aec858c6 (patch)
treef2f7fa54bb09d219d72b3f546aa6360801d47480 /scripts/util
parentMerge pull request #1411 from MathMan05/status (diff)
downloadserver-ts-2ebe2a57fbbe177512b77b0ca6b8cca6aec858c6.tar.xz
Cut down schemas by 90%
Diffstat (limited to 'scripts/util')
-rw-r--r--scripts/util/getRouteDescriptions.js42
1 files changed, 33 insertions, 9 deletions
diff --git a/scripts/util/getRouteDescriptions.js b/scripts/util/getRouteDescriptions.js

index 54c8fe19..9f329f32 100644 --- a/scripts/util/getRouteDescriptions.js +++ b/scripts/util/getRouteDescriptions.js
@@ -2,7 +2,7 @@ const express = require("express"); const path = require("path"); const { traverseDirectory } = require("lambert-server"); const RouteUtility = require("../../dist/api/util/handlers/route.js"); -const { bgRedBright } = require("picocolors"); +const { bgRedBright, greenBright, yellowBright, blueBright, redBright, underline, bold } = require("picocolors"); const methods = ["get", "post", "put", "delete", "patch"]; const routes = new Map(); @@ -14,23 +14,47 @@ let currentPath = ""; If someone could fix that I'd really appreciate it, but for now just, don't do that :p */ +function colorizeMethod(method) { + switch (method.toLowerCase()) { + case "get": + return greenBright(method.toUpperCase()); + case "post": + return yellowBright(method.toUpperCase()); + case "put": + return blueBright(method.toUpperCase()); + case "delete": + return redBright(method.toUpperCase()); + case "patch": + return yellowBright(method.toUpperCase()); + default: + return method.toUpperCase(); + } +} + +function formatPath(path) { + return path + .replace(/:(\w+)/g, underline(":$1")) + .replace(/#(\w+)/g, underline("#$1")) + ; +} + /** * @param {string} file - * @param {string} method - * @param {string} prefix - * @param {string} path + * @param {string} apiMethod + * @param {string} apiPathPrefix + * @param {string} apiPath * @param args */ -function proxy(file, method, prefix, path, ...args) { +function proxy(file, apiMethod, apiPathPrefix, apiPath, ...args) { const opts = args.find((x) => x?.prototype?.OPTS_MARKER == true); if (!opts) return console.error( - `${bgRedBright("ERROR")} ${file} has route without route() description middleware`, + ` \x1b[5m${bgRedBright("ERROR")}\x1b[25m ${file.replace(path.resolve(__dirname, "..", "..", "dist"), "/src/")} has route without route() description middleware: ${colorizeMethod(apiMethod)} ${formatPath(apiPath)}`, ); - console.log(`${method.toUpperCase().padStart("OPTIONS".length)} ${prefix + path}`); + console.log(`${colorizeMethod(apiMethod).padStart("DELETE".length + 10)} ${formatPath(apiPathPrefix + apiPath)}`); opts.file = file.replace("/dist/", "/src/").replace(".js", ".ts"); - routes.set(prefix + path + "|" + method, opts()); + routes.set(apiPathPrefix + apiPath + "|" + apiMethod, opts()); } express.Router = () => { @@ -56,7 +80,7 @@ module.exports = function getRouteDescriptions() { currentFile = file; currentPath = file.replace(root.slice(0, -1), ""); - currentPath = currentPath.split(".").slice(0, -1).join("."); // trancate .js/.ts file extension of path + currentPath = currentPath.split(".").slice(0, -1).join("."); // truncate .js/.ts file extension of path currentPath = currentPath.replaceAll("#", ":").replaceAll("\\", "/"); // replace # with : for path parameters and windows paths with slashes if (currentPath.endsWith("/index")) currentPath = currentPath.slice(0, "/index".length * -1); // delete index from path