feat: custom ui dir
This commit is contained in:
parent
fb70bb3c89
commit
d827ec86b2
|
|
@ -42,6 +42,9 @@
|
|||
},
|
||||
"components": {
|
||||
"type": "string"
|
||||
},
|
||||
"ui": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["utils", "components"]
|
||||
|
|
|
|||
|
|
@ -113,7 +113,6 @@ export const add = new Command()
|
|||
}
|
||||
|
||||
const spinner = ora('Installing components...').start()
|
||||
const skippedDeps = new Set<string>()
|
||||
for (const item of payload) {
|
||||
spinner.text = `Installing ${item.name}...`
|
||||
const targetDir = getItemTargetPath(
|
||||
|
|
@ -185,10 +184,6 @@ export const add = new Command()
|
|||
|
||||
// Install dependencies.
|
||||
if (item.dependencies?.length) {
|
||||
item.dependencies.forEach(dep =>
|
||||
skippedDeps.add(dep),
|
||||
)
|
||||
|
||||
await addDependency(item.dependencies, {
|
||||
cwd,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import template from 'lodash.template'
|
|||
import ora from 'ora'
|
||||
import prompts from 'prompts'
|
||||
import * as z from 'zod'
|
||||
import { addDependency, addDevDependency } from 'nypm'
|
||||
import { addDependency, addDevDependency, ensureDependencyInstalled } from 'nypm'
|
||||
import * as templates from '../utils/templates'
|
||||
import {
|
||||
getRegistryBaseColor,
|
||||
|
|
@ -280,15 +280,22 @@ export async function runInit(cwd: string, config: Config) {
|
|||
config.style === 'new-york' ? ['@radix-icons/vue'] : ['lucide-vue-next'],
|
||||
).filter(Boolean)
|
||||
|
||||
await Promise.all(
|
||||
[
|
||||
async () => {
|
||||
if (config.framework === 'nuxt') {
|
||||
await addDevDependency(PROJECT_DEPENDENCIES.nuxt, {
|
||||
cwd,
|
||||
})
|
||||
}
|
||||
|
||||
await addDependency(deps, {
|
||||
},
|
||||
Promise.all(deps.map((d) => {
|
||||
return ensureDependencyInstalled(d, {
|
||||
cwd,
|
||||
})
|
||||
})),
|
||||
],
|
||||
)
|
||||
|
||||
dependenciesSpinner?.succeed()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ export const rawConfigSchema = z
|
|||
aliases: z.object({
|
||||
components: z.string(),
|
||||
utils: z.string(),
|
||||
ui: z.string(),
|
||||
}),
|
||||
})
|
||||
.strict()
|
||||
|
|
@ -53,6 +54,7 @@ export const configSchema = rawConfigSchema
|
|||
tailwindCss: z.string(),
|
||||
utils: z.string(),
|
||||
components: z.string(),
|
||||
ui: z.string(),
|
||||
}),
|
||||
})
|
||||
|
||||
|
|
@ -103,6 +105,9 @@ export async function resolveConfigPaths(cwd: string, config: RawConfig) {
|
|||
tailwindCss: path.resolve(cwd, config.tailwind.css),
|
||||
utils: resolveImport(config.aliases.utils, tsConfig),
|
||||
components: resolveImport(config.aliases.components, tsConfig),
|
||||
ui: config.aliases['ui']
|
||||
? await resolveImport(config.aliases['ui'], tsConfig)
|
||||
: await resolveImport(config.aliases['components'], tsConfig),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,9 +122,12 @@ export function getItemTargetPath(
|
|||
override?: string,
|
||||
) {
|
||||
// Allow overrides for all items but ui.
|
||||
if (override && item.type !== 'components:ui')
|
||||
if (override)
|
||||
return override
|
||||
|
||||
if (item.type === 'components:ui' && config.aliases.ui)
|
||||
return config.resolvedPaths.ui
|
||||
|
||||
const [parent, type] = item.type.split(':')
|
||||
if (!(parent in config.resolvedPaths))
|
||||
return null
|
||||
|
|
|
|||
|
|
@ -8,6 +8,12 @@ export const transformImport: Transformer = async ({ sourceFile, config }) => {
|
|||
|
||||
// Replace @/lib/registry/[style] with the components alias.
|
||||
if (moduleSpecifier.startsWith('@/lib/registry/')) {
|
||||
if (config.aliases.ui) {
|
||||
importDeclaration.setModuleSpecifier(
|
||||
moduleSpecifier.replace(/^@\/lib\/registry\/[^/]+\/ui/, config.aliases.ui),
|
||||
)
|
||||
}
|
||||
else {
|
||||
importDeclaration.setModuleSpecifier(
|
||||
moduleSpecifier.replace(
|
||||
/^@\/lib\/registry\/[^/]+/,
|
||||
|
|
@ -15,6 +21,7 @@ export const transformImport: Transformer = async ({ sourceFile, config }) => {
|
|||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Replace `import { cn } from "@/lib/utils"`
|
||||
if (moduleSpecifier === '@/lib/utils') {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user