Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
select build target
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Dec 28, 2018
1 parent 95268cd commit 93384f5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 29 deletions.
58 changes: 44 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ structopt = "0.2"
tar = "0.4.16"
toml = "0.4"
which = "2.0.0"
walkdir = "2"
zip = "0.5.0"

[dev-dependencies]
Expand Down
21 changes: 11 additions & 10 deletions src/command/publish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod access;
use self::access::Access;
use command::build::{Build, BuildOptions};
use command::utils::{find_pkg_directory, set_crate_path};
use dialoguer::{Confirmation, Input};
use dialoguer::{Confirmation, Input, Select};
use failure::Error;
use npm;
use slog::Logger;
Expand All @@ -15,7 +15,7 @@ use PBAR;
/// Creates a tarball from a 'pkg' directory
/// and publishes it to the NPM registry
pub fn publish(
target: String,
_target: String,
path: Option<PathBuf>,
access: Option<Access>,
log: &Logger,
Expand All @@ -31,18 +31,19 @@ pub fn publish(
// while `wasm-pack publish`, if the pkg directory cannot be found,
// then try to `wasm-pack build`
if Confirmation::new()
.with_text("Your npm package hasn't be built, build it?")
.with_text("Your package hasn't been built, build it?")
.interact()?
{
let out_dir = Input::new()
.with_prompt("out_dir")
.default("pkg".to_string())
.show_default(true)
.with_prompt("out_dir[default: pkg]")
.default(".".to_string())
.show_default(false)
.interact()?;
let target = Input::new()
.with_prompt("target")
.default(target)
.show_default(true)
let out_dir = format!("{}/pkg", out_dir);
let target = Select::new()
.with_prompt("target[default: browser]")
.items(&["browser", "nodejs", "no-modules"])
.default(0)
.interact()?
.to_string();
let build_opts = BuildOptions {
Expand Down
10 changes: 5 additions & 5 deletions src/command/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use failure;
use progressbar::Step;
use std::fs;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;
use PBAR;

/// If an explicit path is given, then use it, otherwise assume the current
Expand All @@ -28,11 +29,10 @@ pub fn find_pkg_directory(path: &Path) -> Option<PathBuf> {
return Some(path.to_owned());
}

path.read_dir().ok().and_then(|entries| {
entries
.filter_map(|x| x.ok().map(|v| v.path()))
.find(|x| is_pkg_directory(&x))
})
WalkDir::new(path)
.into_iter()
.filter_map(|x| x.ok().map(|e| e.into_path()))
.find(|x| is_pkg_directory(&x))
}

fn is_pkg_directory(path: &Path) -> bool {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern crate slog_async;
extern crate slog_term;
extern crate tar;
extern crate toml;
extern crate walkdir;
extern crate which;
extern crate zip;

Expand Down

0 comments on commit 93384f5

Please sign in to comment.