github.com/nektos/act@v0.2.63/pkg/runner/testdata/actions/node12/node_modules/before-after-hook/lib/add.js (about) 1 module.exports = addHook; 2 3 function addHook(state, kind, name, hook) { 4 var orig = hook; 5 if (!state.registry[name]) { 6 state.registry[name] = []; 7 } 8 9 if (kind === "before") { 10 hook = function (method, options) { 11 return Promise.resolve() 12 .then(orig.bind(null, options)) 13 .then(method.bind(null, options)); 14 }; 15 } 16 17 if (kind === "after") { 18 hook = function (method, options) { 19 var result; 20 return Promise.resolve() 21 .then(method.bind(null, options)) 22 .then(function (result_) { 23 result = result_; 24 return orig(result, options); 25 }) 26 .then(function () { 27 return result; 28 }); 29 }; 30 } 31 32 if (kind === "error") { 33 hook = function (method, options) { 34 return Promise.resolve() 35 .then(method.bind(null, options)) 36 .catch(function (error) { 37 return orig(error, options); 38 }); 39 }; 40 } 41 42 state.registry[name].push({ 43 hook: hook, 44 orig: orig, 45 }); 46 }