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 npm;
use slog::Logger;
use std::path::Path;
use std::result;
use PBAR;
@ -10,7 +9,7 @@ pub fn pack(path: Option<String>, log: &Logger) -> result::Result<(), Error> {
let crate_path = set_crate_path(path);
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!(
"Unable to find the pkg directory at path '{}', or in a child directory of '{}'",
&crate_path, &crate_path

@ -2,7 +2,6 @@ use command::utils::{find_pkg_directory, set_crate_path};
use error::Error;
use npm;
use slog::Logger;
use std::path::Path;
use std::result;
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, "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!(
"Unable to find the pkg directory at path '{}', or in a child directory of '{}'",
&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 {
let crate_path = match path {
@ -9,18 +9,22 @@ pub fn set_crate_path(path: Option<String>) -> String {
crate_path
}
pub 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));
pub fn find_pkg_directory(guess_path: &str) -> Option<PathBuf> {
let path = PathBuf::from(guess_path);
if is_pkg_directory(&path) {
return Some(path);
}
path.parent().and_then(|v| {
if is_pkg_directory(v) {
Some(Box::new(v))
} else {
None
path.read_dir().ok().and_then(|entries| {
for entry in entries {
if entry.is_ok() {
let p = entry.unwrap().path();
if is_pkg_directory(&p) {
return Some(p);
}
}
}
None
})
}

Loading…
Cancel
Save