refactor: load jsconfig and remove root option
This commit is contained in:
parent
d588ce03fb
commit
996114de19
|
|
@ -117,12 +117,6 @@ export async function promptForConfig(
|
|||
{ title: 'Nuxt', value: 'nuxt' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
name: 'root',
|
||||
message: `Where is your ${highlight('source code')} folder located`,
|
||||
initial: (prev, values) => defaultConfig?.root ?? values.framework === 'nuxt' ? '.' : 'src',
|
||||
},
|
||||
{
|
||||
type: 'select',
|
||||
name: 'style',
|
||||
|
|
@ -181,7 +175,6 @@ export async function promptForConfig(
|
|||
|
||||
const config = rawConfigSchema.parse({
|
||||
// $schema: 'https://ui.shadcn.com/schema.json',
|
||||
root: options.root,
|
||||
style: options.style,
|
||||
typescript: options.typescript,
|
||||
framework: options.framework,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ const explorer = cosmiconfig('components', {
|
|||
export const rawConfigSchema = z
|
||||
.object({
|
||||
$schema: z.string().optional(),
|
||||
root: z.string(),
|
||||
style: z.string(),
|
||||
typescript: z.boolean().default(false),
|
||||
tailwind: z.object({
|
||||
|
|
@ -65,26 +64,31 @@ export async function getConfig(cwd: string) {
|
|||
|
||||
export async function resolveConfigPaths(cwd: string, config: RawConfig) {
|
||||
let tsConfig: ConfigLoaderResult | undefined
|
||||
let tsConfigPath = path.resolve(
|
||||
cwd,
|
||||
config.framework === 'nuxt' ? '.nuxt/tsconfig.json' : './tsconfig.json',
|
||||
)
|
||||
|
||||
if (config.typescript) {
|
||||
const TSCONFIG_PATH = config.framework === 'nuxt' ? '.nuxt/tsconfig.json' : './tsconfig.json'
|
||||
|
||||
// Read tsconfig.json.
|
||||
const tsconfigPath = path.resolve(cwd, TSCONFIG_PATH)
|
||||
tsConfig = loadConfig(tsconfigPath)
|
||||
|
||||
tsConfig = loadConfig(tsConfigPath)
|
||||
// In new Vue project, tsconfig has references to tsconfig.app.json, which is causing the path not resolving correctly
|
||||
// If no paths were found, try to load tsconfig.app.json.
|
||||
if ('paths' in tsConfig && Object.keys(tsConfig.paths).length === 0) {
|
||||
const FALLBACK_TSCONFIG_PATH = path.resolve(cwd, './tsconfig.app.json')
|
||||
if (existsSync(FALLBACK_TSCONFIG_PATH))
|
||||
tsConfig = loadConfig(FALLBACK_TSCONFIG_PATH)
|
||||
tsConfigPath = path.resolve(cwd, './tsconfig.app.json')
|
||||
if (existsSync(tsConfigPath))
|
||||
tsConfig = loadConfig(tsConfigPath)
|
||||
}
|
||||
}
|
||||
else {
|
||||
tsConfigPath = path.resolve(cwd, './jsconfig.json')
|
||||
tsConfig = loadConfig(tsConfigPath)
|
||||
}
|
||||
|
||||
if (tsConfig.resultType === 'failed') {
|
||||
throw new Error(
|
||||
`Failed to load tsconfig.json. ${tsConfig.message ?? ''}`.trim(),
|
||||
)
|
||||
}
|
||||
if (tsConfig.resultType === 'failed') {
|
||||
throw new Error(
|
||||
`Failed to load ${tsConfigPath}. ${tsConfig.message ?? ''}`.trim(),
|
||||
)
|
||||
}
|
||||
|
||||
return configSchema.parse({
|
||||
|
|
@ -92,8 +96,8 @@ export async function resolveConfigPaths(cwd: string, config: RawConfig) {
|
|||
resolvedPaths: {
|
||||
tailwindConfig: path.resolve(cwd, config.tailwind.config),
|
||||
tailwindCss: path.resolve(cwd, config.tailwind.css),
|
||||
utils: tsConfig ? await resolveImport(config.aliases.utils, tsConfig) : config.aliases.utils,
|
||||
components: tsConfig ? await resolveImport(config.aliases.components, tsConfig) : config.aliases.components,
|
||||
utils: await resolveImport(config.aliases.utils, tsConfig),
|
||||
components: await resolveImport(config.aliases.components, tsConfig),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import path from 'node:path'
|
||||
import process from 'node:process'
|
||||
import { HttpsProxyAgent } from 'https-proxy-agent'
|
||||
import fetch from 'node-fetch'
|
||||
import type * as z from 'zod'
|
||||
|
|
@ -129,7 +130,6 @@ export function getItemTargetPath(
|
|||
return null
|
||||
|
||||
return path.join(
|
||||
config.typescript ? '' : config.root,
|
||||
config.resolvedPaths[parent as keyof typeof config.resolvedPaths],
|
||||
type,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ interface File {
|
|||
|
||||
export async function transformSFC(file: File, config: Config) {
|
||||
let content = transformImport(file.content, config)
|
||||
if (config.typescript)
|
||||
if (!config.typescript)
|
||||
content = await transformByDetype(content, file.name)
|
||||
|
||||
return content
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user