chore: use build & start process for development as well #2222
@ -6,6 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node --enable-source-maps --import ./build/src/pathman.js build/src/index.js",
|
"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": "tsc --incremental --sourceMap && ncp static/webui build/static/webui",
|
||||||
|
"build:dev": "tsc --incremental --sourceMap",
|
||||||
"build-and-start": "npm run build && npm run start",
|
"build-and-start": "npm run build && npm run start",
|
||||||
"dev": "node scripts/dev.js",
|
"dev": "node scripts/dev.js",
|
||||||
"verify": "tsgo --noEmit",
|
"verify": "tsgo --noEmit",
|
||||||
|
@ -3,7 +3,15 @@ const { spawn } = require("child_process");
|
|||||||
const chokidar = require("chokidar");
|
const chokidar = require("chokidar");
|
||||||
const kill = require("tree-kill");
|
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);
|
const args = [...process.argv].splice(2);
|
||||||
|
args.push("--dev");
|
||||||
|
args.push("--secret");
|
||||||
|
args.push(secret);
|
||||||
|
|
||||||
let buildproc, runproc;
|
let buildproc, runproc;
|
||||||
function run(changedFile) {
|
function run(changedFile) {
|
||||||
@ -20,11 +28,11 @@ function run(changedFile) {
|
|||||||
runproc = undefined;
|
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.on("exit", code => {
|
||||||
buildproc = undefined;
|
buildproc = undefined;
|
||||||
if (code === 0) {
|
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.on("exit", () => {
|
||||||
runproc = undefined;
|
runproc = undefined;
|
||||||
});
|
});
|
||||||
@ -35,4 +43,7 @@ function run(changedFile) {
|
|||||||
run();
|
run();
|
||||||
chokidar.watch("src").on("change", run);
|
chokidar.watch("src").on("change", run);
|
||||||
chokidar.watch("static/fixed_responses").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);
|
||||||
|
});
|
||||||
|
11
src/controllers/custom/webuiFileChangeDetectedController.ts
Normal file
11
src/controllers/custom/webuiFileChangeDetectedController.ts
Normal 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();
|
||||||
|
};
|
@ -1,6 +1,7 @@
|
|||||||
interface IArguments {
|
interface IArguments {
|
||||||
configPath?: string;
|
configPath?: string;
|
||||||
dev?: boolean;
|
dev?: boolean;
|
||||||
|
secret?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const args: IArguments = {};
|
export const args: IArguments = {};
|
||||||
@ -14,5 +15,9 @@ for (let i = 2; i < process.argv.length; ) {
|
|||||||
case "--dev":
|
case "--dev":
|
||||||
args.dev = true;
|
args.dev = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "--secret":
|
||||||
|
args.secret = process.argv[i++];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import { renameAccountController } from "@/src/controllers/custom/renameAccountC
|
|||||||
import { ircDroppedController } from "@/src/controllers/custom/ircDroppedController";
|
import { ircDroppedController } from "@/src/controllers/custom/ircDroppedController";
|
||||||
import { unlockAllIntrinsicsController } from "@/src/controllers/custom/unlockAllIntrinsicsController";
|
import { unlockAllIntrinsicsController } from "@/src/controllers/custom/unlockAllIntrinsicsController";
|
||||||
import { addMissingMaxRankModsController } from "@/src/controllers/custom/addMissingMaxRankModsController";
|
import { addMissingMaxRankModsController } from "@/src/controllers/custom/addMissingMaxRankModsController";
|
||||||
|
import { webuiFileChangeDetectedController } from "@/src/controllers/custom/webuiFileChangeDetectedController";
|
||||||
|
|
||||||
import { createAccountController } from "@/src/controllers/custom/createAccountController";
|
import { createAccountController } from "@/src/controllers/custom/createAccountController";
|
||||||
import { createMessageController } from "@/src/controllers/custom/createMessageController";
|
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 { importController } from "@/src/controllers/custom/importController";
|
||||||
import { manageQuestsController } from "@/src/controllers/custom/manageQuestsController";
|
import { manageQuestsController } from "@/src/controllers/custom/manageQuestsController";
|
||||||
import { setEvolutionProgressController } from "@/src/controllers/custom/setEvolutionProgressController";
|
import { setEvolutionProgressController } from "@/src/controllers/custom/setEvolutionProgressController";
|
||||||
|
import { setBoosterController } from "@/src/controllers/custom/setBoosterController";
|
||||||
|
|
||||||
import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
|
import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
|
||||||
import { updateConfigDataController } from "@/src/controllers/custom/updateConfigDataController";
|
import { updateConfigDataController } from "@/src/controllers/custom/updateConfigDataController";
|
||||||
import { setBoosterController } from "../controllers/custom/setBoosterController";
|
|
||||||
|
|
||||||
const customRouter = express.Router();
|
const customRouter = express.Router();
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ customRouter.get("/renameAccount", renameAccountController);
|
|||||||
customRouter.get("/ircDropped", ircDroppedController);
|
customRouter.get("/ircDropped", ircDroppedController);
|
||||||
customRouter.get("/unlockAllIntrinsics", unlockAllIntrinsicsController);
|
customRouter.get("/unlockAllIntrinsics", unlockAllIntrinsicsController);
|
||||||
customRouter.get("/addMissingMaxRankMods", addMissingMaxRankModsController);
|
customRouter.get("/addMissingMaxRankMods", addMissingMaxRankModsController);
|
||||||
|
customRouter.get("/webuiFileChangeDetected", webuiFileChangeDetectedController);
|
||||||
|
|
||||||
customRouter.post("/createAccount", createAccountController);
|
customRouter.post("/createAccount", createAccountController);
|
||||||
customRouter.post("/createMessage", createMessageController);
|
customRouter.post("/createMessage", createMessageController);
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { repoDir, rootDir } from "@/src/helpers/pathHelper";
|
import { repoDir, rootDir } from "@/src/helpers/pathHelper";
|
||||||
|
import { args } from "@/src/helpers/commandLineArguments";
|
||||||
|
|
||||||
|
const baseDir = args.dev ? repoDir : rootDir;
|
||||||
|
|
||||||
const webuiRouter = express.Router();
|
const webuiRouter = express.Router();
|
||||||
|
|
||||||
@ -19,29 +22,29 @@ webuiRouter.use("/webui", (req, res, next) => {
|
|||||||
|
|
||||||
// Serve virtual routes
|
// Serve virtual routes
|
||||||
webuiRouter.get("/webui/inventory", (_req, res) => {
|
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) => {
|
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) => {
|
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) => {
|
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) => {
|
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) => {
|
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) => {
|
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
|
// 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
|
// Serve favicon
|
||||||
webuiRouter.get("/favicon.ico", (_req, res) => {
|
webuiRouter.get("/favicon.ico", (_req, res) => {
|
||||||
@ -58,7 +61,7 @@ webuiRouter.get("/webui/riven-tool/RivenParser.js", (_req, res) => {
|
|||||||
|
|
||||||
// Serve translations
|
// Serve translations
|
||||||
webuiRouter.get("/translations/:file", (req, res) => {
|
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 };
|
export { webuiRouter };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user