feat(加入热更和eval的管理模块):

This commit is contained in:
liangtongchuan
2023-04-30 23:54:48 +08:00
committed by luying
parent a362a397b5
commit 3a41136722
4 changed files with 176 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { Application, IComponent, manualReloadCrons, manualReloadHandlers, manualReloadRemoters } from "pinus";
export class UpdateComponent implements IComponent {
name = "UpdateComponent";
app: Application;
constructor(app: Application) {
this.app = app;
this.app.set(this.name, this);
}
start(cb: () => void) {
console.log("UpdateComponent start", this.app.getServerId());
cb();
}
stop(force: boolean, cb: () => void) {
console.log("UpdateComponent stop", force, this.app.getServerId());
cb();
}
hotupdate(files: string, cb: (err, res?) => void) {
try {
const filelist = files.split(",");
for (let i = 0; i < filelist.length; i++) {
const file = this.app.getBase() + filelist[i];
if (!file || !require.cache[file]) {
console.log("UpdateComponent hotupdate", this.app.getServerId(), "file not exist", file);
cb("file not exist");
return;
}
}
for (let i = 0; i < filelist.length; i++) {
const file = this.app.getBase() + filelist[i];
delete require.cache[file];
console.log("UpdateComponent hotupdate", this.app.getServerId(), file)
}
manualReloadHandlers(this.app);
manualReloadRemoters(this.app);
manualReloadCrons(this.app);
cb(null, "success");
} catch (error) {
console.log("UpdateComponent hotupdate", this.app.getServerId(), error)
cb(error);
return;
}
}
}