MCPcopy Create free account
hub / github.com/vercel/examples / walk

Function walk

python/vibe-coding-ide/frontend/scripts/build-templates.js:150–175  ·  view source on GitHub ↗
(currentDir)

Source from the content-addressed store, hash-verified

148 const files = {}
149
150 function walk(currentDir) {
151 const entries = fs.readdirSync(currentDir, { withFileTypes: true })
152
153 for (const entry of entries) {
154 const fullPath = path.join(currentDir, entry.name)
155 const relativePath = path.relative(baseDir, fullPath).replace(/\\/g, '/')
156
157 if (entry.isDirectory()) {
158 walk(fullPath)
159 } else if (entry.isFile()) {
160 // Skip metadata file if present
161 if (entry.name === 'index.ts') continue
162
163 if (isBinaryImage(entry.name)) {
164 // For binary images, store as base64 data URL
165 const buffer = fs.readFileSync(fullPath)
166 const base64 = buffer.toString('base64')
167 const ext = path.extname(entry.name).slice(1)
168 files[relativePath] = `data:image/${ext};base64,${base64}`
169 } else {
170 // For text files, store as raw string
171 files[relativePath] = fs.readFileSync(fullPath, 'utf-8')
172 }
173 }
174 }
175 }
176
177 walk(dir)
178 return files

Callers 1

readDirRecursiveFunction · 0.85

Calls 2

isBinaryImageFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected