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