Remove auto option

This commit is contained in:
YuKun Liu committed 2022-05-10 22:58:48 +08:00
1 parent 551d2477ff
commit 9ddaa773d9
1 file changed
+73 -38
+73 -38
View File
@@ -362,48 +362,54 @@ fn build_assets(config: &CrateConfig) -> Result<()> {
"--no-source-map" "--no-source-map"
} }
} else { } else {
"--no-source-map" "--source-map"
}; };
if tab.contains_key("auto") && tab.get("auto").unwrap().as_bool().unwrap_or(false) { if tab.contains_key("files") {
// if the sass open auto, we need auto-check the assets dir. if tab.get("files").unwrap().is_str() {
let asset_dir = config.asset_dir.clone(); let file = tab.get("files").unwrap().as_str().unwrap().trim();
if asset_dir.is_dir() {
for entry in walkdir::WalkDir::new(&asset_dir) if file == "*" {
.into_iter() // if the sass open auto, we need auto-check the assets dir.
.filter_map(|e| e.ok()) let asset_dir = config.asset_dir.clone();
{ if asset_dir.is_dir() {
let temp = entry.path(); for entry in walkdir::WalkDir::new(&asset_dir)
if temp.is_file() { .into_iter()
let suffix = temp.extension().unwrap().to_str().unwrap(); .filter_map(|e| e.ok())
if suffix == "scss" { {
// if file suffix is `scss` we need transform it. let temp = entry.path();
let out_file = if temp.is_file() {
format!("{}.css", temp.file_stem().unwrap().to_str().unwrap()); let suffix = temp.extension().unwrap().to_str().unwrap();
let target_path = config if suffix == "scss" {
.out_dir // if file suffix is `scss` we need transform it.
.join(temp.strip_prefix(&asset_dir).unwrap().parent().unwrap()) let out_file = format!(
.join(out_file); "{}.css",
sass.call( temp.file_stem().unwrap().to_str().unwrap()
"sass", );
vec![ let target_path = config
temp.to_str().unwrap(), .out_dir
target_path.to_str().unwrap(), .join(
source_map, temp.strip_prefix(&asset_dir)
], .unwrap()
)?; .parent()
.unwrap(),
)
.join(out_file);
sass.call(
"sass",
vec![
temp.to_str().unwrap(),
target_path.to_str().unwrap(),
source_map,
],
)?;
}
}
} }
} }
} } else {
} // just transform one file.
} else if tab.contains_key("files") && tab.get("files").unwrap().is_array() { let path = config.asset_dir.join(file);
// check files list.
let list = tab.get("files").unwrap().as_array().unwrap();
for i in list {
if i.is_str() {
let path = i.as_str().unwrap();
let path = PathBuf::from(path);
let path = config.asset_dir.join(path);
if path.is_file() { if path.is_file() {
sass.call( sass.call(
"sass", "sass",
@@ -422,10 +428,39 @@ fn build_assets(config: &CrateConfig) -> Result<()> {
)?; )?;
} }
} }
} else if tab.get("files").unwrap().is_array() {
// check files list.
let list = tab.get("files").unwrap().as_array().unwrap();
for i in list {
if i.is_str() {
let path = i.as_str().unwrap();
let path = PathBuf::from(path);
let path = config.asset_dir.join(path);
if path.is_file() {
sass.call(
"sass",
vec![
path.to_str().unwrap(),
path.parent()
.unwrap()
.join(format!(
"{}.css",
path.file_stem().unwrap().to_str().unwrap()
))
.to_str()
.unwrap(),
source_map,
],
)?;
}
}
}
} }
} }
} }
} }
// SASS END
Ok(()) Ok(())
} }