|
1 | 1 | /// <reference path="../typedef.js" />
|
2 | 2 |
|
3 |
| -const { deepAssign, log, keysAsFunctionsRecursive } = require('./utils') |
| 3 | +const { deepAssign, log, keysAsFunctionsRecursive, sortHooks } = require('./utils') |
4 | 4 |
|
5 | 5 |
|
6 | 6 | /** @type {AppEvent[]} */
|
@@ -34,35 +34,36 @@ const App = class {
|
34 | 34 | merge(obj) { deepAssign(this, obj) }
|
35 | 35 | async initiate() {
|
36 | 36 | this.config.roxi = await require('./roxi').run()
|
| 37 | + this.config.roxi.plugins.unshift( |
| 38 | + { name: 'mapper', params: {}, hooks: [{ event: 'bundle', order: { first: true }, action: app => keysAsFunctionsRecursive(app) }] }, |
| 39 | + ) |
37 | 40 | process.env.ROXI_LOG_LEVEL = this.config.roxi.logLevel
|
38 | 41 | }
|
39 | 42 | async run(events = this.events) {
|
40 | 43 | try {
|
41 | 44 | for (const event of events) {
|
42 |
| - console.log('event', event) |
43 | 45 | this.state.event = event
|
44 | 46 | await runPlugins(event, this)
|
45 | 47 | }
|
46 | 48 | } catch (err) { this.errorHandler(err) }
|
47 | 49 | }
|
48 | 50 | }
|
49 | 51 |
|
50 |
| -//todo move this somewhere else? |
51 |
| -const objToArray = { |
52 |
| - hooks: [{ event: 'bundle', action: app => keysAsFunctionsRecursive(app) }] |
53 |
| -} |
54 | 52 |
|
55 | 53 | /**
|
56 | 54 | * @param {AppEvent} event
|
57 | 55 | * @param {RoxiApp} app
|
58 | 56 | */
|
59 | 57 | async function runPlugins(event, app) {
|
60 |
| - const plugins = [objToArray, ...app.config.roxi.plugins] |
61 |
| - for (const plugin of plugins) { |
62 |
| - const hooks = plugin.hooks.filter(hookCondition(app, plugin.params, { event })) |
63 |
| - for (const hook of hooks) |
64 |
| - await app.hookHandler(app, hook, plugin, { event }) |
65 |
| - } |
| 58 | + let hooks = [] |
| 59 | + |
| 60 | + for (const plugin of app.config.roxi.plugins) |
| 61 | + plugin.hooks |
| 62 | + .filter(hookCondition(app, plugin.params, { event })) |
| 63 | + .forEach(hook => hooks.push({ plugin, hook })) |
| 64 | + |
| 65 | + for (const hook of sortHooks(hooks)) |
| 66 | + await app.hookHandler(app, hook.hook, hook.plugin, { event }) |
66 | 67 | }
|
67 | 68 |
|
68 | 69 | /**
|
|
0 commit comments