Skip to content

Commit

Permalink
refactor: determine framework based on project info
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadM1998 committed Jun 21, 2024
1 parent c098a20 commit 53ddfd2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/commands/frameworks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
5 changes: 3 additions & 2 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 53ddfd2

Please sign in to comment.