add default npm repo to codebase and always pass it as a param

master
Jan Willem Henckel 7 years ago
parent 1d982599de
commit 31c1d1d32a
  1. 6
      src/command.rs
  2. 15
      src/npm.rs

@ -152,9 +152,11 @@ fn login(
always_auth: bool,
auth_type: Option<String>,
) -> result::Result<(), Error> {
npm::npm_login(registry, scope, always_auth, auth_type)?;
let registry = registry.unwrap_or(npm::DEFAULT_NPM_REGISTRY.to_string());
PBAR.message("👋 logged you in!");
npm::npm_login(&registry, &scope, always_auth, &auth_type)?;
PBAR.message(&format!("👋 logged you in to {}!", registry));
Ok(())
}

@ -1,6 +1,8 @@
use error::Error;
use std::process::{Command, Stdio};
pub const DEFAULT_NPM_REGISTRY: &'static str = "https://registry.npmjs.org/";
pub fn npm_pack(path: &str) -> Result<(), Error> {
let pkg_file_path = format!("{}/pkg", path);
let output = Command::new("npm")
@ -30,16 +32,15 @@ pub fn npm_publish(path: &str) -> Result<(), Error> {
}
pub fn npm_login(
registry: Option<String>,
scope: Option<String>,
registry: &String,
scope: &Option<String>,
always_auth: bool,
auth_type: Option<String>,
auth_type: &Option<String>,
) -> Result<(), Error> {
let mut args = String::new();
if let Some(registry) = registry {
args.push_str(&format!(" --registry={}", registry));
}
args.push_str(&format!("--registry={}", registry));
if let Some(scope) = scope {
args.push_str(&format!(" --scope={}", scope));
}
@ -61,7 +62,7 @@ pub fn npm_login(
if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr);
Error::cli("Registry user account login failed", s)
Error::cli(&format!("Login to registry {} failed", registry), s)
} else {
Ok(())
}

Loading…
Cancel
Save