@keystatic/core

Search for an npm package
import path from 'node:path';
import fs from 'node:fs/promises';
import { c as collectionReader, s as singletonReader } from './generic-04895417.node.js';
import 'react/jsx-runtime';
import './index-360e5820.node.js';
import '@markdoc/markdoc/dist/index.mjs';
import 'emery/assertions';
import 'emery';
import './index-1a9da0fb.node.js';
import 'crypto';
import '@braintree/sanitize-url';
import 'js-yaml';
function createReader(repoPath, config) {
const fs$1 = {
async fileExists(path$1) {
try {
await fs.stat(path.join(repoPath, path$1));
return true;
} catch (err) {
if (err.code === 'ENOENT') return false;
throw err;
}
},
async readdir(path$1) {
try {
const entries = await fs.readdir(path.join(repoPath, path$1), {
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$1) {
try {
return await fs.readFile(path.join(repoPath, path$1));
} 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$1)])),
singletons: Object.fromEntries(Object.keys(config.singletons || {}).map(key => [key, singletonReader(key, config, fs$1)])),
repoPath,
config
};
}
export { createReader };