| 18 | 'https://raw.githubusercontent.com/Mobilecn-UI/nativecn-ui/main'; |
| 19 | |
| 20 | export async function fetchComponents(components: string[]) { |
| 21 | try { |
| 22 | const fetchedComponents = await Promise.all( |
| 23 | components.map(async component => { |
| 24 | const response = await fetch(`${baseUrl}/components/${component}.tsx`); |
| 25 | const content = await response.text(); |
| 26 | return { |
| 27 | name: `${component}.tsx`, |
| 28 | content, |
| 29 | }; |
| 30 | }) |
| 31 | ); |
| 32 | |
| 33 | return fetchedComponents; |
| 34 | } catch (error) { |
| 35 | console.error(error); |
| 36 | throw new Error(`Failed to fetch components from registry.`); |
| 37 | } |
| 38 | } |