mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
refactor: use bun to execute server and analytics
This commit is contained in:
1 parent
2feedc329c
commit
77577d9b8d
13 files changed
+128
-120
No files matched your search
+5
-13
@@ -3,13 +3,12 @@
|
||||
"version": "0.0.0",
|
||||
"description": "Linux Odyssey Server",
|
||||
"scripts": {
|
||||
"start": "node dist/server/src/index.js",
|
||||
"setup": "tsx src/cli/setup.ts",
|
||||
"clean": "tsx src/cli/clean.ts",
|
||||
"build": "tsc",
|
||||
"start": "bun src/index.ts",
|
||||
"setup": "bun src/cli/setup.ts",
|
||||
"clean": "bun src/cli/clean.ts",
|
||||
"type-check": "tsc --noEmit",
|
||||
"dev": "tsx watch --include \"../quests/**/*.yml\" src/index.ts",
|
||||
"build:quests": "tsx src/cli/build.ts"
|
||||
"dev": "bun scripts/dev.ts",
|
||||
"build:quests": "bun src/cli/build.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@odyssey/constants": "workspace:*",
|
||||
@@ -41,15 +40,12 @@
|
||||
"passport-local": "^1.0.0",
|
||||
"socket.io": "^4.7.1",
|
||||
"swagger-ui-express": "^5.0.0",
|
||||
"tsx": "^4.19.3",
|
||||
"validator": "^13.15.22",
|
||||
"winston": "^3.11.0",
|
||||
"yaml": "^2.8.3",
|
||||
"zod": "^3.24.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@swc/core": "^1.4.2",
|
||||
"@swc/helpers": "^0.5.6",
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/dockerode": "^3.3.23",
|
||||
"@types/express": "^4.17.21",
|
||||
@@ -63,12 +59,8 @@
|
||||
"@types/passport-jwt": "^4.0.1",
|
||||
"@types/passport-local": "^1.0.38",
|
||||
"@types/passport-oauth2": "^1.4.15",
|
||||
"@types/source-map-support": "^0",
|
||||
"@types/swagger-ui-express": "^4.1.6",
|
||||
"@types/validator": "^13.11.9",
|
||||
"concurrently": "^8.2.2",
|
||||
"regenerator-runtime": "^0.14.1",
|
||||
"source-map-support": "^0.5.21",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Dev server with auto-restart. `bun --watch` only tracks imported modules,
|
||||
// but quests are read from YAML at startup, so rewrite the entry file (same
|
||||
// contents) whenever a quest file changes to trigger a restart. Bun ignores
|
||||
// timestamp-only changes, so `touch` would not work.
|
||||
import { watch, readFileSync, writeFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
const entry = path.join(import.meta.dir, '../src/index.ts')
|
||||
const questsDir = path.join(import.meta.dir, '../../quests')
|
||||
|
||||
const server = Bun.spawn(['bun', '--watch', entry], {
|
||||
stdio: ['inherit', 'inherit', 'inherit'],
|
||||
})
|
||||
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
watch(questsDir, { recursive: true }, (_event, filename) => {
|
||||
if (!filename?.endsWith('.yml')) return
|
||||
clearTimeout(timer)
|
||||
timer = setTimeout(() => {
|
||||
writeFileSync(entry, readFileSync(entry))
|
||||
}, 100)
|
||||
})
|
||||
|
||||
const stop = () => server.kill()
|
||||
process.on('SIGINT', stop)
|
||||
process.on('SIGTERM', stop)
|
||||
process.exit(await server.exited)
|
||||
@@ -1,8 +1,6 @@
|
||||
import { Router } from 'express'
|
||||
import passport from 'passport'
|
||||
import commands from './commandRouter.js'
|
||||
import authRouter from './authRouter.js'
|
||||
import authRequired from '../../middleware/authRequired.js'
|
||||
import config from '../../config.js'
|
||||
import leaderboardController from '../controllers/leaderboardController.js'
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ function createConfig() {
|
||||
|
||||
function getProjectRoot(): string {
|
||||
// Start from the current file's directory
|
||||
let currentDir = __dirname
|
||||
let currentDir = import.meta.dir
|
||||
|
||||
// Keep going up until we find the root package.json with workspaces
|
||||
while (currentDir !== path.parse(currentDir).root) {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true,
|
||||
"outDir": "./dist"
|
||||
"module": "Preserve",
|
||||
"moduleResolution": "bundler",
|
||||
"target": "ESNext",
|
||||
"types": ["bun", "node"],
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "src/*.test.js", "dist"],
|
||||
"ts-node": {
|
||||
"swc": true
|
||||
}
|
||||
"include": ["src", "scripts", "migrations"],
|
||||
"exclude": ["node_modules", "src/*.test.js"]
|
||||
}
|
||||
Reference in new issue
Block a user