|
1 | 1 | use std::fs::create_dir_all;
|
2 | 2 | use std::path::{Path, PathBuf};
|
3 | 3 |
|
4 |
| -use libs::glob::glob; |
| 4 | +use libs::walkdir::{WalkDir, DirEntry}; |
| 5 | +use libs::globset::{Glob}; |
5 | 6 | use libs::sass_rs::{compile_file, Options, OutputStyle};
|
6 | 7 |
|
7 | 8 | use crate::anyhow;
|
8 | 9 | use errors::{bail, Result};
|
9 | 10 | use utils::fs::{create_file, ensure_directory_exists};
|
10 | 11 |
|
11 | 12 | pub fn compile_sass(base_path: &Path, output_path: &Path) -> Result<()> {
|
| 13 | + console::info("compiling sass..."); |
| 14 | + |
12 | 15 | ensure_directory_exists(output_path)?;
|
13 | 16 |
|
14 | 17 | let sass_path = {
|
@@ -65,19 +68,23 @@ fn compile_sass_glob(
|
65 | 68 | Ok(compiled_paths)
|
66 | 69 | }
|
67 | 70 |
|
| 71 | +fn is_partial_scss(entry: &DirEntry) -> bool { |
| 72 | + entry.file_name() |
| 73 | + .to_str() |
| 74 | + .map(|s| s.starts_with("_")) |
| 75 | + .unwrap_or(false) |
| 76 | +} |
| 77 | + |
68 | 78 | fn get_non_partial_scss(sass_path: &Path, extension: &str) -> Vec<PathBuf> {
|
69 |
| - let glob_string = format!("{}/**/*.{}", sass_path.display(), extension); |
70 |
| - glob(&glob_string) |
71 |
| - .expect("Invalid glob for sass") |
| 79 | + let glob_string = format!("*.{}", extension); |
| 80 | + let glob = Glob::new(glob_string.as_str()).expect("Invalid glob for sass").compile_matcher(); |
| 81 | + |
| 82 | + WalkDir::new(sass_path) |
| 83 | + .into_iter() |
| 84 | + .filter_entry(|e| !is_partial_scss(e)) |
72 | 85 | .filter_map(|e| e.ok())
|
73 |
| - .filter(|entry| { |
74 |
| - !entry |
75 |
| - .as_path() |
76 |
| - .iter() |
77 |
| - .last() |
78 |
| - .map(|c| c.to_string_lossy().starts_with('_')) |
79 |
| - .unwrap_or(true) |
80 |
| - }) |
| 86 | + .map(|e| e.into_path()) |
| 87 | + .filter(|e| glob.is_match(e)) |
81 | 88 | .collect::<Vec<_>>()
|
82 | 89 | }
|
83 | 90 |
|
|
0 commit comments