MCPcopy Create free account
hub / github.com/formkit/formkit / generate

Function generate

packages/cli/src/theme.ts:373–504  ·  view source on GitHub ↗
(
  theme: Theme<ThemeOptions> | ReturnType<Theme<ThemeOptions>>,
  variables?: string,
  isTS?: boolean,
  semantic?: boolean,
  themeName?: string
)

Source from the content-addressed store, hash-verified

371}
372
373export async function generate(
374 theme: Theme<ThemeOptions> | ReturnType<Theme<ThemeOptions>>,
375 variables?: string,
376 isTS?: boolean,
377 semantic?: boolean,
378 themeName?: string
379): Promise<string> {
380 if (typeof theme === 'function') {
381 const vars = parseVariables(variables)
382 themeName = theme.meta.name
383 theme = theme(vars)
384 }
385 if (!themeName) error('Could not determine theme name.')
386 info(`Loaded theme: ${themeName}`)
387 const classes = theme.tailwind()
388 if (semantic) return await stylesheetFromTailwind(classes)
389 const classList: Record<string, Record<string, true>> = {}
390 const globals: Record<string, Record<string, true>> = {}
391
392 for (const input in classes) {
393 for (const section in classes[input]) {
394 const key = `${input}__${section}`
395 const sectionClasses = classes[input][section]
396 .split(' ')
397 .reduce((acc, cur) => {
398 acc[cur] = true
399 return acc
400 }, {} as Record<string, true>)
401 if (input === '__globals') {
402 globals[section] = sectionClasses
403 } else {
404 classList[key] = sectionClasses
405 }
406 }
407 }
408
409 const themeFile = `${
410 isTS ? "import type { FormKitNode } from '@formkit/core'\n\n" : ''
411 }/**
412 * @privateRemarks
413 * This file was generated by the FormKit CLI and should not be manually
414 * edited unless you’d like to "eject" from the CLI’s ability to update it.
415 *
416 * @checksum -
417 * @variables - ${variables}
418 * @theme - ${slugify(themeName)}
419 **/
420
421 /**
422 * This is the theme function itself, it should be imported and used as the
423 * config.rootClasses function. For example:
424 *
425 * \`\`\`js
426 * import { theme } from './formkit.theme'
427 * import { defineFormKitConfig } from '@formkit/vue'
428 *
429 * export default defineFormKitConfig({
430 * config: {

Callers 1

buildThemeFunction · 0.85

Calls 5

errorFunction · 0.90
infoFunction · 0.90
slugifyFunction · 0.90
parseVariablesFunction · 0.85
addThemeChecksumFunction · 0.85

Tested by

no test coverage detected