A library for writing host-specific, single-binary configuration management and deployment tools
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

7 years ago
7 years ago
7 years ago
  1. use std::error::Error;
  2. use std::fmt;
  3. use command_runner::CommandRunner;
  4. use symbols::Symbol;
  5. pub struct NpmInstall<'a> {
  6. target: &'a str,
  7. command_runner: &'a CommandRunner
  8. }
  9. impl<'a> NpmInstall<'a> {
  10. pub fn new(target: &'a str, command_runner: &'a CommandRunner) -> NpmInstall<'a> {
  11. NpmInstall {
  12. target: target,
  13. command_runner: command_runner
  14. }
  15. }
  16. }
  17. impl<'a> fmt::Display for NpmInstall<'a> {
  18. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  19. write!(f, "npm install in {}", self.target)
  20. }
  21. }
  22. impl<'a> Symbol for NpmInstall<'a> {
  23. fn target_reached(&self) -> Result<bool, Box<Error>> {
  24. let result = try!(self.command_runner.run_with_args("sh", &["-c", &format!("cd '{}' && npm ls", self.target)]));
  25. Ok(result.status.success() && !String::from_utf8(result.stdout).unwrap().contains("(empty)"))
  26. }
  27. fn execute(&self) -> Result<(), Box<Error>> {
  28. try!(self.command_runner.run_with_args("sh", &["-c", &format!("cd '{}' && npm install --production", self.target)]));
  29. Ok(())
  30. }
  31. }
  32. #[cfg(test)]
  33. mod test {
  34. }