Check child directories instead of parent directory

master
Mackiovello 7 years ago
parent a67762a9e5
commit 63c91caeae
  1. 3
      src/command/pack.rs
  2. 3
      src/command/publish.rs
  3. 24
      src/command/utils.rs

@ -2,7 +2,6 @@ use command::utils::{find_pkg_directory, set_crate_path};
use error::Error; use error::Error;
use npm; use npm;
use slog::Logger; use slog::Logger;
use std::path::Path;
use std::result; use std::result;
use PBAR; use PBAR;
@ -10,7 +9,7 @@ pub fn pack(path: Option<String>, log: &Logger) -> result::Result<(), Error> {
let crate_path = set_crate_path(path); let crate_path = set_crate_path(path);
info!(&log, "Packing up the npm package..."); info!(&log, "Packing up the npm package...");
let pkg_directory: Box<&Path> = find_pkg_directory(&crate_path).ok_or(Error::PkgNotFound { let pkg_directory = find_pkg_directory(&crate_path).ok_or(Error::PkgNotFound {
message: format!( message: format!(
"Unable to find the pkg directory at path '{}', or in a child directory of '{}'", "Unable to find the pkg directory at path '{}', or in a child directory of '{}'",
&crate_path, &crate_path &crate_path, &crate_path

@ -2,7 +2,6 @@ use command::utils::{find_pkg_directory, set_crate_path};
use error::Error; use error::Error;
use npm; use npm;
use slog::Logger; use slog::Logger;
use std::path::Path;
use std::result; use std::result;
use PBAR; use PBAR;
@ -11,7 +10,7 @@ pub fn publish(path: Option<String>, log: &Logger) -> result::Result<(), Error>
info!(&log, "Publishing the npm package..."); info!(&log, "Publishing the npm package...");
info!(&log, "npm info located in the npm debug log"); info!(&log, "npm info located in the npm debug log");
let pkg_directory: Box<&Path> = find_pkg_directory(&crate_path).ok_or(Error::PkgNotFound { let pkg_directory = find_pkg_directory(&crate_path).ok_or(Error::PkgNotFound {
message: format!( message: format!(
"Unable to find the pkg directory at path '{}', or in a child directory of '{}'", "Unable to find the pkg directory at path '{}', or in a child directory of '{}'",
&crate_path, &crate_path &crate_path, &crate_path

@ -1,4 +1,4 @@
use std::path::Path; use std::path::{Path, PathBuf};
pub fn set_crate_path(path: Option<String>) -> String { pub fn set_crate_path(path: Option<String>) -> String {
let crate_path = match path { let crate_path = match path {
@ -9,18 +9,22 @@ pub fn set_crate_path(path: Option<String>) -> String {
crate_path crate_path
} }
pub fn find_pkg_directory(guess_path: &str) -> Option<Box<&Path>> { pub fn find_pkg_directory(guess_path: &str) -> Option<PathBuf> {
let path = Path::new(guess_path); let path = PathBuf::from(guess_path);
if is_pkg_directory(path) { if is_pkg_directory(&path) {
return Some(Box::new(path)); return Some(path);
} }
path.parent().and_then(|v| { path.read_dir().ok().and_then(|entries| {
if is_pkg_directory(v) { for entry in entries {
Some(Box::new(v)) if entry.is_ok() {
} else { let p = entry.unwrap().path();
None if is_pkg_directory(&p) {
return Some(p);
}
} }
}
None
}) })
} }

Loading…
Cancel
Save