Comparing version 0.0.9 to 0.0.10
@@ -87,3 +87,3 @@ 'use strict' | ||
for (let task of this.registry.tasks) { | ||
for (let task of this.registry.tasks.reverse()) { | ||
try { | ||
@@ -100,2 +100,36 @@ await task.recover(err) | ||
* @param {any} task | ||
* @memberof Task | ||
*/ | ||
async bootSubTask(task, state) { | ||
this.registry.addTask(task) | ||
// pass share config | ||
task.config.bootme = this.registry.sharedConfig | ||
// lazy evaluation of task config | ||
if (typeof task.config === 'function') { | ||
const config = await task.config() | ||
task.setConfig(config) | ||
} else { | ||
task.setConfig(task.config) | ||
} | ||
task.addHook('onInit', async state => task.init(state)) | ||
await task.executeHooks('onInit', state) | ||
await task.executeHooks('onBefore', state) | ||
const result = await task.action(state) | ||
if (result && typeof task.validateResult === 'function') { | ||
await task.validateResult(result) | ||
} | ||
state.pipeline.results.set(`${task.name}`, result) | ||
await task.executeHooks('onAfter', state) | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} task | ||
* @memberof Pipeline | ||
@@ -114,2 +148,4 @@ */ | ||
task.setConfig(config) | ||
} else { | ||
task.setConfig(task.config) | ||
} | ||
@@ -116,0 +152,0 @@ |
@@ -45,4 +45,11 @@ 'use strict' | ||
} | ||
const exists = this.tasks.find(t => t.name === task.name) | ||
if (exists) { | ||
throw new Error(`The Task "${task.name}" already exists`) | ||
} | ||
task.addHook('onInit', async state => task.init(state)) | ||
task.config.bootme = this.sharedConfig | ||
this.tasks.push(task) | ||
@@ -61,3 +68,3 @@ | ||
addHook(taskName, hookName, fn) { | ||
const task = this.tasks.find((t) => t.name === taskName) | ||
const task = this.tasks.find(t => t.name === taskName) | ||
@@ -64,0 +71,0 @@ if (task) { |
@@ -53,3 +53,3 @@ 'use strict' | ||
if (result.error) { | ||
error(`Invalid config schema. Task ${this.name}`) | ||
error(`Invalid config schema. Task "${this.name}"`) | ||
throw result.error | ||
@@ -109,3 +109,4 @@ } | ||
throw new TypeError( | ||
`Hook handler of must be a function or Task instance. Task "${this.name}"` | ||
`Hook handler of must be a function or Task instance. Task "${this | ||
.name}"` | ||
) | ||
@@ -153,4 +154,5 @@ } | ||
for (let hook of this[name]) { | ||
// allow passing tasks as hook handlers | ||
if (hook instanceof Task) { | ||
await hook.action(state) | ||
await state.pipeline.bootSubTask(hook, state) | ||
} else { | ||
@@ -157,0 +159,0 @@ await hook.call(this, state) |
{ | ||
"name": "bootme", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11316
471