Search for path in entered directory and the parent of entered

This lets us have backwards compatibility while improving the user experience.
master
Mackiovello 7 years ago
parent 8efabfa3af
commit b57d68f97a
  1. 34
      src/command/publish.rs
  2. 3
      src/npm.rs

@ -2,6 +2,7 @@ use command::utils::set_crate_path;
use error::Error;
use npm;
use slog::Logger;
use std::path::Path;
use std::result;
use PBAR;
@ -10,16 +11,35 @@ pub fn publish(path: Option<String>, log: &Logger) -> result::Result<(), Error>
info!(&log, "Publishing the npm package...");
info!(&log, "npm info located in the npm debug log");
npm::npm_publish(&crate_path).map_err(|e| {
match e {
Error::Io { .. } => Error::PkgNotFound {
message: format!("Unable to find the pkg directory at path '{}', set the path as the parent directory of the pkg directory", &crate_path),
},
e => e,
}
let pkg_directory: Box<&Path> = find_pkg_directory(&crate_path).ok_or(Error::PkgNotFound {
message: format!(
"Unable to find the pkg directory at path '{}', or in a child directory of '{}'",
&crate_path, &crate_path
),
})?;
npm::npm_publish(&pkg_directory.to_string_lossy())?;
info!(&log, "Published your package!");
PBAR.message("💥 published your package!");
Ok(())
}
fn find_pkg_directory(guess_path: &str) -> Option<Box<&Path>> {
let path = Path::new(guess_path);
if is_pkg_directory(path) {
return Some(Box::new(path));
}
path.parent().and_then(|v| {
if is_pkg_directory(v) {
Some(Box::new(v))
} else {
None
}
})
}
fn is_pkg_directory(path: &Path) -> bool {
path.exists() && path.is_dir() && path.ends_with("pkg")
}

@ -18,9 +18,8 @@ pub fn npm_pack(path: &str) -> Result<(), Error> {
}
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)
.current_dir(path)
.arg("publish")
.output()?;
if !output.status.success() {

Loading…
Cancel
Save