The Glob library does not work correctly on windows.  This changes the approach to use the normal WalkDir crate, and the Globset crate instead to find the filter.  This new code correctly compiles sass files across platforms now.
use std::fs::create_dir_all;
use std::path::{Path, PathBuf};
-use libs::glob::glob;
+use libs::walkdir::{WalkDir, DirEntry};
+use libs::globset::{Glob};
use libs::sass_rs::{compile_file, Options, OutputStyle};
use crate::anyhow;
@@ -9,6 +10,8 @@ use errors::{bail, Result};
use utils::fs::{create_file, ensure_directory_exists};
pub fn compile_sass(base_path: &Path, output_path: &Path) -> Result<()> {
+ console::info("compiling sass...");
+
ensure_directory_exists(output_path)?;
let sass_path = {
@@ -65,19 +68,23 @@ fn compile_sass_glob(
Ok(compiled_paths)
}
+fn is_partial_scss(entry: &DirEntry) -> bool {
+ entry.file_name()
+ .to_str()
+ .map(|s| s.starts_with("_"))
+ .unwrap_or(false)
+}
+
fn get_non_partial_scss(sass_path: &Path, extension: &str) -> Vec<PathBuf> {
- let glob_string = format!("{}/**/*.{}", sass_path.display(), extension);
- glob(&glob_string)
- .expect("Invalid glob for sass")
+ let glob_string = format!("*.{}", extension);
+ let glob = Glob::new(glob_string.as_str()).expect("Invalid glob for sass").compile_matcher();
+
+ WalkDir::new(sass_path)
+ .into_iter()
+ .filter_entry(|e| !is_partial_scss(e))
.filter_map(|e| e.ok())
- .filter(|entry| {
- !entry
- .as_path()
- .iter()
- .last()
- .map(|c| c.to_string_lossy().starts_with('_'))
- .unwrap_or(true)
- })
+ .map(|e| e.into_path())
+ .filter(|e| glob.is_match(e))
.collect::<Vec<_>>()
}
