|
@@ -6,18 +6,19 @@ use std::{
|
|
|
cmp::Ordering,
|
|
|
env::current_dir,
|
|
|
ffi::OsStr,
|
|
|
- fs::FileType,
|
|
|
path::{Path, PathBuf},
|
|
|
};
|
|
|
|
|
|
use ignore::WalkBuilder;
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
|
-use tauri_utils::config::parse::ConfigFormat;
|
|
|
+use tauri_utils::config::parse::{
|
|
|
+ folder_has_configuration_file, is_configuration_file, ConfigFormat,
|
|
|
+};
|
|
|
|
|
|
const TAURI_GITIGNORE: &[u8] = include_bytes!("../../tauri.gitignore");
|
|
|
|
|
|
-fn lookup<F: Fn(&PathBuf, FileType) -> bool>(dir: &Path, checker: F) -> Option<PathBuf> {
|
|
|
+fn lookup<F: Fn(&PathBuf) -> bool>(dir: &Path, checker: F) -> Option<PathBuf> {
|
|
|
let mut default_gitignore = std::env::temp_dir();
|
|
|
default_gitignore.push(".gitignore");
|
|
|
if !default_gitignore.exists() {
|
|
@@ -51,7 +52,7 @@ fn lookup<F: Fn(&PathBuf, FileType) -> bool>(dir: &Path, checker: F) -> Option<P
|
|
|
|
|
|
for entry in builder.build().flatten() {
|
|
|
let path = dir.join(entry.path());
|
|
|
- if checker(&path, entry.file_type().unwrap()) {
|
|
|
+ if checker(&path) {
|
|
|
return Some(path);
|
|
|
}
|
|
|
}
|
|
@@ -67,13 +68,7 @@ fn get_tauri_dir() -> PathBuf {
|
|
|
return cwd.join("src-tauri/");
|
|
|
}
|
|
|
|
|
|
- lookup(&cwd, |path, file_type| if file_type.is_dir() {
|
|
|
- path.join(ConfigFormat::Json.into_file_name()).exists() || path.join(ConfigFormat::Json5.into_file_name()).exists() || path.join(ConfigFormat::Toml.into_file_name()).exists()
|
|
|
- } else if let Some(file_name) = path.file_name() {
|
|
|
- file_name == OsStr::new(ConfigFormat::Json.into_file_name()) || file_name == OsStr::new(ConfigFormat::Json5.into_file_name()) || file_name == OsStr::new(ConfigFormat::Toml.into_file_name())
|
|
|
- } else {
|
|
|
- false
|
|
|
- })
|
|
|
+ lookup(&cwd, |path| folder_has_configuration_file(path) || is_configuration_file(path))
|
|
|
.map(|p| if p.is_dir() { p } else { p.parent().unwrap().to_path_buf() })
|
|
|
.unwrap_or_else(||
|
|
|
panic!("Couldn't recognize the current folder as a Tauri project. It must contain a `{}`, `{}` or `{}` file in any subfolder.",
|
|
@@ -85,7 +80,7 @@ fn get_tauri_dir() -> PathBuf {
|
|
|
}
|
|
|
|
|
|
fn get_app_dir() -> Option<PathBuf> {
|
|
|
- lookup(¤t_dir().expect("failed to read cwd"), |path, _| {
|
|
|
+ lookup(¤t_dir().expect("failed to read cwd"), |path| {
|
|
|
if let Some(file_name) = path.file_name() {
|
|
|
file_name == OsStr::new("package.json")
|
|
|
} else {
|