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() + } })