use std::path::Path;
use aion_package::{CodegenMode, codegen_project};
use anyhow::{Context, Result};
use serde::Serialize;
use serde_json::Value;
use crate::output::to_value;
#[derive(Serialize)]
struct CodegenOutput {
module: String,
schemas: Vec<String>,
action: &'static str,
}
pub(crate) fn run(path: &Path, check: bool) -> Result<Value> {
let mode = if check {
CodegenMode::Check
} else {
CodegenMode::Write
};
let report = codegen_project(path, mode).with_context(|| {
format!(
"failed to generate Gleam codecs for workflow project at {}",
path.display()
)
})?;
to_value(CodegenOutput {
module: report.module_relative,
schemas: report.schemas,
action: if check { "checked" } else { "written" },
})
}