From 1cc6f35b90e9080b7fdfb9df6450512de62aa4d3 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Sat, 11 Jul 2026 13:09:08 -0500 Subject: [PATCH] feat: matcha run detects runtime and spawns watch Signed-off-by: Diego Resendez --- src/cmd_run.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 8 +++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/cmd_run.rs diff --git a/src/cmd_run.rs b/src/cmd_run.rs new file mode 100644 index 0000000..35b3686 --- /dev/null +++ b/src/cmd_run.rs @@ -0,0 +1,42 @@ +use std::io::{Error, ErrorKind}; +use std::path::Path; + +use crate::runtime::{self, Runtime}; + +fn command_for(rt: Runtime) -> (&'static str, Vec<&'static str>) { + match rt { + Runtime::Deno => ("deno", vec!["task", "dev"]), + Runtime::Bun => ("bun", vec!["--watch", "run", "dev"]), + Runtime::Node => ("npm", vec!["run", "dev"]), + } +} + +pub fn run(dir: &Path) -> std::io::Result<()> { + let rt = runtime::detect(dir).ok_or_else(|| Error::new( + ErrorKind::NotFound, + "no runtime detected (need deno.json, bun.lock, or package.json)", + ))?; + let (prog, args) = command_for(rt); + println!("→ {prog} {}", args.join(" ")); + let status = std::process::Command::new(prog).args(&args).current_dir(dir).status()?; + std::process::exit(status.code().unwrap_or(1)); +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::runtime::Runtime; + + #[test] + fn deno_uses_task_dev() { + assert_eq!(command_for(Runtime::Deno), ("deno", vec!["task", "dev"])); + } + #[test] + fn bun_watch() { + assert_eq!(command_for(Runtime::Bun), ("bun", vec!["--watch", "run", "dev"])); + } + #[test] + fn node_watch() { + assert_eq!(command_for(Runtime::Node), ("npm", vec!["run", "dev"])); + } +} diff --git a/src/main.rs b/src/main.rs index 943cca4..b08d5eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ mod cli; mod cmd_new; +mod cmd_run; mod runtime; mod template; @@ -15,7 +16,12 @@ fn main() { std::process::exit(1); } } - Command::Run => eprintln!("run: not yet implemented"), + Command::Run => { + if let Err(e) = cmd_run::run(std::path::Path::new(".")) { + eprintln!("error: {e}"); + std::process::exit(1); + } + } Command::Create { .. } => eprintln!("create: not yet implemented"), Command::Add { .. } => eprintln!("add: not yet implemented"), }