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.

42 lines
1.1 KiB

7 years ago
  1. use std::fmt;
  2. use std::io;
  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. type Error = io::Error;
  24. fn target_reached(&self) -> Result<bool, Self::Error> {
  25. let result = try!(self.command_runner.run_with_args("sh", &["-c", &format!("cd '{}' && npm ls", self.target)]));
  26. Ok(result.status.success() && !String::from_utf8(result.stdout).unwrap().contains("(empty)"))
  27. }
  28. fn execute(&self) -> Result<(), Self::Error> {
  29. try!(self.command_runner.run_with_args("sh", &["-c", &format!("cd '{}' && npm install --production", self.target)]));
  30. Ok(())
  31. }
  32. }
  33. #[cfg(test)]
  34. mod test {
  35. }