use error::Error; use std::process::Command; pub fn npm_pack(path: &str) -> Result<(), Error> { let pkg_file_path = format!("{}/pkg", path); let output = Command::new("npm") .current_dir(pkg_file_path) .arg("pack") .output()?; if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); Error::cli("Packaging up your code failed", s) } else { Ok(()) } } pub fn npm_publish(path: &str) -> Result<(), Error> { let pkg_file_path = format!("{}/pkg", path); let output = Command::new("npm") .current_dir(pkg_file_path) .arg("publish") .output()?; if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); Error::cli("Publishing to npm failed", s) } else { Ok(()) } } pub fn npm_login( registry: Option, scope: Option, always_auth: bool, auth_type: Option, ) -> Result<(), Error> { let mut args = String::new(); if let Some(registry) = registry { args.push_str(&format!(" --registry={}", registry)) } if let Some(scope) = scope { args.push_str(&format!(" --scope={}", scope)) } if always_auth == true { args.push_str(" --always_auth") } if let Some(auth_type) = auth_type { args.push_str(&format!(" --auth_type={}", auth_type)) } let status = Command::new("npm").arg("login").arg(args).status()?; if !status.success() { bail!("Registry user account login failed"); } else { Ok(()) } }