1use std::path::PathBuf;
2
3#[derive(clap::Args)]
4pub struct InitCmd {
5 #[arg(long, default_value = "dmc.toml")]
6 pub path: PathBuf,
7}
8
9impl InitCmd {
10 pub fn run(self) -> std::io::Result<()> {
12 if self.path.exists() {
13 eprintln!("refusing to overwrite existing {}", self.path.display());
14 std::process::exit(2);
15 }
16 std::fs::write(&self.path, DEFAULT_CONFIG)?;
17 println!("wrote {}", self.path.display());
18 Ok(())
19 }
20}
21
22const DEFAULT_CONFIG: &str = r#"# dmc.toml - Rust MDX compiler config.
23# Every option below is commented at its default; uncomment + change to override.
24
25# --- Engine ---------------------------------------------------------------
26# Project root used to resolve relative paths in collection patterns.
27# root = "."
28
29# Where compiled JSON indexes are written. One file per collection: <output_dir>/<name>.json
30output_dir = ".dmc"
31
32# Optional: name + format of the aggregated index file (when multiple collections).
33# output_name = "index"
34# output_format = "esm" # "esm" | "json"
35
36# Wipe output_dir before each build (also enabled by `--clean` flag).
37# clean = false
38
39# Abort on the first frontmatter validation failure (also enabled by `--strict` flag).
40# strict = false
41
42# Include rendered HTML in the per-record output (alongside `body`/`content`).
43# Sidecar always emits HTML when JS plugins are configured; this is for the
44# native render path.
45# include_html = false
46
47# --- Compile (markdown / mdx) ---------------------------------------------
48# GitHub-Flavored Markdown extensions: tables, strikethrough, autolinks, task lists.
49# markdown_gfm = true
50
51# Native HTML emit on (auto-disabled for files that go through the sidecar).
52# emit_html = true
53
54# Native MDX body emit on.
55# emit_body = true
56
57# Run a JS minifier on the emitted MDX body (requires sidecar).
58# mdx_minify = false
59
60# MDX output format: "module" wraps body as an ES module with the imports
61# rolled in; "function-body" returns just the function body string.
62# mdx_output_format = "function-body"
63
64# --- JS plugin pipelines (run via the Node sidecar) -----------------------
65# Each entry is either "package-name" or ["package-name", { ...options }].
66# Plugins resolve from the project's node_modules first, then sidecar's.
67#
68# Example:
69# markdown_remark_plugins = [
70# "remark-gfm",
71# ["remark-toc", { tight = true }],
72# ]
73# markdown_rehype_plugins = [
74# ["rehype-pretty-code", { theme = "github-dark" }],
75# ]
76#
77# markdown_remark_plugins = []
78# markdown_rehype_plugins = []
79# mdx_remark_plugins = []
80# mdx_rehype_plugins = []
81
82# --- Asset handling -------------------------------------------------------
83# Copy files referenced by relative `` / `<a href="...">` into the
84# output bundle. Requires both `output_assets` and `output_base` set.
85# copy_linked_files = false
86# output_assets = "static"
87# output_base = "/"
88
89# --- Sidecar tuning (env-only, listed for reference) ----------------------
90# DMC_SIDECAR_POOL_SIZE -> number of long-lived `node` processes (default min(cores, 4))
91# dmc_SIDECAR -> override path to dmc-sidecar/index.mjs
92
93# --- Collections ----------------------------------------------------------
94# Each collection globs files under `base_dir` matching `pattern`, compiles
95# them, validates frontmatter against `schema` (optional), and writes
96# `<output_dir>/<name>.json`. The schema doubles as a TypeScript source --
97# `index.d.ts` ships a typed interface derived from it.
98[[collections]]
99name = "docs"
100pattern = "docs/**/*.{md,mdx}"
101base_dir = "."
102# single = false # if true, expect exactly one match; emit a single object instead of an array
103
104# Frontmatter schema. dmc-schema descriptor (each node has `kind`):
105# string | number | boolean | array (with `item`) | object (with `fields`,
106# optional `passthrough`) | enum (with `variants`) | literal | union |
107# nullable | optional | default | record | tuple | intersection |
108# discriminatedUnion | isodate | path | slug | unique | file | image |
109# markdown | mdx | raw | toc | metadata | excerpt | coerce.{string,number,boolean,date}
110# Wrap a field in `{ kind = "optional", inner = { ... } }` to make it optional.
111schema = { kind = "object", fields = { title = { kind = "string" }, description = { kind = "optional", inner = { kind = "string" } }, date = { kind = "optional", inner = { kind = "isodate" } }, draft = { kind = "optional", inner = { kind = "boolean" } }, tags = { kind = "optional", inner = { kind = "array", item = { kind = "string" } } }, author = { kind = "optional", inner = { kind = "object", fields = { name = { kind = "string" }, url = { kind = "optional", inner = { kind = "string" } } } } } } }
112"#;