( themeName: string, endpoint: string, variables: string, isTS: boolean, semantic: boolean, spinner?: Ora )
| 637 | } |
| 638 | |
| 639 | async function apiTheme( |
| 640 | themeName: string, |
| 641 | endpoint: string, |
| 642 | variables: string, |
| 643 | isTS: boolean, |
| 644 | semantic: boolean, |
| 645 | spinner?: Ora |
| 646 | ): Promise<string> { |
| 647 | if (spinner) { |
| 648 | spinner.text = `🔨 building ${themeName}` |
| 649 | } else { |
| 650 | info(`⚡️ building theme: ${themeName}`) |
| 651 | } |
| 652 | const res = await fetch(`${endpoint}/generate`, { |
| 653 | method: 'POST', |
| 654 | headers: { 'Content-Type': 'application/json' }, |
| 655 | body: JSON.stringify({ |
| 656 | theme: themeName, |
| 657 | variables, |
| 658 | ts: String(isTS), |
| 659 | semantic: String(semantic), |
| 660 | }), |
| 661 | }) |
| 662 | if (res.ok) { |
| 663 | const code = normalizeGeneratedTheme(themeName, await res.text()) |
| 664 | return semantic ? code : scopeGeneratedThemeStateClasses(code) |
| 665 | } else { |
| 666 | error(`Could not generate theme — ${res.statusText}`) |
| 667 | } |
| 668 | } |
no test coverage detected