mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
ui-next: refactor addon ui patch resolving
This commit is contained in:
2 files changed
+10
-6
No files matched your search
@@ -622,7 +622,7 @@ export interface ProblemSearchOptions {
|
|||||||
|
|
||||||
export type ProblemSearch = (domainId: string, q: string, options?: ProblemSearchOptions) => Promise<ProblemSearchResponse>;
|
export type ProblemSearch = (domainId: string, q: string, options?: ProblemSearchOptions) => Promise<ProblemSearchResponse>;
|
||||||
|
|
||||||
export type UIInjectableFields = 'ProblemAdd' | 'Notification' | 'Nav' | 'UserDropdown' | 'DomainManage' | 'ControlPanel' | 'Route';
|
export type UIInjectableFields = 'ProblemAdd' | 'Notification' | 'Nav' | 'UserDropdown' | 'DomainManage' | 'ControlPanel';
|
||||||
export interface UI {
|
export interface UI {
|
||||||
nodes: Record<UIInjectableFields, any[]>;
|
nodes: Record<UIInjectableFields, any[]>;
|
||||||
getNodes: typeof import('./lib/ui').getNodes;
|
getNodes: typeof import('./lib/ui').getNodes;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import react from '@vitejs/plugin-react';
|
|||||||
import c2k from 'koa2-connect/ts';
|
import c2k from 'koa2-connect/ts';
|
||||||
import { createServer, type Plugin } from 'vite';
|
import { createServer, type Plugin } from 'vite';
|
||||||
import { serializer } from '@hydrooj/framework';
|
import { serializer } from '@hydrooj/framework';
|
||||||
import { Context, getNodes } from 'hydrooj';
|
import { Context } from 'hydrooj';
|
||||||
|
|
||||||
const INJECT_MARKER = '<!-- __HYDRO_INJECTION__DO_NOT_REMOVE_THIS__ -->';
|
const INJECT_MARKER = '<!-- __HYDRO_INJECTION__DO_NOT_REMOVE_THIS__ -->';
|
||||||
const buildInject = (str: string) => `<script id="__HYDRO_INJECTION__" type="application/json">${str}</script>`;
|
const buildInject = (str: string) => `<script id="__HYDRO_INJECTION__" type="application/json">${str}</script>`;
|
||||||
@@ -23,10 +23,14 @@ function hydroPlugins(): Plugin {
|
|||||||
},
|
},
|
||||||
load(id) {
|
load(id) {
|
||||||
if (id === resolvedVirtualModuleId) {
|
if (id === resolvedVirtualModuleId) {
|
||||||
const plugins = getNodes('Route');
|
const entries: string[] = [];
|
||||||
if (!plugins) return 'export default [];';
|
for (const addon of Object.values(global.addons)) {
|
||||||
const imports = plugins.map((p, i) => `import plugin${i} from '${p.args.entry}';`).join('\n');
|
const uiEntry = path.resolve(addon, 'ui', 'index.ts');
|
||||||
const exports = `export default [${plugins.map((p, i) => `plugin${i}`).join(', ')}];`;
|
if (fs.existsSync(uiEntry)) entries.push(uiEntry);
|
||||||
|
}
|
||||||
|
if (!entries.length) return 'export default [];';
|
||||||
|
const imports = entries.map((e, i) => `import plugin${i} from '${e}';`).join('\n');
|
||||||
|
const exports = `export default [${entries.map((_, i) => `plugin${i}`).join(', ')}];`;
|
||||||
return `${imports}\n${exports}`;
|
return `${imports}\n${exports}`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user