From b271e1e8df0f06d6e31e47a6e670fd11122ab284 Mon Sep 17 00:00:00 2001 From: MuhammadM1998 Date: Fri, 21 Jun 2024 17:27:44 +0300 Subject: [PATCH] refactor: determine framework based on project info --- packages/cli/src/commands/add.ts | 5 +++-- packages/cli/src/commands/diff.ts | 5 +++-- packages/cli/src/commands/frameworks/index.ts | 8 ++++++++ packages/cli/src/commands/init.ts | 5 +++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index e4d5cbf0..df19029c 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -5,6 +5,7 @@ import { consola } from 'consola' import { colors } from 'consola/utils' import { Command } from 'commander' import { z } from 'zod' +import { getProjectInfo } from '../utils/get-project-info' import frameworksCommands from './frameworks' import { handleError } from '@/src/utils/handle-error' @@ -45,8 +46,8 @@ export const add = new Command() } // Get the corresponding framework commands - // TODO: Pass this to action inside a `context` argument to the function - const framework = 'vue' + const { isNuxt } = await getProjectInfo() + const framework = isNuxt ? 'nuxt' : 'vue' const { loadConfig, add } = frameworksCommands[framework] // Read config diff --git a/packages/cli/src/commands/diff.ts b/packages/cli/src/commands/diff.ts index 76a88ea6..e6542936 100644 --- a/packages/cli/src/commands/diff.ts +++ b/packages/cli/src/commands/diff.ts @@ -5,6 +5,7 @@ import { consola } from 'consola' import { colors } from 'consola/utils' import { Command } from 'commander' import { z } from 'zod' +import { getProjectInfo } from '../utils/get-project-info' import frameworksCommands from './frameworks' import { handleError } from '@/src/utils/handle-error' @@ -40,8 +41,8 @@ export const diff = new Command() } // Get the corresponding framework commands - // TODO: Pass this to action inside a `context` argument to the function - const framework = 'vue' + const { isNuxt } = await getProjectInfo() + const framework = isNuxt ? 'nuxt' : 'vue' const { loadConfig, diff } = frameworksCommands[framework] // Load Config diff --git a/packages/cli/src/commands/frameworks/index.ts b/packages/cli/src/commands/frameworks/index.ts index f9491bf0..328156db 100644 --- a/packages/cli/src/commands/frameworks/index.ts +++ b/packages/cli/src/commands/frameworks/index.ts @@ -10,4 +10,12 @@ export default { add: addVue, diff: diffVue, }, + // For now we run the same commands for Nuxt as for Vue + // TODO: replace with Nuxt-specific commands when required + nuxt: { + loadConfig: loadConfigVue, + init: initVue, + add: addVue, + diff: diffVue, + }, } diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 0a60f25c..809306f1 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -6,6 +6,7 @@ import { z } from 'zod' import { consola } from 'consola' import { colors } from 'consola/utils' import { handleError } from '../utils/handle-error' +import { getProjectInfo } from '../utils/get-project-info' import frameworksCommands from './frameworks' const initOptionsSchema = z.object({ @@ -34,8 +35,8 @@ export const init = new Command() } // Get the corresponding framework commands - // TODO: Pass this to action inside a `context` argument to the function - const framework = 'vue' + const { isNuxt } = await getProjectInfo() + const framework = isNuxt ? 'nuxt' : 'vue' const { loadConfig, init } = frameworksCommands[framework] // Read config