summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-10 12:35:46 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-10 12:35:46 +0200
commit3b4e026eadd1334f3f075774613ed7e8c4203b40 (patch)
tree1d3f04b27ecfb0a5bc3a1fbce1ee7aa77ff95199
parent:bug: fix windows process.getuid (diff)
downloadserver-3b4e026eadd1334f3f075774613ed7e8c4203b40.tar.xz
:bug: fix tsc compiler
-rw-r--r--api/src/Server.ts3
-rw-r--r--bundle/scripts/build.js36
-rw-r--r--bundle/tsconfig.json21
-rw-r--r--cdn/src/Server.ts14
-rw-r--r--util/src/util/TraverseDirectory.ts10
-rw-r--r--util/src/util/index.ts1
6 files changed, 54 insertions, 31 deletions
diff --git a/api/src/Server.ts b/api/src/Server.ts
index 19e3d245..1f11a295 100644
--- a/api/src/Server.ts
+++ b/api/src/Server.ts
@@ -11,6 +11,7 @@ import TestClient from "./middlewares/TestClient";
 import { initTranslation } from "./middlewares/Translation";
 import morgan from "morgan";
 import { initInstance } from "./util/Instance";
+import { registerRoutes } from "@fosscord/util";
 
 export interface FosscordServerOptions extends ServerOptions {}
 
