first commit
This commit is contained in:
commit
2eb8aac027
91 files changed
+20139
No files matched your search
@@ -0,0 +1,77 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
fn fnv1a64(parts: &[&[u8]]) -> u64 {
|
||||
let mut hash = 0xcbf29ce484222325u64;
|
||||
for part in parts {
|
||||
for byte in *part {
|
||||
hash ^= u64::from(*byte);
|
||||
hash = hash.wrapping_mul(0x100000001b3);
|
||||
}
|
||||
}
|
||||
hash
|
||||
}
|
||||
|
||||
fn bundle_manifest(root: &Path, directory: &Path, manifest: &Path, extension: &str) -> String {
|
||||
println!("cargo:rerun-if-changed={}", manifest.display());
|
||||
let manifest_text = fs::read_to_string(manifest)
|
||||
.unwrap_or_else(|error| panic!("{}: {error}", manifest.display()));
|
||||
let mut bundle = String::new();
|
||||
for raw in manifest_text.lines() {
|
||||
let name = raw.trim();
|
||||
if name.is_empty() || name.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
assert!(
|
||||
name.ends_with(extension)
|
||||
&& !name.contains('/')
|
||||
&& !name.contains('\\')
|
||||
&& !name.contains(".."),
|
||||
"invalid {extension} manifest entry: {name}"
|
||||
);
|
||||
let path = directory.join(name);
|
||||
assert!(
|
||||
path.starts_with(root),
|
||||
"asset path escaped project root: {}",
|
||||
path.display()
|
||||
);
|
||||
println!("cargo:rerun-if-changed={}", path.display());
|
||||
let source =
|
||||
fs::read_to_string(&path).unwrap_or_else(|error| panic!("{}: {error}", path.display()));
|
||||
if !bundle.is_empty() {
|
||||
bundle.push('\n');
|
||||
}
|
||||
bundle.push_str(&source);
|
||||
if !source.ends_with('\n') {
|
||||
bundle.push('\n');
|
||||
}
|
||||
}
|
||||
bundle
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let root = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
|
||||
let out = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR"));
|
||||
let css_dir = root.join("src/web/css");
|
||||
let js_dir = root.join("src/web/js");
|
||||
for path in [
|
||||
root.join("src/web/index.html"),
|
||||
root.join("src/web/icons.svg"),
|
||||
root.join("src/web/i18n/en.json"),
|
||||
root.join("src/web/i18n/pl.json"),
|
||||
] {
|
||||
println!("cargo:rerun-if-changed={}", path.display());
|
||||
}
|
||||
let css = bundle_manifest(&root, &css_dir, &css_dir.join("manifest.txt"), ".css");
|
||||
let js = bundle_manifest(&root, &js_dir, &js_dir.join("manifest.txt"), ".js");
|
||||
let icons = fs::read(root.join("src/web/icons.svg")).expect("read icons.svg");
|
||||
let en = fs::read(root.join("src/web/i18n/en.json")).expect("read en catalog");
|
||||
let pl = fs::read(root.join("src/web/i18n/pl.json")).expect("read pl catalog");
|
||||
let index = fs::read(root.join("src/web/index.html")).expect("read index.html");
|
||||
let asset_id = fnv1a64(&[css.as_bytes(), js.as_bytes(), &icons, &en, &pl, &index]);
|
||||
println!("cargo:rustc-env=POSTFIXADMIN_RS_ASSET_ID={asset_id:016x}");
|
||||
fs::write(out.join("postfixadmin-rs.css"), css).expect("write css bundle");
|
||||
fs::write(out.join("postfixadmin-rs.js"), js).expect("write js bundle");
|
||||
}
|
||||
Reference in new issue
Block a user