feat: add absPath into commandPlugins!

This commit is contained in:
Jacob Nguyen
2022-06-27 15:54:13 -05:00
parent 4f520b2e5a
commit 84ff217d7f
3 changed files with 21 additions and 12 deletions

View File

@@ -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 });
}),
);

View File

@@ -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),
}));
}

View File

@@ -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>>;
}