rsconstruct 0.9.78

Rust based fast build system
//! mermaid generator — registered as a `SimpleGenerator` with a custom execute fn.

use std::process::Command;
use anyhow::Result;

use crate::config::StandardConfig;
use crate::graph::Product;
use crate::processors::{run_command, check_command_output, ensure_output_dir};

use crate::processors::{SimpleGenerator, SimpleGeneratorParams, DiscoverMode};

fn execute_mermaid(ctx: &crate::build_context::BuildContext, config: &StandardConfig, product: &Product) -> Result<()> {
    let input = product.primary_input();
    let output = product.primary_output();
    ensure_output_dir(output)?;
    let command = config.require_command("mermaid")?;
    let mut cmd = Command::new(command);
    cmd.arg("-i").arg(input);
    cmd.arg("-o").arg(output);
    for arg in &config.args { cmd.arg(arg); }
    let out = run_command(ctx, &cmd)?;
    check_command_output(&out, format_args!("mmdc {}", input.display()))
}


fn create_mermaid(toml: &toml::Value) -> anyhow::Result<Box<dyn crate::processors::Processor>> {
    crate::registries::deserialize_and_create(toml, |cfg| Box::new(SimpleGenerator::new(cfg, SimpleGeneratorParams { extra_tools: &["node"], extra_tools_fn: None, discover_mode: DiscoverMode::MultiFormat, execute_fn: execute_mermaid, is_native: false })))
}
inventory::submit! { crate::registries::ProcessorPlugin {
    version: 1,
    name: "mermaid", processor_type: crate::processors::ProcessorType::Generator, create: create_mermaid,
    fields: &[],
    omit_standard_fields: &[],
    scan_defaults: Some(crate::config::ScanDefaultsData { src_dirs: &[], src_extensions: &[".mmd"], src_exclude_dirs: &[] }),
    defaults: Some(crate::config::ProcessorDefaults { output_dir: "out/mermaid", formats: &["png"], command: "mmdc", ..crate::config::ProcessorDefaults::EMPTY }),
    defconfig_json: crate::registries::default_config_json::<crate::config::StandardConfig>,
    keywords: &["diagram", "mermaid", "svg", "png", "generator", "node", "npm"],
    description: "Render Mermaid diagrams to images",
    is_native: false,
    can_fix: false,
    supports_batch: false,
    max_jobs_cap: None,
} }