Skip to content

Commit

Permalink
Maybe fixed hook system
Browse files Browse the repository at this point in the history
  • Loading branch information
cb1kenobi committed Jan 26, 2024
1 parent f666671 commit cccda85
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class CLI {
* @access public
*/
createHook(name, ctx, fn) {
let dataPayload = {};
let dataPayload;

if (typeof ctx === 'function') {
fn = ctx;
Expand All @@ -274,8 +274,11 @@ export class CLI {
ctx = null;
}

const hookType = typeof fn === 'function' ? 'function' : 'event';
this.debugLogger.trace(`Creating ${hookType} hook "${name}"`);

return (...args) => {
let data = Object.assign(dataPayload, {
let data = Object.assign(dataPayload || {}, {
type: name,
args,
fn,
Expand All @@ -285,6 +288,8 @@ export class CLI {
const pres = this.hooks.pre[name] || [];
const posts = this.hooks.post[name] || [];

this.debugLogger.trace(`Firing ${hookType} hook "${name}" pres=${pres.length}, posts=${posts.length}`);

(async () => {
// call all pre filters
await pres
Expand Down

0 comments on commit cccda85

Please sign in to comment.