Something went wrong. Try again.
CLI tool to sync your Markdown to Leaflet
leafletpub atproto cli markdown
Something went wrong. Try again.
1.1 kB · 40 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041import { readFile, access } from "node:fs/promises";import { createJiti } from "jiti";import { join } from "node:path";import type { Config } from "./config";import { isBun } from "std-env";
export const jiti = createJiti(import.meta.url);
export async function exists(path: string | URL) { try { await access(path); return true; } catch { return false; }}
export async function readJson(path: string | URL) { if (isBun) return await Bun.file(path).json();
return JSON.parse((await readFile(path)).toString());}
export async function loadConfig() { const extensions = [".js", ".ts", ".mjs", ".mts", ".json"];
let selectedExt: string | undefined = undefined; for (const ext of extensions) { if (await exists(join(process.cwd(), `/leaflet-md.config${ext}`))) { selectedExt = ext; break; } }
if (!selectedExt) return undefined;
const configPath = join(process.cwd(), `/leaflet-md.config${selectedExt}`); const config = (await jiti.import(configPath, { default: true })) as Config; return config;}