import fs from 'node:fs' const items = JSON.parse(fs.readFileSync('park-registry.json', 'utf8').replace(/^\uFEFF/, '')) const imports = new Set() let config = { preflight: true, include: ['./src/**/*.{ts,tsx}'], outdir: 'styled-system', jsxFramework: 'react', } function merge(a, b) { for (const [k, v] of Object.entries(b || {})) { if (v && typeof v === 'object' && !Array.isArray(v)) { a[k] ??= {} merge(a[k], v) } else a[k] = v } return a } const recipes = [], slots = [] for (const item of items) { for (const i of item.panda?.imports || []) imports.add(`import { ${i.name} } from './src/theme/${i.from.replaceAll('\\', '/')}'`) merge(config, item.panda?.extension) for (const f of item.files || []) if (f.type === 'registry:recipe' && f.path !== 'index.ts') { let n = f.content.match(/export const (\w+)/)?.[1] if (n) (f.content.includes('defineSlotRecipe') ? slots : recipes).push([ n, f.path.replace(/\.ts$/, ''), ]) } } fs.writeFileSync( 'src/theme/recipes/index.ts', [...recipes, ...slots].map(([n, p]) => `import {${n}} from './${p}'`).join('\n') + `\nexport const recipes = {${recipes.map(([n]) => n)}}\nexport const slotRecipes = {${slots.map(([n]) => n)}}\n`, ) merge(config, { theme: { extend: { semanticTokens: { radii: { l1: { value: '2px' }, l2: { value: '3px' }, l3: { value: '4px' }, }, }, }, }, }) let code = JSON.stringify(config, null, 2).replace(/"\$ref:([^"]+)"/g, '$1') fs.writeFileSync( 'panda.config.ts', `import {defineConfig} from '@pandacss/dev'\n${[...imports].join('\n')}\nexport default defineConfig(${code})\n`, ) for (const [file, from, to] of [ ['src/theme/global-css.ts', "colorPalette: 'gray'", "colorPalette: 'violet'"], [ 'src/theme/conditions.ts', "light: ':root &, .light &'", "light: ':root:not(.dark) &, .light &'", ], ]) fs.writeFileSync(file, fs.readFileSync(file, 'utf8').replace(from, to))