feat: 在服務端重新編譯前端

This commit is contained in:
CrescentLeaf
2025-09-07 18:21:49 +08:00
parent 1a69b521e6
commit 71b368a5ac
2 changed files with 22 additions and 10 deletions

View File

@@ -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": {

View File

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