1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const apis = require(`./api-ssr-docs`)
|
14 |
|
15 |
|
16 | module.exports = (api, args, defaultReturn, argTransform) => {
|
17 | if (!apis[api]) {
|
18 | console.log(`This API doesn't exist`, api)
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 | let results = plugins.map(plugin => {
|
24 | if (!plugin.plugin[api]) {
|
25 | return undefined
|
26 | }
|
27 | const result = plugin.plugin[api](args, plugin.options)
|
28 | if (result && argTransform) {
|
29 | args = argTransform({ args, result })
|
30 | }
|
31 | return result
|
32 | })
|
33 |
|
34 |
|
35 | results = results.filter(result => typeof result !== `undefined`)
|
36 |
|
37 | if (results.length > 0) {
|
38 | return results
|
39 | } else {
|
40 | return [defaultReturn]
|
41 | }
|
42 | }
|