| import nodePath from 'node:path'; |
| import nodeFs from 'node:fs/promises'; |
| import { c as collectionReader, s as singletonReader } from './generic-0c4bb44f.worker.js'; |
| import 'react/jsx-runtime'; |
| import './index-382895ba.worker.js'; |
| import '@markdoc/markdoc/dist/index.mjs'; |
| import 'emery/assertions'; |
| import 'emery'; |
| import './index-08620d62.worker.js'; |
| import '@braintree/sanitize-url'; |
| import 'js-yaml'; |
|
|
| 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 }; |