(options: Partial<BuildThemeOptions> = {})
| 100 | } |
| 101 | |
| 102 | export async function buildTheme(options: Partial<BuildThemeOptions> = {}) { |
| 103 | if (!themes.length) await fetchThemes() |
| 104 | |
| 105 | // Detect Tailwind version from user's project |
| 106 | const detectedTwVersion = await detectTailwindVersion() |
| 107 | if (detectedTwVersion) { |
| 108 | info(`Detected Tailwind CSS v${detectedTwVersion} in your project`) |
| 109 | } else { |
| 110 | info('Could not detect Tailwind version, defaulting to v4 theme') |
| 111 | } |
| 112 | |
| 113 | let themeName = options.theme || '' |
| 114 | |
| 115 | // If theme was explicitly provided, check if we need to adjust for TW version |
| 116 | if (options.theme && !isTw3Theme(options.theme)) { |
| 117 | // User provided a base theme name, adjust based on detected TW version |
| 118 | themeName = getThemeNameForTailwindVersion(options.theme, detectedTwVersion) |
| 119 | if (themeName !== options.theme) { |
| 120 | info(`Using ${themeName} for Tailwind v${detectedTwVersion} compatibility`) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if (!options.theme) { |
| 125 | const generatedTheme = await localGeneratedTheme() |
| 126 | |
| 127 | if (generatedTheme) { |
| 128 | const [code, path] = generatedTheme |
| 129 | try { |
| 130 | const [checksum, variables, theme] = extractThemeData(code) |
| 131 | |
| 132 | // determine if the theme is from themes.formkit.com |
| 133 | const themeFromList = themes.find((t: any) => t.slug === theme) |
| 134 | |
| 135 | if (themeFromList) { |
| 136 | const { editMode } = await prompts({ |
| 137 | type: 'confirm', |
| 138 | message: `Found local theme file for ${theme}, edit this theme?`, |
| 139 | name: 'editMode', |
| 140 | initial: true, |
| 141 | }) |
| 142 | if (editMode) { |
| 143 | return await editTheme(path, code, checksum, variables, theme) |
| 144 | } |
| 145 | } else if (generatedTheme) { |
| 146 | red( |
| 147 | 'It appears you have a local theme installed that is not part of the themes.formkit.com registry. By continuing your local theme file will be overwritten.' |
| 148 | ) |
| 149 | const { confirm } = await prompts({ |
| 150 | type: 'confirm', |
| 151 | message: 'Are you sure you want to continue?', |
| 152 | name: 'confirm', |
| 153 | initial: false, |
| 154 | }) |
| 155 | |
| 156 | if (!confirm) { |
| 157 | return error('Aborting.') |
| 158 | } |
| 159 | } |
no test coverage detected