MCPcopy
hub / github.com/intentui/intentui / collectBlocks

Function collectBlocks

src/scripts/generate-registry.ts:274–305  ·  view source on GitHub ↗
(pagePath: string, code: string)

Source from the content-addressed store, hash-verified

272const exampleSlugFromFile = (file: string) => stripExt(path.basename(file))
273
274const collectBlocks = async (pagePath: string, code: string) => {
275 const groupRoot = path.dirname(path.dirname(pagePath))
276 const isTsLike = (n: string) => /\.(tsx|ts)$/.test(n) && !n.endsWith('.d.ts')
277 const seen = new Set<string>()
278 const queue: string[] = [pagePath]
279 const rootEntries = await fs.readdir(groupRoot, { withFileTypes: true })
280 for (const e of rootEntries) {
281 if (e.isFile() && isTsLike(e.name)) {
282 const fp = path.join(groupRoot, e.name)
283 if (!seen.has(fp)) {
284 seen.add(fp)
285 queue.push(fp)
286 }
287 }
288 }
289 while (queue.length) {
290 const file = queue.pop()!
291 const src = file === pagePath ? code : await read(file)
292 const specs = importSpecifiers(src)
293 for (const s of specs) {
294 if (s.startsWith('./') || s.startsWith('../')) {
295 const p = await resolveLocalPath(file, s)
296 if (p && p.startsWith(groupRoot) && !seen.has(p)) {
297 seen.add(p)
298 queue.push(p)
299 }
300 }
301 }
302 }
303 seen.delete(pagePath)
304 return [...seen]
305}
306
307async function rewritePrivatesToRegistry(
308 fromFile: string,

Callers 2

registryDepsForBlockFunction · 0.85
buildBlockItemFunction · 0.85

Calls 4

isTsLikeFunction · 0.85
readFunction · 0.85
importSpecifiersFunction · 0.85
resolveLocalPathFunction · 0.85

Tested by

no test coverage detected