Skip to content

Commit 97c8015

Browse files
committed
refactor(registry/utils): replace inline original file creation with createRegistryFile utility
- improve modularity and upcoming reusability - added Type alias `RegistryItemFile` of `registryItemFileSchema`
1 parent 8c25682 commit 97c8015

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

packages/shadcn/src/registry/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export const registryItemFileSchema = z.discriminatedUnion("type", [
3636
}),
3737
])
3838

39+
export type RegistryItemFile = z.infer<typeof registryItemFileSchema>
40+
3941
export const registryItemTailwindSchema = z.object({
4042
config: z
4143
.object({

packages/shadcn/src/registry/utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "@/src/schema"
99
import { Config } from "@/src/utils/get-config"
1010
import { ProjectInfo, getProjectInfo } from "@/src/utils/get-project-info"
11+
import { createRegistryFile } from "@/src/utils/registry/create-registry-file"
1112
import { determineFileType } from "@/src/utils/registry/determine-file-type"
1213
import { resolveImport } from "@/src/utils/resolve-import"
1314
import {
@@ -107,11 +108,7 @@ export async function recursivelyResolveFileImports(
107108

108109
// Add the original file first
109110
const fileType = determineFileType(filePath)
110-
const originalFile = {
111-
path: relativeRegistryFilePath,
112-
type: fileType,
113-
target: "",
114-
}
111+
const originalFile = createRegistryFile(relativeRegistryFilePath, fileType)
115112
files.push(originalFile)
116113

117114
// 1. Find all import statements in the file.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { RegistryItemFile } from "@/src/schema"
2+
3+
const createRegistryFile = (
4+
filePath: string,
5+
fileType: RegistryItemFile["type"],
6+
target: string = ""
7+
): RegistryItemFile => {
8+
//
9+
return {
10+
path: filePath,
11+
type: fileType,
12+
target: target,
13+
}
14+
}
15+
16+
export { createRegistryFile }

0 commit comments

Comments
 (0)