You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After #528, the CLI should check in a Nuxt project If shadcn-nuxt injects the file or not and act accordingly. This requires modifying the following code.
This checking can get messy too quick, and that's for Nuxt-specifics alone. Adding features specific to astro for example would require adding checks for that too.
I propose refactoring the runInit command to the following
cli/src/commands/init.ts
import{runNuxtInitTemplate,runNuxtInitTemplate,runNuxtInitTemplate}from'./initTempaltes'exportasyncfunctionrunInit(cwd: string,config: Config){constspinner=ora('Initializing project...')?.start()constcontext=awaitgetProjectInfo()// `context` has `framework` option among other useful keysconst{ framework }=context// Shared Inline Code// Running the appropriate init template based on frameworkletsuccess,error;if(context.framework==='nuxt'){success,error}=runNuxtInitTemplate(context)elseif(context.framework==='vite'){success,error}=runVueInitTemplate(context)elseif(context.framework==='astro'){success,error}=runAstroInitTemplate(context)// Just for example. For now I think `Nuxt` and `Vue` templates would be sufficentif(error)returnconsola.error('Error while initializing.',error)spinner?.succeed()}
cli/src/commands/initTempaltes.ts
exportfunctionrunNuxtInitTemplate(context: ProjectContext){// Specific Nuxt ThingssharedFunction()// Other Specific Nuxt Thingsreturn{ success, error }}exportfunctionrunViteInitTemplate(context: ProjectContext){// Specific Vite SetupsharedFunction()// Other Specific Vite Thingsreturn{ success, error }}exportfunctionrunAstroInitTemplate(context: ProjectContext){// Specific Astro SetupsharedFunction()// Other Specific Astro Thingsreturn{ success, error }}functionsharedFunction(){// Stuff}
This way is more organized and easier to understand & maintain. Also if anyone want to contribute to specific framework he won't need to understand how the other frameworks work and avoids changing unrelated code which can cause mistakes.
I opened the issue for discussion. I'm up to raise a PR once a final structure is agreed 🙏
Additional information
I intend to submit a PR for this feature.
I have already implemented and/or tested this feature.
The text was updated successfully, but these errors were encountered:
Describe the feature
After #528, the CLI should check in a Nuxt project If
shadcn-nuxt
injects the file or not and act accordingly. This requires modifying the following code.https://github.com/radix-vue/shadcn-vue/blob/bd0a8206efa0c0f1fee735f17ab94c63b408e106/packages/cli/src/commands/init.ts#L301-L306
Similarly after #531 need to check if we should install all deps or only a set of them here
https://github.com/radix-vue/shadcn-vue/blob/bd0a8206efa0c0f1fee735f17ab94c63b408e106/packages/cli/src/commands/init.ts#L313-L316
This checking can get messy too quick, and that's for Nuxt-specifics alone. Adding features specific to astro for example would require adding checks for that too.
I propose refactoring the
runInit
command to the followingcli/src/commands/init.ts
cli/src/commands/initTempaltes.ts
This way is more organized and easier to understand & maintain. Also if anyone want to contribute to specific framework he won't need to understand how the other frameworks work and avoids changing unrelated code which can cause mistakes.
I opened the issue for discussion. I'm up to raise a PR once a final structure is agreed 🙏
Additional information
The text was updated successfully, but these errors were encountered: