Skip to content

Commit

Permalink
feat(cli): allow conf path to be gitignored, closes #3636 (#3683)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Mar 13, 2022
1 parent 263b45e commit cc7c2d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/allow-conf-gitignore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---

Allows the `tauri.conf.json` file to be git ignored on the path lookup function.
13 changes: 8 additions & 5 deletions tooling/cli/src/helpers/app_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
cmp::Ordering,
env::current_dir,
ffi::OsStr,
fs::FileType,
path::{Path, PathBuf},
};

Expand All @@ -14,7 +15,7 @@ use once_cell::sync::Lazy;

const TAURI_GITIGNORE: &[u8] = include_bytes!("../../tauri.gitignore");

fn lookup<F: Fn(&PathBuf) -> bool>(dir: &Path, checker: F) -> Option<PathBuf> {
fn lookup<F: Fn(&PathBuf, FileType) -> bool>(dir: &Path, checker: F) -> Option<PathBuf> {
let mut default_gitignore = std::env::temp_dir();
default_gitignore.push(".gitignore");
if !default_gitignore.exists() {
Expand Down Expand Up @@ -47,25 +48,27 @@ fn lookup<F: Fn(&PathBuf) -> bool>(dir: &Path, checker: F) -> Option<PathBuf> {

for entry in builder.build().flatten() {
let path = dir.join(entry.path());
if checker(&path) {
if checker(&path, entry.file_type().unwrap()) {
return Some(path);
}
}
None
}

fn get_tauri_dir() -> PathBuf {
lookup(&current_dir().expect("failed to read cwd"), |path| if let Some(file_name) = path.file_name() {
lookup(&current_dir().expect("failed to read cwd"), |path, file_type| if file_type.is_dir() {
path.join("tauri.conf.json").exists() || path.join("tauri.conf.json5").exists()
} else if let Some(file_name) = path.file_name() {
file_name == OsStr::new("tauri.conf.json") || file_name == OsStr::new("tauri.conf.json5")
} else {
false
})
.map(|p| p.parent().unwrap().to_path_buf())
.map(|p| if p.is_dir() { p } else { p.parent().unwrap().to_path_buf() })
.expect("Couldn't recognize the current folder as a Tauri project. It must contain a `tauri.conf.json` or `tauri.conf.json5` file in any subfolder.")
}

fn get_app_dir() -> Option<PathBuf> {
lookup(&current_dir().expect("failed to read cwd"), |path| {
lookup(&current_dir().expect("failed to read cwd"), |path, _| {
if let Some(file_name) = path.file_name() {
file_name == OsStr::new("package.json")
} else {
Expand Down

0 comments on commit cc7c2d7

Please sign in to comment.