* Builds the formkit.config.ts file. * @param options - Build the formkit.config.ts file for a Nuxt project. * @returns
(options: CreateAppOptions)
| 600 | * @returns |
| 601 | */ |
| 602 | function buildFormKitConfig(options: CreateAppOptions): string { |
| 603 | const imports = ['import { genesisIcons } from "@formkit/icons"'] |
| 604 | imports.push('import { rootClasses } from "./formkit.theme"') |
| 605 | if (options.lang === 'ts' && options.framework === 'vite') { |
| 606 | imports.push("import { DefaultConfigOptions } from '@formkit/vue'") |
| 607 | } else if (options.lang === 'ts' && options.framework === 'nuxt') { |
| 608 | imports.push("import { defineFormKitConfig } from '@formkit/vue'") |
| 609 | } |
| 610 | const setup = [] |
| 611 | let config = '' |
| 612 | if (options.pro) { |
| 613 | imports.push("import { createProPlugin, inputs } from '@formkit/pro'") |
| 614 | setup.push('') |
| 615 | setup.push(`const pro = createProPlugin('${options.pro}', inputs)`) |
| 616 | setup.push('') |
| 617 | config += ` plugins: [pro]` |
| 618 | } |
| 619 | config += `${config ? ',\n' : ''} icons: { ...genesisIcons }` |
| 620 | config += `${config ? ',\n' : ''} config: { rootClasses }` |
| 621 | |
| 622 | const viteExport = `const config${ |
| 623 | options.lang === 'ts' ? ': DefaultConfigOptions' : '' |
| 624 | } = { |
| 625 | ${config} |
| 626 | } |
| 627 | |
| 628 | export default config` |
| 629 | |
| 630 | const nuxtExport = `export default defineFormKitConfig(() => ({ |
| 631 | ${config} |
| 632 | }))` |
| 633 | |
| 634 | let defaultExport = '' |
| 635 | if (options.framework === 'nuxt') { |
| 636 | defaultExport = nuxtExport |
| 637 | } else if (options.framework === 'vite') { |
| 638 | defaultExport = viteExport |
| 639 | } |
| 640 | |
| 641 | const rawConfig = `${imports.join('\n')} |
| 642 | ${setup.join('\n')} |
| 643 | ${defaultExport} |
| 644 | ` |
| 645 | |
| 646 | return rawConfig |
| 647 | } |