| 1 | import type { TransformersSetup, TransformersSetupReturn } from '@slidev/types' |
| 2 | import { loadSetups } from './load' |
| 3 | |
| 4 | export default async function setupTransformers(roots: string[]) { |
| 5 | const returns = await loadSetups<TransformersSetup>(roots, 'transformers.ts', []) |
| 6 | const result: TransformersSetupReturn = { |
| 7 | pre: [], |
| 8 | preCodeblock: [], |
| 9 | postCodeblock: [], |
| 10 | post: [], |
| 11 | codeblocks: [], |
| 12 | } |
| 13 | for (const r of [...returns].reverse()) { |
| 14 | if (r.pre) |
| 15 | result.pre.push(...r.pre) |
| 16 | if (r.preCodeblock) |
| 17 | result.preCodeblock.push(...r.preCodeblock) |
| 18 | } |
| 19 | for (const r of returns) { |
| 20 | if (r.postCodeblock) |
| 21 | result.postCodeblock.push(...r.postCodeblock) |
| 22 | if (r.post) |
| 23 | result.post.push(...r.post) |
| 24 | if (r.codeblocks) |
| 25 | result.codeblocks.push(...r.codeblocks) |
| 26 | } |
| 27 | return result |
| 28 | } |
| 29 |