From e99dd58c669f1891e6dce936dad30961ba1c3e10 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Sat, 11 Jul 2026 13:28:40 -0500 Subject: [PATCH] feat: optional --check delegates type-check to detected runtime Signed-off-by: Diego Resendez --- src/check.rs | 38 ++++++++++++++++++++++++++++++++++++++ src/cmd_create.rs | 15 ++++++++++++--- src/main.rs | 1 + 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/check.rs diff --git a/src/check.rs b/src/check.rs new file mode 100644 index 0000000..6327efc --- /dev/null +++ b/src/check.rs @@ -0,0 +1,38 @@ +use std::path::Path; +use crate::runtime::{self, Runtime}; + +fn check_command(rt: Runtime) -> (&'static str, Vec<&'static str>) { + match rt { + Runtime::Deno => ("deno", vec!["check", "src/app.module.ts"]), + Runtime::Bun => ("bunx", vec!["tsc", "--noEmit"]), + Runtime::Node => ("npx", vec!["tsc", "--noEmit"]), + } +} + +pub fn run(dir: &Path) -> std::io::Result { + let Some(rt) = runtime::detect(dir) else { return Ok(true) }; // nothing to check against + let (prog, args) = check_command(rt); + let status = std::process::Command::new(prog).args(&args).current_dir(dir).status()?; + Ok(status.success()) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::runtime::Runtime; + + #[test] + fn deno_check_cmd() { + assert_eq!(check_command(Runtime::Deno), ("deno", vec!["check", "src/app.module.ts"])); + } + + #[test] + fn node_uses_tsc_noemit() { + assert_eq!(check_command(Runtime::Node), ("npx", vec!["tsc", "--noEmit"])); + } + + #[test] + fn bun_uses_bunx_tsc_noemit() { + assert_eq!(check_command(Runtime::Bun), ("bunx", vec!["tsc", "--noEmit"])); + } +} diff --git a/src/cmd_create.rs b/src/cmd_create.rs index 5bece6a..ada2ac4 100644 --- a/src/cmd_create.rs +++ b/src/cmd_create.rs @@ -19,16 +19,16 @@ fn controller_stub(name: &str) -> String { lower = name.to_lowercase(), name = name) } -pub fn run(kind: &str, name: &str, _check: bool) -> std::io::Result<()> { +pub fn run(kind: &str, name: &str, check: bool) -> std::io::Result<()> { match kind { - "controller" => create_controller(name), + "controller" => create_controller(name, check), "module" | "step" => Err(Error::new(ErrorKind::Unsupported, format!("create {kind} not implemented yet"))), other => Err(Error::new(ErrorKind::InvalidInput, format!("unknown kind {other}"))), } } -fn create_controller(name: &str) -> std::io::Result<()> { +fn create_controller(name: &str, check: bool) -> std::io::Result<()> { let file = Path::new("src/controllers") .join(format!("{}.controller.ts", name.to_lowercase())); std::fs::create_dir_all(file.parent().unwrap())?; @@ -54,5 +54,14 @@ fn create_controller(name: &str) -> std::io::Result<()> { println!("→ could not auto-wire; add {symbol} to controllers[] in src/app.module.ts"); } } + + if check { + match crate::check::run(Path::new(".")) { + Ok(true) => println!("✓ type-check passed"), + Ok(false) => println!("⚠ type-check reported errors"), + Err(e) => println!("⚠ could not run type-check: {e}"), + } + } + Ok(()) } diff --git a/src/main.rs b/src/main.rs index 808e1e7..8a665f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod check; mod cli; mod cmd_create; mod cmd_new;