Reorganise build script into modules

This commit is contained in:
cyqsimon authored and Martin Nordholts committed 2023-11-02 17:54:57 +01:00
1 parent f3a5e9a73c
commit 79a03b4299
4 files changed
+35 -31

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
#![allow(dead_code)]
use std::{collections::HashMap, fs, path::Path};
/// Generates a file from a template.
pub fn render_template(
variables: &HashMap<&str, String>,
in_file: &str,
out_file: impl AsRef<Path>,
) -> anyhow::Result<()> {
let mut content = fs::read_to_string(in_file)?;
for (variable_name, value) in variables {
// Replace {{variable_name}} by the value
let pattern = format!("{{{{{variable_name}}}}}");
content = content.replace(&pattern, value);
}
fs::write(out_file, content)?;
Ok(())
}