fork of https://github.com/rustwasm/wasm-pack for the needs of NextGraph.org
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.
 
 
wasm-pack/src/npm.rs

62 lines
1.6 KiB

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<String>,
scope: Option<String>,
always_auth: bool,
auth_type: Option<String>,
) -> 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(())
}
}