use std::error::Error; use std::fmt; use command_runner::CommandRunner; use symbols::Symbol; pub struct NpmInstall<'a> { target: &'a str, command_runner: &'a CommandRunner } impl<'a> NpmInstall<'a> { pub fn new(target: &'a str, command_runner: &'a CommandRunner) -> NpmInstall<'a> { NpmInstall { target: target, command_runner: command_runner } } } impl<'a> fmt::Display for NpmInstall<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "npm install in {}", self.target) } } impl<'a> Symbol for NpmInstall<'a> { fn target_reached(&self) -> Result> { let result = try!(self.command_runner.run_with_args("sh", &["-c", &format!("cd '{}' && npm ls", self.target)])); Ok(result.status.success() && !String::from_utf8(result.stdout).unwrap().contains("(empty)")) } fn execute(&self) -> Result<(), Box> { try!(self.command_runner.run_with_args("sh", &["-c", &format!("cd '{}' && npm install --production", self.target)])); Ok(()) } } #[cfg(test)] mod test { }