mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: hot reload for ui modules
This commit is contained in:
1 parent
26364a717c
commit
d9a28d9152
5 files changed
+43
-34
No files matched your search
@@ -21,7 +21,6 @@ if (!global.Hydro) {
|
||||
lib: {},
|
||||
// @ts-ignore
|
||||
ui: {
|
||||
manifest: {},
|
||||
template: {},
|
||||
},
|
||||
// @ts-ignore
|
||||
|
||||
@@ -705,7 +705,6 @@ export interface Lib extends Record<string, any> {
|
||||
|
||||
export type UIInjectableFields = 'ProblemAdd' | 'Nav' | 'UserDropdown';
|
||||
export interface UI {
|
||||
manifest: Dictionary<string>,
|
||||
template: Dictionary<string>,
|
||||
nodes: Record<UIInjectableFields, any[]>,
|
||||
getNodes: typeof import('./lib/ui').getNodes,
|
||||
|
||||
@@ -32,18 +32,6 @@ export function addon(addonPath: string, prepend = false) {
|
||||
const name = payload.name.startsWith('@hydrooj/') ? payload.name.split('@hydrooj/')[1] : payload.name;
|
||||
global.Hydro.version[name] = payload.version;
|
||||
const modulePath = path.dirname(packagejson);
|
||||
const publicPath = path.resolve(modulePath, 'public');
|
||||
if (fs.existsSync(publicPath)) {
|
||||
global.publicDirs[prepend ? 'push' : 'unshift'](publicPath);
|
||||
const targets = fs.readdirSync(publicPath);
|
||||
for (const target of targets) {
|
||||
if (global.Hydro.ui.manifest[target] && !prepend) {
|
||||
global.Hydro.ui.manifest[target] = publicPath;
|
||||
} else if (!global.Hydro.ui.manifest[target]) {
|
||||
global.Hydro.ui.manifest[target] = publicPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
global.addons[prepend ? 'unshift' : 'push'](modulePath);
|
||||
} catch (e) {
|
||||
logger.error(`Addon not found: ${addonPath}`);
|
||||
|
||||
@@ -59,14 +59,21 @@ class Watcher {
|
||||
|
||||
this.watcher.on('change', (path) => {
|
||||
logger.debug('change detected:', relative(this.root, path));
|
||||
bus.emit('app/watch/change', path);
|
||||
|
||||
if (this.externals.has(path)) {
|
||||
logger.warn('Require full reload');
|
||||
} else if (require.cache[path]) {
|
||||
this.stashed.add(path);
|
||||
bus.emit('app/before-reload', this.stashed);
|
||||
triggerLocalReload();
|
||||
bus.emit('app/reload', this.stashed);
|
||||
}
|
||||
});
|
||||
this.watcher.on('unlink', (path) => {
|
||||
logger.debug('change detected: ', `-${relative(this.root, path)}`);
|
||||
bus.emit('app/watch/unlink', path);
|
||||
});
|
||||
}
|
||||
|
||||
stop() {
|
||||
@@ -133,7 +140,6 @@ class Watcher {
|
||||
private triggerLocalReload() {
|
||||
const start = Date.now();
|
||||
this.analyzeChanges();
|
||||
console.log(this.accepted);
|
||||
|
||||
/** plugins pending classification */
|
||||
const pending = new Map<string, Runtime>();
|
||||
|
||||
Reference in new issue
Block a user