You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.0 KiB
41 lines
1.0 KiB
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<bool, Box<Error>> {
|
|
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<Error>> {
|
|
try!(self.command_runner.run_with_args("sh", &["-c", &format!("cd '{}' && npm install --production", self.target)]));
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
}
|