From e9088f48a7ddf6865eb514787a4869414deac0de Mon Sep 17 00:00:00 2001 From: Kath <55346310+Kathund@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:52:26 +0800 Subject: [PATCH] fix(endpoints): Endpoints not being read on windows --- index.ts | 4 ++-- src/helper.ts | 18 +++++++++--------- tsconfig.json | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/index.ts b/index.ts index 390fe3a..40076fb 100644 --- a/index.ts +++ b/index.ts @@ -6,7 +6,7 @@ import { PORT } from "./config.json"; import express from "express"; import { join } from "path"; -const filesDir = join(__dirname, "src", "files"); +const filesDir = join(__dirname, "src", "files"); if (!existsSync(filesDir)) { mkdirSync(filesDir); } @@ -20,7 +20,7 @@ try { const result = loadEndpoints(endpointsDir, app); if (result !== undefined) { otherMessage( - `Loaded ${result.loaded} endpoints, skipped ${result.skipped} endpoints` + `Loaded ${result.loaded} endpoints, skipped ${result.skipped} endpoints`, ); } else { otherMessage(`No endpoints found in ${endpointsDir}`); diff --git a/src/helper.ts b/src/helper.ts index a75971d..2307b5a 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -1,11 +1,12 @@ -import { otherMessage, errorMessage } from './logger'; -import { readdirSync, statSync } from 'fs'; -import { Application } from 'express'; -import { join } from 'path'; +import { otherMessage, errorMessage } from "./logger"; +import { readdirSync, statSync } from "fs"; +import { Application } from "express"; +import { basename, join } from "path"; export const loadEndpoints = (directory: string, app: Application) => { try { const items = readdirSync(directory); + console.log(items); let skipped = 0; let loaded = 0; @@ -19,20 +20,19 @@ export const loadEndpoints = (directory: string, app: Application) => { skipped += result.skipped; loaded += result.loaded; } - } else if (item.toLowerCase().endsWith('.ts')) { - if (item.toLowerCase().includes('disabled')) { + } else if (item.toLowerCase().endsWith(".ts")) { + if (item.toLowerCase().includes("disabled")) { skipped++; continue; } loaded++; - // eslint-disable-next-line const route = require(itemPath).default; route(app); - otherMessage(`Loaded ${itemPath.split('/src/endpoints/')[1].split('.ts')[0]} endpoint`); + otherMessage(`Loaded ${basename(itemPath).split(".ts")[0]} endpoint`); } } return { loaded, skipped }; } catch (error: any) { errorMessage(`Error loading endpoints: ${error}`); } -}; \ No newline at end of file +}; diff --git a/tsconfig.json b/tsconfig.json index e87e4a6..618ea2e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "strict": true, - "target": "es2016", + "target": "ES2021", "outDir": "./dist", "module": "CommonJS", "skipLibCheck": true,