@@ -72,7 +73,7 @@ export class FosscordServer extends Server {
 		await initRateLimits(api);
 		await initTranslation(api);
 
-		this.routes = await this.registerRoutes(path.join(__dirname, "routes", "/"));
+		this.routes = await registerRoutes(this, path.join(__dirname, "routes", "/"));
 
 		api.use("*", (error: any, req: Request, res: Response, next: NextFunction) => {
 			if (error) return next(error);
diff --git a/bundle/scripts/build.js b/bundle/scripts/build.js
index 2a82ec57..69111c88 100644
--- a/bundle/scripts/build.js
+++ b/bundle/scripts/build.js
@@ -2,18 +2,32 @@ const { execSync } = require("child_process");
 const path = require("path");
 const fse = require("fs-extra");
 
-const api = path.join(__dirname, "..", "..", "api");
-const dist = path.join(__dirname, "..", "dist");
+fse.copySync(path.join(__dirname, "..", "..", "api", "assets"), path.join(__dirname, "..", "dist", "api", "assets"));
+fse.copySync(
+	path.join(__dirname, "..", "..", "api", "client_test"),
+	path.join(__dirname, "..", "dist", "api", "client_test")
+);
+fse.copySync(path.join(__dirname, "..", "..", "api", "locales"), path.join(__dirname, "..", "dist", "api", "locales"));
+fse.copySync(path.join(__dirname, "..", "..", "api", "src"), path.join(__dirname, "..", "dist", "api", "src"));
+fse.copySync(path.join(__dirname, "..", "..", "util", "src"), path.join(__dirname, "..", "dist", "util", "src"));
+fse.copySync(path.join(__dirname, "..", "..", "cdn", "src"), path.join(__dirname, "..", "dist", "cdn", "src"));
+fse.copySync(path.join(__dirname, "..", "..", "gateway", "src"), path.join(__dirname, "..", "dist", "gateway", "src"));
+fse.copySync(path.join(__dirname, "..", "..", "bundle", "src"), path.join(__dirname, "..", "dist", "bundle", "src"));
 
-fse.copySync(path.join(api, "assets"), path.join(dist, "api", "assets"));
-fse.copySync(path.join(api, "client_test"), path.join(dist, "api", "client_test"));
-fse.copySync(path.join(api, "locales"), path.join(dist, "api", "locales"));
+console.log("Copying   src files done");
+console.log("Compiling src files ...");
 
 console.log(
-	execSync("node " + path.join(__dirname, "..", "node_modules", "typescript", "lib", "tsc.js") + " -p .", {
-		cwd: path.join(__dirname, ".."),
-		shell: true,
-		env: process.env,
-		encoding: "utf8",
-	})
+	execSync(
+		"node " +
+			path.join(__dirname, "..", "node_modules", "typescript", "lib", "tsc.js") +
+			" -p " +
+			path.join(__dirname, ".."),
+		{
+			cwd: path.join(__dirname, ".."),
+			shell: true,
+			env: process.env,
+			encoding: "utf8",
+		}
+	)
 );
diff --git a/bundle/tsconfig.json b/bundle/tsconfig.json
index 1b2949da..4e8db342 100644
--- a/bundle/tsconfig.json
+++ b/bundle/tsconfig.json
@@ -1,16 +1,11 @@
 {
-	"include": [
-		"../api/src/**/*.ts",
-		"../gateway/src/**/*.ts",
-		"../cdn/src/**/*.ts",
-		"../util/src/**/*.ts",
-		"src/**/*.ts"
-	],
+	"include": ["dist/**/*.ts"],
+	"exclude": [],
 	"compilerOptions": {
 		/* Visit https://aka.ms/tsconfig.json to read more about this file */
 
 		/* Basic Options */
-		"incremental": true /* Enable incremental compilation */,
+		"incremental": false /* Enable incremental compilation */,
 		"target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
 		"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
 		"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
@@ -22,7 +17,7 @@
 		"sourceMap": false /* Generates corresponding '.map' file. */,
 		// "outFile": "./",                       /* Concatenate and emit output to single file. */
 		"outDir": "./dist/" /* Redirect output structure to the directory. */,
-		"rootDir": "../" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
+		"rootDir": "./dist/" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
 		// "composite": true,                     /* Enable project compilation */
 		// "tsBuildInfoFile": "./",               /* Specify file to store incremental compilation information */
 		// "removeComments": true,                /* Do not emit comments to output. */
@@ -73,16 +68,12 @@
 		"emitDecoratorMetadata": true,
 		"experimentalDecorators": true,
 		"resolveJsonModule": true,
-		"baseUrl": "..",
+		"baseUrl": "./dist/",
 		"paths": {
 			"@fosscord/api": ["api/src/index"],
-			"@fosscord/api/*": ["api/src/*"],
 			"@fosscord/gateway": ["gateway/src/index"],
-			"@fosscord/gateway/*": ["gateway/src/*"],
 			"@fosscord/cdn": ["cdn/src/index"],
-			"@fosscord/cdn/*": ["cdn/src/*"],
-			"@fosscord/util": ["util/src/index"],
-			"@fosscord/util/*": ["util/src/*"]
+			"@fosscord/util": ["util/src/index"]
 		},
 		"plugins": [{ "transform": "@zerollup/ts-transform-paths" }]
 	}
diff --git a/cdn/src/Server.ts b/cdn/src/Server.ts
index 590eda6f..cac34a80 100644
--- a/cdn/src/Server.ts
+++ b/cdn/src/Server.ts
@@ -1,5 +1,5 @@
 import { Server, ServerOptions } from "lambert-server";
-import { Config, initDatabase } from "@fosscord/util";
+import { Config, initDatabase, registerRoutes } from "@fosscord/util";
 import path from "path";
 import avatarsRoute from "./routes/avatars";
 import bodyParser from "body-parser";
@@ -23,13 +23,19 @@ export class CDNServer extends Server {
 				"Content-security-policy",
 				"default-src *  data: blob: filesystem: about: ws: wss: 'unsafe-inline' 'unsafe-eval'; script-src * data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src * data: blob: 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src * data: blob: ; style-src * data: blob: 'unsafe-inline'; font-src * data: blob: 'unsafe-inline';"
 			);
-			res.set("Access-Control-Allow-Headers", req.header("Access-Control-Request-Headers") || "*");
-			res.set("Access-Control-Allow-Methods", req.header("Access-Control-Request-Methods") || "*");
+			res.set(
+				"Access-Control-Allow-Headers",
+				req.header("Access-Control-Request-Headers") || "*"
+			);
+			res.set(
+				"Access-Control-Allow-Methods",
+				req.header("Access-Control-Request-Methods") || "*"
+			);
 			next();
 		});
 		this.app.use(bodyParser.json({ inflate: true, limit: "10mb" }));
 
-		await this.registerRoutes(path.join(__dirname, "routes/"));
+		await registerRoutes(this, path.join(__dirname, "routes/"));
 
 		this.app.use("/icons/", avatarsRoute);
 		this.log("verbose", "[Server] Route /icons registered");
diff --git a/util/src/util/TraverseDirectory.ts b/util/src/util/TraverseDirectory.ts
new file mode 100644
index 00000000..275b7dcc
--- /dev/null
+++ b/util/src/util/TraverseDirectory.ts
@@ -0,0 +1,10 @@
+import { Server, traverseDirectory } from "lambert-server";
+
+const DEFAULT_FILTER = /^([^\.].*)(?<!\.d)\.(js)$/;
+
+export function registerRoutes(server: Server, root: string) {
+	return traverseDirectory(
+		{ dirname: root, recursive: true, filter: DEFAULT_FILTER },
+		server.registerRoute.bind(server, root)
+	);
+}
diff --git a/util/src/util/index.ts b/util/src/util/index.ts
index 67583635..c5703468 100644
--- a/util/src/util/index.ts
+++ b/util/src/util/index.ts
@@ -17,3 +17,4 @@ export * from "./Rights";
 export * from "./Snowflake";
 export * from "./String";
 export * from "./Array";
+export * from "./TraverseDirectory";