diff --git a/packages/cli/package.json b/packages/cli/package.json index 7755764d..55634d27 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -66,8 +66,10 @@ "ofetch": "^1.3.4", "ora": "^8.0.1", "pathe": "^1.1.2", + "pkg-types": "^1.1.0", "prompts": "^2.4.2", "radix-vue": "^1.7.3", + "semver": "^7.6.0", "ts-morph": "^22.0.0", "tsconfig-paths": "^4.2.0", "zod": "^3.23.3" diff --git a/packages/cli/src/utils/get-project-info.ts b/packages/cli/src/utils/get-project-info.ts index a2219f6d..3877957d 100644 --- a/packages/cli/src/utils/get-project-info.ts +++ b/packages/cli/src/utils/get-project-info.ts @@ -1,11 +1,14 @@ import { existsSync } from 'node:fs' import path from 'pathe' import fs from 'fs-extra' +import { readPackageJSON } from 'pkg-types' +import type { PackageJson } from 'pkg-types' export async function getProjectInfo() { const info = { tsconfig: null, isNuxt: false, + shadcnNuxt: undefined, isVueVite: false, srcDir: false, componentsUiDir: false, @@ -15,9 +18,13 @@ export async function getProjectInfo() { try { const tsconfig = await getTsConfig() + const isNuxt = existsSync(path.resolve('./nuxt.config.js')) || existsSync(path.resolve('./nuxt.config.ts')) + const shadcnNuxt = isNuxt ? await getShadcnNuxtInfo() : undefined + return { tsconfig, - isNuxt: existsSync(path.resolve('./nuxt.config.js')) || existsSync(path.resolve('./nuxt.config.ts')), + isNuxt, + shadcnNuxt, isVueVite: existsSync(path.resolve('./vite.config.js')) || existsSync(path.resolve('./vite.config.ts')), srcDir: existsSync(path.resolve('./src')), srcComponentsUiDir: existsSync(path.resolve('./src/components/ui')), @@ -29,6 +36,18 @@ export async function getProjectInfo() { } } +async function getShadcnNuxtInfo() { + let nuxtModule: PackageJson | undefined + try { + nuxtModule = await readPackageJSON('shadcn-nuxt') + } + catch (error) { + nuxtModule = undefined + } + + return nuxtModule +} + export async function getTsConfig() { try { const tsconfigPath = path.join('tsconfig.json') diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index be002ed1..3257f85b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -279,12 +279,23 @@ importers: pathe: specifier: ^1.1.2 version: 1.1.2 + pkg-types: + specifier: ^1.1.0 + version: 1.1.0 prompts: specifier: ^2.4.2 version: 2.4.2 radix-vue: +<<<<<<< HEAD specifier: ^1.7.3 version: 1.7.3(vue@3.4.27(typescript@5.4.5)) +======= + specifier: ^1.7.2 + version: 1.7.2(vue@3.4.24(typescript@5.4.5)) + semver: + specifier: ^7.6.0 + version: 7.6.0 +>>>>>>> 582818d (feat(cli): expose `shadcn-nuxt` info) ts-morph: specifier: ^22.0.0 version: 22.0.0 @@ -8938,7 +8949,7 @@ snapshots: lru-cache: 10.2.0 npm-pick-manifest: 9.0.0 proc-log: 4.2.0 - promise-inflight: 1.0.1 + promise-inflight: 1.0.1(bluebird@3.7.2) promise-retry: 2.0.1 semver: 7.6.0 which: 4.0.0 @@ -14854,8 +14865,6 @@ snapshots: process@0.11.10: {} - promise-inflight@1.0.1: {} - promise-inflight@1.0.1(bluebird@3.7.2): optionalDependencies: bluebird: 3.7.2