refactor: determine framework based on project info

This commit is contained in:
MuhammadM1998 2024-06-21 17:27:44 +03:00
parent b55573ac4d
commit b271e1e8df
4 changed files with 17 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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,
},
}

View File

@ -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