From 71f092612d229ac2ad6e48058e4960b03459c48c Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Tue, 24 Sep 2024 11:58:42 -0500 Subject: [PATCH] make source maps --- gulpfile.cjs | 8 ++++++-- package.json | 5 +++-- src/index.ts | 31 ++++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/gulpfile.cjs b/gulpfile.cjs index 28e3a4f..af74040 100644 --- a/gulpfile.cjs +++ b/gulpfile.cjs @@ -5,7 +5,7 @@ const tsProject = ts.createProject("tsconfig.json"); const argv = require("yargs").argv; const rimraf = require("rimraf"); const plumber = require("gulp-plumber"); - +const sourcemaps = require('gulp-sourcemaps'); const swcOptions = { jsc: { parser: { @@ -31,7 +31,7 @@ const swcOptions = { lazy: false, noInterop: false, }, - sourceMaps: "inline", + sourceMaps: true, minify: false, }; @@ -45,15 +45,19 @@ gulp.task("scripts", () => { if (argv.swc) { return gulp .src("src/**/*.ts") + .pipe(sourcemaps.init()) .pipe(plumber()) // Prevent pipe breaking caused by errors .pipe(swc(swcOptions)) + .pipe(sourcemaps.write('.')) .pipe(gulp.dest("dist")); } else { console.warn("[WARN] Using TSC compiler, will be slower than SWC"); return gulp .src("src/**/*.ts") + .pipe(sourcemaps.init()) .pipe(plumber()) // Prevent pipe breaking caused by errors .pipe(tsProject()) + .pipe(sourcemaps.write('.')) .pipe(gulp.dest("dist")); } }); diff --git a/package.json b/package.json index cead41f..f4f57f8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jankclient", "version": "0.1.0", - "description": "A SpaceBar Client written in JS HTML and CSS to run, clone the repo and do either `node index.js` or `bun index.js` both bun and node are supported, and both should function as expected, if there are any problems with Jank Client on things that aren't linux, please let me know. To access Jank Client after init simply go to http://localhost:8080/login and login with your username and password.", + "description": "A SpaceBar Client written in TS HTML and CSS to run, clone the repo and do either `npm start` or `bun start` both bun and node are supported, and both should function as expected. To access Jank Client after init simply go to http://localhost:8080/login and login with your username and password.", "main": ".dist/index.js", "type": "module", "scripts": { @@ -23,7 +23,8 @@ "gulp-swc": "^2.2.0", "node-fetch": "^3.3.2", "rimraf": "^6.0.1", - "ts-to-jsdoc": "^2.2.0" + "ts-to-jsdoc": "^2.2.0", + "gulp-sourcemaps":"^3.0.0" }, "devDependencies": { "@eslint/js": "^9.10.0", diff --git a/src/index.ts b/src/index.ts index 66323b9..0957899 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ import path from"node:path"; import{ observe, uptime }from"./stats.js"; import{ getApiUrls, inviteResponse }from"./utils.js"; import{ fileURLToPath }from"node:url"; - +const devmode = (process.env.NODE_ENV || 'development')==='development'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -34,9 +34,7 @@ async function updateInstances(): Promise{ ); const json = (await response.json()) as Instance[]; for(const instance of json){ - if(!instanceNames.has(instance.name)){ - instances.push(instance as any); - }else{ + if(instanceNames.has(instance.name)){ const existingInstance = instanceNames.get(instance.name); if(existingInstance){ for(const key of Object.keys(instance)){ @@ -45,6 +43,8 @@ async function updateInstances(): Promise{ } } } + }else{ + instances.push(instance as any); } } observe(instances); @@ -53,7 +53,7 @@ async function updateInstances(): Promise{ } } -updateInstances(); +//updateInstances(); app.use("/getupdates", (_req: Request, res: Response)=>{ try{ @@ -104,10 +104,31 @@ app.use("/", async (req: Request, res: Response)=>{ const filePath = path.join(__dirname, "webpage", req.path); if(fs.existsSync(filePath)){ + if(devmode){ + const filePath2 = path.join(__dirname, "../src/webpage", req.path); + if(fs.existsSync(filePath2)){ + res.sendFile(filePath2); + return; + } + } res.sendFile(filePath); }else if(fs.existsSync(`${filePath}.html`)){ + if(devmode){ + const filePath2 = path.join(__dirname, "../src/webpage", req.path); + if(fs.existsSync(filePath2+".html")){ + res.sendFile(filePath2+".html"); + return; + } + } res.sendFile(`${filePath}.html`); }else{ + if(req.path.startsWith("/src/webpage")){ + const filePath2 = path.join(__dirname, "..", req.path); + if(fs.existsSync(`${filePath2}`)){ + res.sendFile(filePath2); + return; + } + } res.sendFile(path.join(__dirname, "webpage", "index.html")); } });