* Looks up for the task and runs * It also keeps the reference for the current active task * Keeping reference for the current task allows to cleanup task on interruption * * @private * @method runTask * @throws {Error} when no task found * @throws {Error} on attempt to run conc
(name, options)
| 228 | * @return {Promise} Task run |
| 229 | */ |
| 230 | runTask(name, options) { |
| 231 | if (this._currentTask) { |
| 232 | throw new Error(`Concurrent tasks are not supported`); |
| 233 | } |
| 234 | |
| 235 | logger.info(`\`${this.name}\` command running \`${name}\` task`); |
| 236 | |
| 237 | let Task = this.tasks[name]; |
| 238 | if (!Task) { |
| 239 | throw new Error(`Unknown task "${name}"`); |
| 240 | } |
| 241 | |
| 242 | let task = new Task(this._env(name)); |
| 243 | |
| 244 | this._currentTask = task; |
| 245 | |
| 246 | return Promise.resolve() |
| 247 | .then(() => task.run(options)) |
| 248 | .catch((error) => { |
| 249 | logger.info(`An error occurred running \`${name}\` from the \`${this.name}\` command.`, error.stack); |
| 250 | |
| 251 | throw error; |
| 252 | }) |
| 253 | .finally(() => { |
| 254 | delete this._currentTask; |
| 255 | }); |
| 256 | }, |
| 257 | |
| 258 | /** |
| 259 | Hook for extending a command before it is run in the cli.run command. |