2023-06-27 18:03:52 +00:00
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
|
|
|
use std::path::Path;
|
|
|
|
|
2023-06-29 04:34:09 +00:00
|
|
|
fn write_bundle_manifest(asset_type: &str) {
|
2023-06-27 18:03:52 +00:00
|
|
|
let root_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
|
|
let root_dir = Path::new(&root_dir);
|
2023-06-29 04:34:09 +00:00
|
|
|
let dir = root_dir.join(format!("static/{}", asset_type));
|
2023-06-27 18:03:52 +00:00
|
|
|
|
|
|
|
let entries = fs::read_dir(&dir).unwrap();
|
|
|
|
|
2023-06-29 04:34:09 +00:00
|
|
|
let bundles: Vec<String> = entries
|
2023-06-27 18:03:52 +00:00
|
|
|
.filter_map(Result::ok)
|
2023-06-29 04:34:09 +00:00
|
|
|
.filter(|entry| {
|
|
|
|
entry
|
|
|
|
.file_name()
|
|
|
|
.to_string_lossy()
|
|
|
|
.ends_with(&format!(".{}", asset_type))
|
|
|
|
})
|
2023-06-27 18:03:52 +00:00
|
|
|
.map(|entry| {
|
|
|
|
Path::new("/")
|
|
|
|
.join(entry.path().strip_prefix(root_dir).unwrap())
|
|
|
|
.display()
|
|
|
|
.to_string()
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
2023-06-29 04:34:09 +00:00
|
|
|
fs::write(dir.join("manifest.txt"), bundles.join("\n")).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("cargo:rerun-if-changed=migrations");
|
|
|
|
println!("cargo:rerun-if-changed=.frontend-built");
|
|
|
|
|
|
|
|
write_bundle_manifest("js");
|
|
|
|
write_bundle_manifest("css");
|
2023-05-07 21:41:45 +00:00
|
|
|
}
|