feat(cli): expose shadcn-nuxt info

This commit is contained in:
MuhammadM1998 2024-05-06 18:13:39 +03:00
parent 68a434453a
commit 486a06874b
3 changed files with 34 additions and 4 deletions

View File

@ -66,8 +66,10 @@
"ofetch": "^1.3.4", "ofetch": "^1.3.4",
"ora": "^8.0.1", "ora": "^8.0.1",
"pathe": "^1.1.2", "pathe": "^1.1.2",
"pkg-types": "^1.1.0",
"prompts": "^2.4.2", "prompts": "^2.4.2",
"radix-vue": "^1.7.3", "radix-vue": "^1.7.3",
"semver": "^7.6.0",
"ts-morph": "^22.0.0", "ts-morph": "^22.0.0",
"tsconfig-paths": "^4.2.0", "tsconfig-paths": "^4.2.0",
"zod": "^3.23.3" "zod": "^3.23.3"

View File

@ -1,11 +1,14 @@
import { existsSync } from 'node:fs' import { existsSync } from 'node:fs'
import path from 'pathe' import path from 'pathe'
import fs from 'fs-extra' import fs from 'fs-extra'
import { readPackageJSON } from 'pkg-types'
import type { PackageJson } from 'pkg-types'
export async function getProjectInfo() { export async function getProjectInfo() {
const info = { const info = {
tsconfig: null, tsconfig: null,
isNuxt: false, isNuxt: false,
shadcnNuxt: undefined,
isVueVite: false, isVueVite: false,
srcDir: false, srcDir: false,
componentsUiDir: false, componentsUiDir: false,
@ -15,9 +18,13 @@ export async function getProjectInfo() {
try { try {
const tsconfig = await getTsConfig() 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 { return {
tsconfig, 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')), isVueVite: existsSync(path.resolve('./vite.config.js')) || existsSync(path.resolve('./vite.config.ts')),
srcDir: existsSync(path.resolve('./src')), srcDir: existsSync(path.resolve('./src')),
srcComponentsUiDir: existsSync(path.resolve('./src/components/ui')), 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() { export async function getTsConfig() {
try { try {
const tsconfigPath = path.join('tsconfig.json') const tsconfigPath = path.join('tsconfig.json')

View File

@ -279,12 +279,23 @@ importers:
pathe: pathe:
specifier: ^1.1.2 specifier: ^1.1.2
version: 1.1.2 version: 1.1.2
pkg-types:
specifier: ^1.1.0
version: 1.1.0
prompts: prompts:
specifier: ^2.4.2 specifier: ^2.4.2
version: 2.4.2 version: 2.4.2
radix-vue: radix-vue:
<<<<<<< HEAD
specifier: ^1.7.3 specifier: ^1.7.3
version: 1.7.3(vue@3.4.27(typescript@5.4.5)) 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: ts-morph:
specifier: ^22.0.0 specifier: ^22.0.0
version: 22.0.0 version: 22.0.0
@ -8938,7 +8949,7 @@ snapshots:
lru-cache: 10.2.0 lru-cache: 10.2.0
npm-pick-manifest: 9.0.0 npm-pick-manifest: 9.0.0
proc-log: 4.2.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 promise-retry: 2.0.1
semver: 7.6.0 semver: 7.6.0
which: 4.0.0 which: 4.0.0
@ -14854,8 +14865,6 @@ snapshots:
process@0.11.10: {} process@0.11.10: {}
promise-inflight@1.0.1: {}
promise-inflight@1.0.1(bluebird@3.7.2): promise-inflight@1.0.1(bluebird@3.7.2):
optionalDependencies: optionalDependencies:
bluebird: 3.7.2 bluebird: 3.7.2