Skip to content

Commit

Permalink
feat: subscribe existing hooks to matching events
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 19, 2022
1 parent ec021f2 commit 4e85ebe
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/sfCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,24 @@ export abstract class SfCommand<T> extends Command {
this.lifecycle.onWarning(async (warning: string) => {
this.warn(warning);
});
const options = {
Command: this.ctor,
argv: this.argv,
commandId: this.id,
};
// what hooks are there in the plugins? Subscribe to matching lifecycle events
this.config.plugins
// omit oclif and telemetry (which subscribes itself to events already)
.filter((plugin) => !plugin.name.startsWith('@oclif/') && plugin.name !== '@salesforce/plugin-telemetry')
.flatMap((p) => Object.entries(p.hooks))
.map(([eventName, hooksForEvent]) => {
hooksForEvent.map(() => {
this.lifecycle.on(eventName, async (result: AnyJson) => {
await this.config.runHook(eventName, Object.assign(options, { result }));
});
});
});

return super._run<R>();
}

Expand Down

0 comments on commit 4e85ebe

Please sign in to comment.