diff --git a/cli/commands/init.mjs b/cli/commands/init.mjs index 9afaafa3..b06586c3 100644 --- a/cli/commands/init.mjs +++ b/cli/commands/init.mjs @@ -24,12 +24,29 @@ export default defineCommand({ pro: { type: 'boolean', description: 'Create a pro component.' + }, + prose: { + type: 'boolean', + description: 'Create a prose component (with --pro).' + }, + content: { + type: 'boolean', + description: 'Create a content component (with --pro).' } }, async setup({ args }) { const name = args.name if (!name) { - consola.error('name argument is missing!') + consola.error('`name` argument is missing!') + process.exit(1) + } + + if (args.prose && !args.pro) { + consola.error('`--prose` flag can only be used with `--pro` flag!') + process.exit(1) + } + if (args.content && !args.pro) { + consola.error('`--content` flag can only be used with `--pro` flag!') process.exit(1) } @@ -53,12 +70,14 @@ export default defineCommand({ consola.success(`🪄 Generated ${filePath}!`) } - const themePath = resolve(path, 'src/theme/index.ts') + const themePath = resolve(path, `src/theme/${args.prose ? 'prose/' : ''}${args.content ? 'content/' : ''}index.ts`) await appendFile(themePath, `export { default as ${camelCase(name)} } from './${kebabCase(name)}'`) await sortFile(themePath) - const typesPath = resolve(path, 'src/runtime/types/index.d.ts') - await appendFile(typesPath, `export * from '../components/${splitByCase(name).map(p => upperFirst(p)).join('')}.vue'`) - await sortFile(typesPath) + if (!args.prose) { + const typesPath = resolve(path, 'src/runtime/types/index.d.ts') + await appendFile(typesPath, `export * from '../components/${args.content && 'content/'}${splitByCase(name).map(p => upperFirst(p)).join('')}.vue'`) + await sortFile(typesPath) + } } }) diff --git a/cli/templates.mjs b/cli/templates.mjs index 2138fb8f..548f0846 100644 --- a/cli/templates.mjs +++ b/cli/templates.mjs @@ -14,11 +14,11 @@ const playground = ({ name, pro }) => { - ` +` } } -const component = ({ name, primitive, pro }) => { +const component = ({ name, primitive, pro, prose, content }) => { const upperName = splitByCase(name).map(p => upperFirst(p)).join('') const camelName = camelCase(name) const kebabName = kebabCase(name) @@ -26,7 +26,7 @@ const component = ({ name, primitive, pro }) => { const path = pro ? 'ui-pro' : 'ui' return { - filename: `src/runtime/components/${upperName}.vue`, + filename: `src/runtime/components/${prose ? 'prose/' : ''}${content ? 'content/' : ''}${upperName}.vue`, contents: primitive ? `