mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: loader.reloadPlugin: remove first arg
This commit is contained in:
5 files changed
+13
-8
No files matched your search
@@ -123,10 +123,15 @@ export async function load(ctx: Context) {
|
|||||||
await model(pending, fail, ctx);
|
await model(pending, fail, ctx);
|
||||||
await setting(pending, fail, require('../model/setting'));
|
await setting(pending, fail, require('../model/setting'));
|
||||||
ctx.plugin(require('../service/server'));
|
ctx.plugin(require('../service/server'));
|
||||||
|
ctx = await new Promise((resolve) => {
|
||||||
|
ctx.inject(['server'], (c) => {
|
||||||
|
resolve(c);
|
||||||
|
});
|
||||||
|
});
|
||||||
await addon(pending, fail, ctx);
|
await addon(pending, fail, ctx);
|
||||||
const scriptDir = path.resolve(__dirname, '..', 'script');
|
const scriptDir = path.resolve(__dirname, '..', 'script');
|
||||||
for (const h of await fs.readdir(scriptDir)) {
|
for (const h of await fs.readdir(scriptDir)) {
|
||||||
ctx.loader.reloadPlugin(ctx, path.resolve(scriptDir, h), {}, `hydrooj/script/${h.split('.')[0]}`);
|
ctx.loader.reloadPlugin(path.resolve(scriptDir, h), {}, `hydrooj/script/${h.split('.')[0]}`);
|
||||||
}
|
}
|
||||||
await script(pending, fail, ctx);
|
await script(pending, fail, ctx);
|
||||||
await cli();
|
await cli();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ const getLoader = (type: LoadTask, filename: string, dontLoad = false) => async
|
|||||||
try {
|
try {
|
||||||
if (dontLoad) throw new Error(`deprecated ${name} in %s will not be load: ${i}`);
|
if (dontLoad) throw new Error(`deprecated ${name} in %s will not be load: ${i}`);
|
||||||
const m = unwrapExports(require(p));
|
const m = unwrapExports(require(p));
|
||||||
if (m.apply) ctx.loader.reloadPlugin(ctx, p, {});
|
if (m.apply) ctx.loader.reloadPlugin(p, {});
|
||||||
else logger.info(`${name} init: %s`, i);
|
else logger.info(`${name} init: %s`, i);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
fail.push(i);
|
fail.push(i);
|
||||||
@@ -69,7 +69,7 @@ export async function builtinModel(ctx: Context) {
|
|||||||
const models = await fs.readdir(modelDir);
|
const models = await fs.readdir(modelDir);
|
||||||
for (const t of models.filter((i) => i.endsWith('.ts'))) {
|
for (const t of models.filter((i) => i.endsWith('.ts'))) {
|
||||||
const q = path.resolve(modelDir, t);
|
const q = path.resolve(modelDir, t);
|
||||||
if ('apply' in require(q)) ctx.loader.reloadPlugin(ctx, q, {}, `hydrooj/model/${t.split('.')[0]}`);
|
if ('apply' in require(q)) ctx.loader.reloadPlugin(q, {}, `hydrooj/model/${t.split('.')[0]}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,14 +61,14 @@ export async function apply(ctx: Context) {
|
|||||||
const handlerDir = path.resolve(__dirname, '..', 'handler');
|
const handlerDir = path.resolve(__dirname, '..', 'handler');
|
||||||
const handlers = await fs.readdir(handlerDir);
|
const handlers = await fs.readdir(handlerDir);
|
||||||
for (const h of handlers.filter((i) => i.endsWith('.ts'))) {
|
for (const h of handlers.filter((i) => i.endsWith('.ts'))) {
|
||||||
ctx.loader.reloadPlugin(ctx, path.resolve(handlerDir, h), {}, `hydrooj/handler/${h.split('.')[0]}`);
|
ctx.loader.reloadPlugin(path.resolve(handlerDir, h), {}, `hydrooj/handler/${h.split('.')[0]}`);
|
||||||
}
|
}
|
||||||
ctx.plugin(require('../service/migration').default);
|
ctx.plugin(require('../service/migration').default);
|
||||||
await handler(pending, fail, ctx);
|
await handler(pending, fail, ctx);
|
||||||
await addon(pending, fail, ctx);
|
await addon(pending, fail, ctx);
|
||||||
const scriptDir = path.resolve(__dirname, '..', 'script');
|
const scriptDir = path.resolve(__dirname, '..', 'script');
|
||||||
for (const h of await fs.readdir(scriptDir)) {
|
for (const h of await fs.readdir(scriptDir)) {
|
||||||
ctx.loader.reloadPlugin(ctx, path.resolve(scriptDir, h), {}, `hydrooj/script/${h.split('.')[0]}`);
|
ctx.loader.reloadPlugin(path.resolve(scriptDir, h), {}, `hydrooj/script/${h.split('.')[0]}`);
|
||||||
}
|
}
|
||||||
await script(pending, fail, ctx);
|
await script(pending, fail, ctx);
|
||||||
await ctx.parallel('app/started');
|
await ctx.parallel('app/started');
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export class Loader extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async reloadPlugin(parent: Context, key: string, config: any, asName = '') {
|
async reloadPlugin(key: string, config: any, asName = '') {
|
||||||
let fork = this.state[key];
|
let fork = this.state[key];
|
||||||
if (fork) {
|
if (fork) {
|
||||||
logger.info('reload plugin %c', key.split('node_modules').pop());
|
logger.info('reload plugin %c', key.split('node_modules').pop());
|
||||||
@@ -115,7 +115,7 @@ export class Loader extends Service {
|
|||||||
resolveConfig(plugin, config);
|
resolveConfig(plugin, config);
|
||||||
if (asName) plugin.name = asName;
|
if (asName) plugin.name = asName;
|
||||||
// fork = parent.plugin(plugin, this.interpolate(config));
|
// fork = parent.plugin(plugin, this.interpolate(config));
|
||||||
fork = parent.plugin(plugin, config);
|
fork = this.ctx.plugin(plugin, config);
|
||||||
if (!fork) return;
|
if (!fork) return;
|
||||||
this.state[key] = fork;
|
this.state[key] = fork;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ export type StringKeys<O> = {
|
|||||||
}[keyof O];
|
}[keyof O];
|
||||||
const fSortR = /[^\d]+|\d+/g;
|
const fSortR = /[^\d]+|\d+/g;
|
||||||
export function sortFiles(files: string[]): string[];
|
export function sortFiles(files: string[]): string[];
|
||||||
export function sortFiles(files: { _id: string }[], key?: '_id'): { _id: string }[];
|
export function sortFiles<T extends { _id: string }>(files: T[], key?: '_id'): T[];
|
||||||
export function sortFiles<T extends Record<string, any>>(files: T[], key: StringKeys<T>): T[];
|
export function sortFiles<T extends Record<string, any>>(files: T[], key: StringKeys<T>): T[];
|
||||||
export function sortFiles(files: Record<string, any>[] | string[], key = '_id') {
|
export function sortFiles(files: Record<string, any>[] | string[], key = '_id') {
|
||||||
if (!files?.length) return [];
|
if (!files?.length) return [];
|
||||||
|
|||||||
Reference in new issue
Block a user