(projectDir: string)
| 113 | * Returns null when none is present. |
| 114 | */ |
| 115 | export function findMotionSpec(projectDir: string): string | null { |
| 116 | if (!existsSync(projectDir)) return null; |
| 117 | const entries = readdirSync(projectDir); |
| 118 | const sidecars = entries.filter((name) => name.endsWith(".motion.json")).sort(); |
| 119 | if (!sidecars[0]) return null; |
| 120 | if (sidecars.length === 1) return join(projectDir, sidecars[0]); |
| 121 | const htmlBases = new Set( |
| 122 | entries.filter((name) => name.endsWith(".html")).map((name) => basename(name, ".html")), |
| 123 | ); |
| 124 | const matched = sidecars.filter((name) => htmlBases.has(basename(name, ".motion.json"))); |
| 125 | if (matched.length > 1) { |
| 126 | throw new Error( |
| 127 | `ambiguous motion sidecars in ${projectDir}: ${matched.join(", ")} each match a composition — remove the sidecars you do not need, or use one composition per project`, |
| 128 | ); |
| 129 | } |
| 130 | return join(projectDir, matched[0] ?? sidecars[0]); |
| 131 | } |
| 132 | |
| 133 | export function readMotionSpec(path: string): MotionSpecParse { |
| 134 | let raw: unknown; |
no test coverage detected