dmc-core 0.2.0

Engine, CLI, watch mode, and collection builds for the dmc MDX compiler
Documentation
use std::path::PathBuf;

use dmc_diagnostic::Code;
use duck_diagnostic::DiagnosticEngine;

use crate::engine::compile::Compiler;

#[derive(clap::Args)]
pub struct CompileCmd {
  #[arg(long, default_value = "dmc.toml")]
  pub path: PathBuf,
}

impl CompileCmd {
  /// Read one mdx file, run the default pipeline, print `CompileOutput`
  /// as pretty JSON to stdout.
  pub fn run(self) -> std::io::Result<()> {
    let mut diag_engine = DiagnosticEngine::<Code>::new();

    let src = std::fs::read_to_string(&self.path)?;
    let out = Compiler::compile(&src, &mut diag_engine);
    let json = serde_json::to_string_pretty(&out).unwrap();
    println!("{}", json);
    Ok(())
  }
}