MCPcopy Create free account
hub / github.com/TanStack/cli / syncDirectory

Method syncDirectory

packages/cli/src/file-syncer.ts:64–155  ·  view source on GitHub ↗
(
    currentPath: string,
    targetBase: string,
    sourceBase: string,
    result: SyncResult,
  )

Source from the content-addressed store, hash-verified

62 }
63
64 private async syncDirectory(
65 currentPath: string,
66 targetBase: string,
67 sourceBase: string,
68 result: SyncResult,
69 ): Promise<void> {
70 const entries = await fs.promises.readdir(currentPath, {
71 withFileTypes: true,
72 })
73
74 for (const entry of entries) {
75 const sourcePath = path.join(currentPath, entry.name)
76 const relativePath = path.relative(sourceBase, sourcePath)
77 const targetPath = path.join(targetBase, relativePath)
78
79 // Skip certain directories
80 if (entry.isDirectory()) {
81 if (this.shouldSkipDirectory(entry.name)) {
82 continue
83 }
84
85 // Ensure target directory exists
86 if (!fs.existsSync(targetPath)) {
87 await fs.promises.mkdir(targetPath, { recursive: true })
88 }
89
90 // Recursively sync subdirectory
91 await this.syncDirectory(sourcePath, targetBase, sourceBase, result)
92 } else if (entry.isFile()) {
93 // Skip certain files
94 if (this.shouldSkipFile(entry.name)) {
95 continue
96 }
97
98 result.sourceFiles.push(relativePath)
99
100 try {
101 const shouldUpdate = await this.shouldUpdateFile(
102 sourcePath,
103 targetPath,
104 )
105
106 if (shouldUpdate) {
107 // Check if file exists to generate diff
108 let fileDiff: string | undefined
109 const targetExists = fs.existsSync(targetPath)
110
111 if (targetExists) {
112 // Generate diff for existing files
113 const oldContent = await fs.promises.readFile(targetPath, 'utf-8')
114 const newContent = await fs.promises.readFile(sourcePath, 'utf-8')
115
116 const changes = diff.createPatch(
117 relativePath,
118 oldContent,
119 newContent,
120 'Previous',
121 'Current',

Callers 1

syncMethod · 0.95

Calls 3

shouldSkipDirectoryMethod · 0.95
shouldSkipFileMethod · 0.95
shouldUpdateFileMethod · 0.95

Tested by

no test coverage detected