| 1 | import type { SlidevThemeMeta } from '@slidev/types' |
| 2 | import { existsSync } from 'node:fs' |
| 3 | import fs from 'node:fs/promises' |
| 4 | import { join } from 'pathe' |
| 5 | import { satisfies } from 'verkit' |
| 6 | import { version } from '../../package.json' |
| 7 | import { createResolver } from '../resolver' |
| 8 | |
| 9 | const officialThemes: Record<string, string> = { |
| 10 | 'none': '', |
| 11 | 'default': '@slidev/theme-default', |
| 12 | 'seriph': '@slidev/theme-seriph', |
| 13 | 'apple-basic': '@slidev/theme-apple-basic', |
| 14 | 'shibainu': '@slidev/theme-shibainu', |
| 15 | 'bricks': '@slidev/theme-bricks', |
| 16 | } |
| 17 | |
| 18 | export const resolveTheme = createResolver('theme', officialThemes) |
| 19 | |
| 20 | export async function getThemeMeta(name: string, root: string) { |
| 21 | const path = join(root, 'package.json') |
| 22 | if (!existsSync(path)) |
| 23 | return {} |
| 24 | |
| 25 | const { slidev = {}, engines = {} } = JSON.parse(await fs.readFile(path, 'utf-8')) |
| 26 | |
| 27 | if (engines.slidev && !satisfies(version, engines.slidev, { includePrerelease: true })) |
| 28 | throw new Error(`[slidev] theme "${name}" requires Slidev version range "${engines.slidev}" but found "${version}"`) |
| 29 | |
| 30 | return slidev as SlidevThemeMeta |
| 31 | } |
| 32 |