diff --git a/.changeset/script-skip-ignored-dirs.md b/.changeset/script-skip-ignored-dirs.md new file mode 100644 index 00000000..5feaf678 --- /dev/null +++ b/.changeset/script-skip-ignored-dirs.md @@ -0,0 +1,5 @@ +--- +"@googleworkspace/cli": patch +--- + +Skip ignored directories while collecting files for `gws script +push`. diff --git a/crates/google-workspace-cli/src/helpers/script.rs b/crates/google-workspace-cli/src/helpers/script.rs index 11bcdebe..f33a9c39 100644 --- a/crates/google-workspace-cli/src/helpers/script.rs +++ b/crates/google-workspace-cli/src/helpers/script.rs @@ -145,6 +145,10 @@ fn visit_dirs(dir: &Path, files: &mut Vec) -> Result<(), GwsE let entry = entry.context("Failed to read entry")?; let path = entry.path(); if path.is_dir() { + let dirname = path.file_name().and_then(|s| s.to_str()).unwrap_or(""); + if dirname.starts_with('.') || dirname == "node_modules" { + continue; + } visit_dirs(&path, files)?; } else if let Some(file_obj) = process_file(&path)? { files.push(file_obj); @@ -169,13 +173,8 @@ fn process_file(path: &Path) -> Result, GwsError> { filename.trim_end_matches(".js").trim_end_matches(".gs"), ), "html" => ("HTML", filename.trim_end_matches(".html")), - "json" => { - if filename == "appsscript.json" { - ("JSON", "appsscript") - } else { - return Ok(None); - } - } + "json" if filename == "appsscript.json" => ("JSON", "appsscript"), + "json" => return Ok(None), _ => return Ok(None), }; @@ -277,6 +276,14 @@ mod tests { let f3 = dir.path().join("ignore.txt"); File::create(&f3).unwrap(); + let hidden = dir.path().join(".hidden"); + fs::create_dir(&hidden).unwrap(); + File::create(hidden.join("secret.gs")).unwrap(); + + let node_modules = dir.path().join("node_modules"); + fs::create_dir(&node_modules).unwrap(); + File::create(node_modules.join("dep.gs")).unwrap(); + let mut files = Vec::new(); visit_dirs(dir.path(), &mut files).unwrap();