mirror of
https://github.com/danbulant/lucide
synced 2026-07-08 20:51:09 +00:00
fix: change generate to support non-last features section (#150)
This commit is contained in:
parent
ddf713f828
commit
8b4da4f131
1 changed files with 12 additions and 7 deletions
|
|
@ -227,11 +227,14 @@ fn generate_features(
|
||||||
|
|
||||||
let mut file_contents = fs::read_to_string(&file_path)?;
|
let mut file_contents = fs::read_to_string(&file_path)?;
|
||||||
|
|
||||||
let index = file_contents.find("[features]");
|
let start_index = file_contents.find("[features]").ok_or_else(|| {
|
||||||
if let Some(index) = index {
|
Box::<dyn Error>::from(format!("`{file_path:?}` does not contain `[features]`."))
|
||||||
file_contents = file_contents[0..index].to_string();
|
})?;
|
||||||
}
|
let end_index = file_contents.find("[dependencies]").ok_or_else(|| {
|
||||||
file_contents = file_contents.trim_end_matches("\n").to_string();
|
Box::<dyn Error>::from(format!(
|
||||||
|
"`{file_path:?}` does not contain `[dependencies]`."
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
|
||||||
let mut features = metadatas
|
let mut features = metadatas
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -253,10 +256,12 @@ fn generate_features(
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
let output = format!(
|
let output = format!(
|
||||||
"{file_contents}\n\n[features]\ndefault = []\n{output_features}\nall-icons = [\n{output_all_features}\n]\n"
|
"[features]\ndefault = []\n{output_features}\nall-icons = [\n{output_all_features}\n]\n\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
fs::write(&file_path, output)?;
|
file_contents.replace_range(start_index..end_index, &output);
|
||||||
|
|
||||||
|
fs::write(&file_path, file_contents)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue