(plugins: FrameworkModule[])
| 1 | import type { FrameworkModule, TinyPagesConfig } from "../../types/types"; |
| 2 | |
| 3 | export function pluginKit(plugins: FrameworkModule[]) { |
| 4 | const pre: FrameworkModule[] = []; |
| 5 | const post: FrameworkModule[] = []; |
| 6 | const mainplugins: FrameworkModule[] = []; |
| 7 | plugins.forEach((p) => { |
| 8 | if (p.enforce === "pre") { |
| 9 | pre.push(p); |
| 10 | } else if (p.enforce === "post") { |
| 11 | post.push(p); |
| 12 | } else { |
| 13 | mainplugins.push(p); |
| 14 | } |
| 15 | }); |
| 16 | const modules: FrameworkModule[] = [...pre, ...mainplugins, ...post]; |
| 17 | return { |
| 18 | async defineConfig(c: TinyPagesConfig) { |
| 19 | for (let m of modules) { |
| 20 | await m?.defineConfig(c); |
| 21 | } |
| 22 | }, |
| 23 | resolveComponentPath(path: string): string { |
| 24 | for (let m of modules) { |
| 25 | const new_path = m?.resolveComponentPath(path); |
| 26 | if (new_path) { |
| 27 | return new_path; |
| 28 | } |
| 29 | } |
| 30 | return ""; |
| 31 | }, |
| 32 | async editEntryFile(id: string, code: string) { |
| 33 | for (let m of modules) { |
| 34 | const new_code = await m?.editEntryFile(id, code); |
| 35 | if (new_code) { |
| 36 | code = new_code; |
| 37 | } |
| 38 | } |
| 39 | return code; |
| 40 | }, |
| 41 | async renderComponent(c, extra) { |
| 42 | for (let m of modules) { |
| 43 | const stringifiedComponent = await m?.renderComponent(c, extra); |
| 44 | if (stringifiedComponent) { |
| 45 | return stringifiedComponent; |
| 46 | } |
| 47 | } |
| 48 | return ""; |
| 49 | }, |
| 50 | }; |
| 51 | } |
no outgoing calls
no test coverage detected