UNPKG

markdown-code

Version:

Keep code examples in Markdown synchronized with actual source files

51 lines (49 loc) 1.28 kB
import { format, hasErrors, hasIssues } from "./chunk-6OD27PGB.js"; import { syncMarkdownFiles } from "./chunk-IHXCU4UX.js"; import "./chunk-3RW5RA4J.js"; import { getValidatedConfig, handleError, logWarningsAndErrors } from "./chunk-WJFWHUDV.js"; // src/commands/sync.ts import { relative } from "path"; var command = ["sync", "$0"]; var describe = "Update markdown files with snippet content (default)"; var handler = async (argv) => { try { const config = await getValidatedConfig(argv); console.log("Syncing markdown files..."); const result = await syncMarkdownFiles(config); logWarningsAndErrors(result.warnings, result.errors); if (hasIssues(result.fileIssues)) { const formattedOutput = format(result.fileIssues); console.error(formattedOutput); if (hasErrors(result.fileIssues)) { process.exit(1); } } if (result.updated.length > 0) { console.log("Updated files:"); result.updated.forEach((file) => { const relativePath = relative(config.workingDir, file); console.log(` ${relativePath}`); }); } else { console.log("All files are already in sync."); } } catch (error) { handleError(error); } }; export { command, describe, handler };