chore: use build & start process for development as well #2222

Merged
Sainan merged 5 commits from dev-redux into main 2025-06-20 18:30:53 -07:00
6 changed files with 46 additions and 13 deletions
Showing only changes of commit fa8a55935b - Show all commits

View File

@ -6,6 +6,7 @@
"scripts": {
"start": "node --enable-source-maps --import ./build/src/pathman.js build/src/index.js",
"build": "tsc --incremental --sourceMap && ncp static/webui build/static/webui",
"build:dev": "tsc --incremental --sourceMap",
"build-and-start": "npm run build && npm run start",
"dev": "node scripts/dev.js",
"verify": "tsgo --noEmit",

View File

@ -3,7 +3,15 @@ const { spawn } = require("child_process");
const chokidar = require("chokidar");
const kill = require("tree-kill");
let secret = "";
for (let i = 0; i != 10; ++i) {
secret += String.fromCharCode(Math.floor(Math.random() * 26) + 0x41);
}
const args = [...process.argv].splice(2);
args.push("--dev");
args.push("--secret");
args.push(secret);
let buildproc, runproc;
function run(changedFile) {
@ -20,11 +28,11 @@ function run(changedFile) {
runproc = undefined;
}
buildproc = spawn("npm", ["run", "build"], { stdio: "inherit", shell: true });
buildproc = spawn("npm", ["run", "build:dev"], { stdio: "inherit", shell: true });
buildproc.on("exit", code => {
buildproc = undefined;
if (code === 0) {
runproc = spawn("npm", ["run", "start", "--", "--dev", ...args], { stdio: "inherit", shell: true });
runproc = spawn("npm", ["run", "start", "--", ...args], { stdio: "inherit", shell: true });
runproc.on("exit", () => {
runproc = undefined;
});
@ -35,4 +43,7 @@ function run(changedFile) {
run();
chokidar.watch("src").on("change", run);
chokidar.watch("static/fixed_responses").on("change", run);
chokidar.watch("static/webui").on("change", run);
chokidar.watch("static/webui").on("change", () => {
fetch("http://localhost/custom/webuiFileChangeDetected?secret=" + secret);
});

View File

@ -0,0 +1,11 @@
import { args } from "@/src/helpers/commandLineArguments";
import { config } from "@/src/services/configService";
import { sendWsBroadcast } from "@/src/services/webService";
import { RequestHandler } from "express";
export const webuiFileChangeDetectedController: RequestHandler = (req, res) => {
if (args.dev && args.secret && req.query.secret == args.secret) {
sendWsBroadcast({ ports: { http: config.httpPort, https: config.httpsPort } });
}
res.end();
};

View File

@ -1,6 +1,7 @@
interface IArguments {
configPath?: string;
dev?: boolean;
secret?: string;
}
export const args: IArguments = {};
@ -14,5 +15,9 @@ for (let i = 2; i < process.argv.length; ) {
case "--dev":
args.dev = true;
break;
case "--secret":
args.secret = process.argv[i++];
break;
}
}

View File

@ -11,6 +11,7 @@ import { renameAccountController } from "@/src/controllers/custom/renameAccountC
import { ircDroppedController } from "@/src/controllers/custom/ircDroppedController";
import { unlockAllIntrinsicsController } from "@/src/controllers/custom/unlockAllIntrinsicsController";
import { addMissingMaxRankModsController } from "@/src/controllers/custom/addMissingMaxRankModsController";
import { webuiFileChangeDetectedController } from "@/src/controllers/custom/webuiFileChangeDetectedController";
import { createAccountController } from "@/src/controllers/custom/createAccountController";
import { createMessageController } from "@/src/controllers/custom/createMessageController";
@ -20,10 +21,10 @@ import { addXpController } from "@/src/controllers/custom/addXpController";
import { importController } from "@/src/controllers/custom/importController";
import { manageQuestsController } from "@/src/controllers/custom/manageQuestsController";
import { setEvolutionProgressController } from "@/src/controllers/custom/setEvolutionProgressController";
import { setBoosterController } from "@/src/controllers/custom/setBoosterController";
import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
import { updateConfigDataController } from "@/src/controllers/custom/updateConfigDataController";
import { setBoosterController } from "../controllers/custom/setBoosterController";
const customRouter = express.Router();
@ -38,6 +39,7 @@ customRouter.get("/renameAccount", renameAccountController);
customRouter.get("/ircDropped", ircDroppedController);
customRouter.get("/unlockAllIntrinsics", unlockAllIntrinsicsController);
customRouter.get("/addMissingMaxRankMods", addMissingMaxRankModsController);
customRouter.get("/webuiFileChangeDetected", webuiFileChangeDetectedController);
customRouter.post("/createAccount", createAccountController);
customRouter.post("/createMessage", createMessageController);

View File

@ -1,6 +1,9 @@
import express from "express";
import path from "path";
import { repoDir, rootDir } from "@/src/helpers/pathHelper";
import { args } from "@/src/helpers/commandLineArguments";
const baseDir = args.dev ? repoDir : rootDir;
const webuiRouter = express.Router();
@ -19,29 +22,29 @@ webuiRouter.use("/webui", (req, res, next) => {
// Serve virtual routes
webuiRouter.get("/webui/inventory", (_req, res) => {
res.sendFile(path.join(rootDir, "static/webui/index.html"));
res.sendFile(path.join(baseDir, "static/webui/index.html"));
});
webuiRouter.get(/webui\/powersuit\/(.+)/, (_req, res) => {
res.sendFile(path.join(rootDir, "static/webui/index.html"));
res.sendFile(path.join(baseDir, "static/webui/index.html"));
});
webuiRouter.get("/webui/mods", (_req, res) => {
res.sendFile(path.join(rootDir, "static/webui/index.html"));
res.sendFile(path.join(baseDir, "static/webui/index.html"));
});
webuiRouter.get("/webui/settings", (_req, res) => {
res.sendFile(path.join(rootDir, "static/webui/index.html"));
res.sendFile(path.join(baseDir, "static/webui/index.html"));
});
webuiRouter.get("/webui/quests", (_req, res) => {
res.sendFile(path.join(rootDir, "static/webui/index.html"));
res.sendFile(path.join(baseDir, "static/webui/index.html"));
});
webuiRouter.get("/webui/cheats", (_req, res) => {
res.sendFile(path.join(rootDir, "static/webui/index.html"));
res.sendFile(path.join(baseDir, "static/webui/index.html"));
});
webuiRouter.get("/webui/import", (_req, res) => {
res.sendFile(path.join(rootDir, "static/webui/index.html"));
res.sendFile(path.join(baseDir, "static/webui/index.html"));
});
// Serve static files
webuiRouter.use("/webui", express.static(path.join(rootDir, "static/webui")));
webuiRouter.use("/webui", express.static(path.join(baseDir, "static/webui")));
// Serve favicon
webuiRouter.get("/favicon.ico", (_req, res) => {
@ -58,7 +61,7 @@ webuiRouter.get("/webui/riven-tool/RivenParser.js", (_req, res) => {
// Serve translations
webuiRouter.get("/translations/:file", (req, res) => {
res.sendFile(path.join(rootDir, `static/webui/translations/${req.params.file}`));
res.sendFile(path.join(baseDir, `static/webui/translations/${req.params.file}`));
});
export { webuiRouter };