feat: optional --check delegates type-check to detected runtime
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
3 files changed
+51
-3
No files matched your search
@@ -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<bool> {
|
||||||
|
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"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
-3
@@ -19,16 +19,16 @@ fn controller_stub(name: &str) -> String {
|
|||||||
lower = name.to_lowercase(), name = name)
|
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 {
|
match kind {
|
||||||
"controller" => create_controller(name),
|
"controller" => create_controller(name, check),
|
||||||
"module" | "step" => Err(Error::new(ErrorKind::Unsupported,
|
"module" | "step" => Err(Error::new(ErrorKind::Unsupported,
|
||||||
format!("create {kind} not implemented yet"))),
|
format!("create {kind} not implemented yet"))),
|
||||||
other => Err(Error::new(ErrorKind::InvalidInput, format!("unknown kind {other}"))),
|
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")
|
let file = Path::new("src/controllers")
|
||||||
.join(format!("{}.controller.ts", name.to_lowercase()));
|
.join(format!("{}.controller.ts", name.to_lowercase()));
|
||||||
std::fs::create_dir_all(file.parent().unwrap())?;
|
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");
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
mod check;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod cmd_create;
|
mod cmd_create;
|
||||||
mod cmd_new;
|
mod cmd_new;
|
||||||
|
|||||||
Reference in new issue
Block a user