Skip to content

Commit

Permalink
ok, this should be good
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleygwilliams committed Sep 14, 2018
1 parent 8b5c5b5 commit 61080b7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod build;
mod login;
mod pack;
/// Data structures and functions for publishing a package.
pub mod publish;
pub mod utils;

Expand Down
11 changes: 3 additions & 8 deletions src/command/publish/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use error::Error;
use std::fmt;
use std::str::FromStr;

/// Represents access level for the to-be publish package. Passed to `wasm-pack publish` as a flag, e.g. `--access=public`.
#[derive(Debug)]
pub enum Access {
/// Access is granted to all. All unscoped packages *must* be public.
Public,
/// Access is restricted, granted via npm permissions. Must be a scoped package.
Restricted,
Default,
}

impl FromStr for Access {
Expand All @@ -27,14 +29,7 @@ impl fmt::Display for Access {
let printable = match *self {
Access::Public => "--access=public",
Access::Restricted => "--access=restricted",
Access::Default => "",
};
write!(f, "{}", printable)
}
}

impl Default for Access {
fn default() -> Access {
Access::Default
}
}
1 change: 1 addition & 0 deletions src/command/publish/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Data structure to represent published package access level.
pub mod access;

use self::access::Access;
Expand Down
26 changes: 19 additions & 7 deletions src/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@ pub fn npm_pack(path: &str) -> Result<(), Error> {

/// Run the `npm publish` command.
pub fn npm_publish(path: &str, access: Option<Access>) -> Result<(), Error> {
let output = Command::new("npm")
.current_dir(path)
.arg("publish")
.arg(&format!("{}", access.unwrap_or_default().to_string()))
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.output()?;
let output = match access {
Some(a) => {
Command::new("npm")
.current_dir(path)
.arg("publish")
.arg(&format!("{}", a.to_string()))
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.output()?
},
None => {
Command::new("npm")
.current_dir(path)
.arg("publish")
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.output()?
},
};

if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr);
Expand Down

0 comments on commit 61080b7

Please sign in to comment.