mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
feat: add absPath into commandPlugins!
This commit is contained in:
@@ -28,17 +28,20 @@ export function onReady(wrapper: Wrapper) {
|
||||
});
|
||||
}),
|
||||
map(({ mod, absPath }) => {
|
||||
return <DefinedCommandModule>{
|
||||
name: mod?.name ?? Files.fmtFileName(basename(absPath)),
|
||||
description: mod?.description ?? '...',
|
||||
...mod,
|
||||
return {
|
||||
absPath,
|
||||
mod: <DefinedCommandModule>{
|
||||
name: mod?.name ?? Files.fmtFileName(basename(absPath)),
|
||||
description: mod?.description ?? '...',
|
||||
...mod,
|
||||
},
|
||||
};
|
||||
}),
|
||||
);
|
||||
const processPlugins$ = processCommandFiles$.pipe(
|
||||
concatMap(mod => {
|
||||
const cmdPluginRes = processCommandPlugins(wrapper, mod);
|
||||
return of({ mod, cmdPluginRes });
|
||||
concatMap(payload => {
|
||||
const cmdPluginRes = processCommandPlugins(wrapper, payload);
|
||||
return of({ mod: payload.mod, cmdPluginRes });
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -13,14 +13,17 @@ import { errTap } from './observableHandling';
|
||||
/**
|
||||
* Utility function to process command plugins for all Modules
|
||||
* @param wrapper
|
||||
* @param mod
|
||||
* @param payload
|
||||
*/
|
||||
export function processCommandPlugins<T extends DefinedCommandModule>(wrapper: Wrapper, mod: T) {
|
||||
return mod.plugins.map(plug => ({
|
||||
export function processCommandPlugins<T extends DefinedCommandModule>(
|
||||
wrapper: Wrapper,
|
||||
payload: { mod: T; absPath: string },
|
||||
) {
|
||||
return payload.mod.plugins.map(plug => ({
|
||||
...plug,
|
||||
name: plug?.name ?? 'Unnamed Plugin',
|
||||
description: plug?.description ?? '...',
|
||||
execute: plug.execute(wrapper, mod, controller),
|
||||
execute: plug.execute(wrapper, payload, controller),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,10 @@ export type CommandPlugin<T extends keyof CommandModuleDefs = keyof CommandModul
|
||||
type: PluginType.Command;
|
||||
execute: (
|
||||
wrapper: Wrapper,
|
||||
module: DefinitelyDefined<CommandModuleDefs[T], 'name' | 'description'>,
|
||||
payload: {
|
||||
mod: DefinitelyDefined<CommandModuleDefs[T], 'name' | 'description'>;
|
||||
absPath: string;
|
||||
},
|
||||
controller: Controller,
|
||||
) => Awaitable<Result<void, void>>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user