import { splitByCase, upperFirst, camelCase, kebabCase } from 'scule'
const playground = ({ name, pro }) => {
const upperName = splitByCase(name).map(p => upperFirst(p)).join('')
const kebabName = kebabCase(name)
return {
filename: `playground/pages/${kebabName}.vue`,
contents: pro
? undefined
: `
`
}
}
const component = ({ name, primitive, pro }) => {
const upperName = splitByCase(name).map(p => upperFirst(p)).join('')
const camelName = camelCase(name)
const kebabName = kebabCase(name)
const key = pro ? 'uiPro' : 'ui'
const path = pro ? 'ui-pro' : 'ui'
return {
filename: `src/runtime/components/${upperName}.vue`,
contents: primitive
? `
`
: `
<${upperName}Root v-bind="rootProps" :class="ui.root({ class: props.class })" />
`
}
}
const theme = ({ name }) => {
const kebabName = kebabCase(name)
return {
filename: `src/theme/${kebabName}.ts`,
contents: `
export default {
slots: {
root: ''
}
}
`
}
}
const test = ({ name }) => {
const upperName = splitByCase(name).map(p => upperFirst(p)).join('')
return {
filename: `test/components/${upperName}.spec.ts`,
contents: `
import { describe, it, expect } from 'vitest'
import ${upperName}, { type ${upperName}Props, type ${upperName}Slots } from '../../src/runtime/components/${upperName}.vue'
import ComponentRender from '../component-render'
describe('${upperName}', () => {
it.each([
// Props
['with as', { props: { as: 'div' } }],
['with class', { props: { class: '' } }],
['with ui', { props: { ui: {} } }],
// Slots
['with default slot', { slots: { default: () => 'Default slot' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: ${upperName}Props, slots?: Partial<${upperName}Slots> }) => {
const html = await ComponentRender(nameOrHtml, options, ${upperName})
expect(html).toMatchSnapshot()
})
})
`
}
}
export default {
playground,
component,
theme,
test
}