From 71b368a5ac4722cfa6a534be033cc937069aedee Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sun, 7 Sep 2025 18:21:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E6=9C=8D=E5=8B=99=E7=AB=AF?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=B7=A8=E8=AD=AF=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deno.jsonc | 4 ++-- server/main.ts | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/deno.jsonc b/deno.jsonc index 7de7103..5cb052a 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -1,7 +1,7 @@ { "tasks": { - "server": "deno task build && deno run --allow-read --allow-write --allow-env --allow-net --allow-sys ./server/main.ts", - "debug": "deno task build && deno run --watch --allow-read --allow-write --allow-env --allow-net --allow-sys ./server/main.ts", + "server": "deno task build && deno run --allow-read --allow-write --allow-env --allow-net --allow-sys --allow-run=deno ./server/main.ts", + "debug": "deno task build && deno run --watch --allow-read --allow-write --allow-env --allow-net --allow-sys --allow-run=deno ./server/main.ts", "build": "cd ./client && deno task build" }, "imports": { diff --git a/server/main.ts b/server/main.ts index 3016ea8..2246491 100644 --- a/server/main.ts +++ b/server/main.ts @@ -9,6 +9,7 @@ import https from 'node:https' import readline from 'node:readline' import process from "node:process" import chalk from "chalk" +import child_process from "node:child_process" const app = express() app.use((req, res, next) => { @@ -20,12 +21,12 @@ app.use((req, res, next) => { app.use('/', express.static(config.data_path + '/page_compiled')) const httpServer: HttpServerLike = ( - ((config.server.use == 'http') && http.createServer(app)) || - ((config.server.use == 'https') && https.createServer(config.server.https, app)) || + ((config.server.use == 'http') && http.createServer(app)) || + ((config.server.use == 'https') && https.createServer(config.server.https, app)) || http.createServer(app) ) const io = new SocketIo.Server(httpServer, { - + }) ApiManager.initServer(httpServer, io) @@ -33,13 +34,24 @@ ApiManager.initEvents() ApiManager.initAllApis() httpServer.listen(config.server.listen) -console.log(chalk.yellow("===== TheWhiteSilk Server =====")) console.log(chalk.green("API & Web 服務已經開始運作")) +function help() { + console.log(chalk.yellow("===== TheWhiteSilk Server =====")) + console.log(chalk.yellow("b - 重新編譯前端")) +} +help() const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout + input: process.stdin, + output: process.stdout }) -rl.on('line', async (text) => { - +rl.on('line', (text) => { + if (text == 'b') { + console.log(chalk.green("重新編譯...")) + child_process.spawnSync("deno", ["task", "build"], { + stdio: [process.stdin, process.stdout, process.stderr] + }) + console.log(chalk.green("✓ 編譯完畢")) + help() + } })