| import nodePath from 'node:path'; |
| import nodeFs from 'node:fs/promises'; |
| import { c as collectionReader, s as singletonReader } from './generic-db09966b.react-server.js'; |
| import 'react/jsx-runtime'; |
| import './index-49bb61a8.react-server.js'; |
| import '@markdoc/markdoc/dist/index.mjs'; |
| import 'emery/assertions'; |
| import 'emery'; |
| import './index-e8fd44a1.react-server.js'; |
| import '@braintree/sanitize-url'; |
| import 'js-yaml'; |
| import 'react'; |
|
|
| function createReader(repoPath, config) { |
| const fs = { |
| async fileExists(path) { |
| try { |
| await nodeFs.stat(nodePath.join(repoPath, path)); |
| return true; |
| } catch (err) { |
| if (err.code === 'ENOENT') return false; |
| throw err; |
| } |
| }, |
| async readdir(path) { |
| try { |
| const entries = await nodeFs.readdir(nodePath.join(repoPath, path), { |
| withFileTypes: true |
| }); |
| const filtered = []; |
| for (const entry of entries) { |
| if (entry.isDirectory()) { |
| filtered.push({ |
| name: entry.name, |
| kind: 'directory' |
| }); |
| } |
| if (entry.isFile()) { |
| filtered.push({ |
| name: entry.name, |
| kind: 'file' |
| }); |
| } |
| } |
| return filtered; |
| } catch (err) { |
| if (err.code === 'ENOENT') return []; |
| throw err; |
| } |
| }, |
| async readFile(path) { |
| try { |
| return await nodeFs.readFile(nodePath.join(repoPath, path)); |
| } catch (err) { |
| if (err.code === 'ENOENT') return null; |
| throw err; |
| } |
| } |
| }; |
| return { |
| collections: Object.fromEntries(Object.keys(config.collections || {}).map(key => [key, collectionReader(key, config, fs)])), |
| singletons: Object.fromEntries(Object.keys(config.singletons || {}).map(key => [key, singletonReader(key, config, fs)])), |
| repoPath, |
| config |
| }; |
| } |
|
|
| export { createReader }; |