Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/shadcn/src/registry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const registryItemFileSchema = z.discriminatedUnion("type", [
}),
])

export type RegistryItemFile = z.infer<typeof registryItemFileSchema>

export const registryItemTailwindSchema = z.object({
config: z
.object({
Expand Down
32 changes: 3 additions & 29 deletions packages/shadcn/src/registry/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "@/src/schema"
import { Config } from "@/src/utils/get-config"
import { ProjectInfo, getProjectInfo } from "@/src/utils/get-project-info"
import { createRegistryFile } from "@/src/utils/registry/create-registry-file"
import { determineFileType } from "@/src/utils/registry/determine-file-type"
import { resolveImport } from "@/src/utils/resolve-import"
import {
findCommonRoot,
Expand Down Expand Up @@ -106,11 +108,7 @@ export async function recursivelyResolveFileImports(

// Add the original file first
const fileType = determineFileType(filePath)
const originalFile = {
path: relativeRegistryFilePath,
type: fileType,
target: "",
}
const originalFile = createRegistryFile(relativeRegistryFilePath, fileType)
files.push(originalFile)

// 1. Find all import statements in the file.
Expand Down Expand Up @@ -227,30 +225,6 @@ async function createTempSourceFile(filename: string) {
return path.join(dir, filename)
}

// This is a bit tricky to accurately determine.
// For now we'll use the module specifier to determine the type.
function determineFileType(
moduleSpecifier: string
): z.infer<typeof registryItemSchema>["type"] {
if (moduleSpecifier.includes("/ui/")) {
return "registry:ui"
}

if (moduleSpecifier.includes("/lib/")) {
return "registry:lib"
}

if (moduleSpecifier.includes("/hooks/")) {
return "registry:hook"
}

if (moduleSpecifier.includes("/components/")) {
return "registry:component"
}

return "registry:component"
}

// Additional utility functions for local file support
export function isUrl(path: string) {
try {
Expand Down
16 changes: 16 additions & 0 deletions packages/shadcn/src/utils/registry/create-registry-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { RegistryItemFile } from "@/src/schema"

const createRegistryFile = (
filePath: string,
fileType: RegistryItemFile["type"],
target: string = ""
): RegistryItemFile => {
//
return {
path: filePath,
type: fileType,
target: target,
}
}

export { createRegistryFile }
25 changes: 25 additions & 0 deletions packages/shadcn/src/utils/registry/determine-file-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { RegistryItem } from "@/src/registry/schema"

// This is a bit tricky to accurately determine.
// For now we'll use the module specifier to determine the type.
const determineFileType = (moduleSpecifier: string): RegistryItem["type"] => {
if (moduleSpecifier.includes("/ui/")) {
return "registry:ui"
}

if (moduleSpecifier.includes("/lib/")) {
return "registry:lib"
}

if (moduleSpecifier.includes("/hooks/")) {
return "registry:hook"
}

if (moduleSpecifier.includes("/components/")) {
return "registry:component"
}

return "registry:component"
}

export { determineFileType }