diff --git a/.gitignore b/.gitignore index 56512f7..ba67566 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /target prod tarpaulin-report.html +actix-example/target +actix-example/prod diff --git a/Cargo.lock b/Cargo.lock index cff63f0..047a000 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,14 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "actix-example" +version = "0.1.0" +dependencies = [ + "cache-buster", + "mime", +] + [[package]] name = "block-buffer" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index bc175b4..b9114e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,11 @@ edition = "2018" license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[workspace] +members = [ + ".", + "actix-example" +] [lib] name = "cache_buster" diff --git a/actix-example/Cargo.toml b/actix-example/Cargo.toml new file mode 100644 index 0000000..70949d7 --- /dev/null +++ b/actix-example/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "actix-example" +version = "0.1.0" +authors = ["realaravinth "] +edition = "2018" +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +cache-buster = { path = "../"} + +[build-dependencies] +cache-buster = { path = "../"} +mime = "0.3.16" diff --git a/actix-example/build.rs b/actix-example/build.rs new file mode 100644 index 0000000..91aad76 --- /dev/null +++ b/actix-example/build.rs @@ -0,0 +1,22 @@ +use cache_buster::BusterBuilder; + +fn main() { + let types = vec![ + mime::IMAGE_PNG, + mime::IMAGE_SVG, + mime::IMAGE_JPEG, + mime::IMAGE_GIF, + ]; + + let config = BusterBuilder::default() + .source("../dist") + .result("./prod") + .mime_types(types) + .copy(true) + .follow_links(true) + .build() + .unwrap(); + + config.init().unwrap(); + config.hash().unwrap().to_env(); +} diff --git a/actix-example/src/main.rs b/actix-example/src/main.rs new file mode 100644 index 0000000..99bc547 --- /dev/null +++ b/actix-example/src/main.rs @@ -0,0 +1,24 @@ +use cache_buster::Files; + +fn main() { + let files = Files::load(); + + assert!(file_exists("../dist/log-out.svg", &files)); + assert!(file_exists( + "../dist/a/b/c/d/s/d/svg/credit-card.svg", + &files + )); + + assert!(!file_exists("dist/log-out.svg", &files)); + assert!(!file_exists("dist/a/b/c/d/s/d/svg/credit-card.svg", &files)); +} + +fn file_exists(path: &str, files: &Files) -> bool { + use std::path::Path; + + if let Some(file) = files.get(path) { + Path::new(file).exists() + } else { + false + } +}