UNPKG

mdxlayer

Version:

Transform your MDX content into typed, JSON-powered data with flexible schema validation.

26 lines (23 loc) 584 B
import fs from 'node:fs'; import path from 'node:path'; import { cliOutDir } from './args.js'; const transformFile = ({ doc, subpath, filename }) => { const outputPath = path.resolve( process.cwd(), `${cliOutDir}/${subpath}`, filename ); const content = typeof doc === "string" ? doc : JSON.stringify(doc, null, 2); try { fs.mkdirSync(path.dirname(outputPath), { recursive: true }); fs.writeFileSync(outputPath, content); } catch (error) { console.error(`Error writing ${filename}:`, error); throw error; } }; export { transformFile };