optional mime type
This commit is contained in:
parent
33d0612292
commit
e75ac689d2
2 changed files with 60 additions and 64 deletions
|
@ -15,6 +15,10 @@
|
||||||
`CACHE_BUSTER_DATA_FILE`(`./src/cache_buster_data.json`) and the user
|
`CACHE_BUSTER_DATA_FILE`(`./src/cache_buster_data.json`) and the user
|
||||||
is requested to read and pass the value to `File::new()`
|
is requested to read and pass the value to `File::new()`
|
||||||
|
|
||||||
|
- `Files.mime_types` now accepts an `Option<Vec<mime::Mime>>`. When it
|
||||||
|
is unset(i.e `None`), no mime based filtering is done and all files
|
||||||
|
inside source directory is considered for processing.
|
||||||
|
|
||||||
### Fixed:
|
### Fixed:
|
||||||
|
|
||||||
- `Files::get()` now behaves as it is described in the documentation
|
- `Files::get()` now behaves as it is described in the documentation
|
||||||
|
|
|
@ -121,16 +121,6 @@ impl<'a> Buster<'a> {
|
||||||
self.init()?;
|
self.init()?;
|
||||||
let mut file_map: Files = Files::new(&self.result);
|
let mut file_map: Files = Files::new(&self.result);
|
||||||
|
|
||||||
for entry in WalkDir::new(&self.source)
|
|
||||||
.follow_links(self.follow_links)
|
|
||||||
.into_iter()
|
|
||||||
{
|
|
||||||
let entry = entry?;
|
|
||||||
|
|
||||||
let path = entry.path();
|
|
||||||
if !path.is_dir() {
|
|
||||||
let path = Path::new(&path);
|
|
||||||
|
|
||||||
let mut process_worker = |path: &Path| {
|
let mut process_worker = |path: &Path| {
|
||||||
let contents = Self::read_to_string(&path).unwrap();
|
let contents = Self::read_to_string(&path).unwrap();
|
||||||
let hash = Self::hasher(&contents);
|
let hash = Self::hasher(&contents);
|
||||||
|
@ -159,6 +149,16 @@ impl<'a> Buster<'a> {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
for entry in WalkDir::new(&self.source)
|
||||||
|
.follow_links(self.follow_links)
|
||||||
|
.into_iter()
|
||||||
|
{
|
||||||
|
let entry = entry?;
|
||||||
|
|
||||||
|
let path = entry.path();
|
||||||
|
if !path.is_dir() {
|
||||||
|
let path = Path::new(&path);
|
||||||
|
|
||||||
match self.mime_types.as_ref() {
|
match self.mime_types.as_ref() {
|
||||||
Some(mime_types) => {
|
Some(mime_types) => {
|
||||||
for mime_type in mime_types.iter() {
|
for mime_type in mime_types.iter() {
|
||||||
|
@ -275,25 +275,11 @@ impl Files {
|
||||||
/// data to the main program. This funtction sets that variable
|
/// data to the main program. This funtction sets that variable
|
||||||
fn to_env(&self) {
|
fn to_env(&self) {
|
||||||
let json = serde_json::to_string(&self).unwrap();
|
let json = serde_json::to_string(&self).unwrap();
|
||||||
// println!("cargo:rustc-env={}={}", ENV_VAR_NAME, json);
|
|
||||||
let res = Path::new(CACHE_BUSTER_DATA_FILE);
|
let res = Path::new(CACHE_BUSTER_DATA_FILE);
|
||||||
if res.exists() {
|
if res.exists() {
|
||||||
fs::remove_file(&res).unwrap();
|
fs::remove_file(&res).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// const PREFIX: &str = r##"pub const FILE_MAP: &str = r#" "##;
|
|
||||||
// const POSTFIX: &str = r##""#;"##;
|
|
||||||
|
|
||||||
// let content = format!("#[allow(dead_code)]\n{}{}{}", &PREFIX, &json, &POSTFIX);
|
|
||||||
|
|
||||||
// fs::write(CACHE_BUSTER_DATA_FILE, content).unwrap();
|
|
||||||
fs::write(CACHE_BUSTER_DATA_FILE, &json).unwrap();
|
fs::write(CACHE_BUSTER_DATA_FILE, &json).unwrap();
|
||||||
|
|
||||||
// needed for testing load()
|
|
||||||
// if the above statement fails(println), then something's broken
|
|
||||||
// with the rust compiler. So not really worried about that.
|
|
||||||
// #[cfg(test)]
|
|
||||||
// std::env::set_var(ENV_VAR_NAME, serde_json::to_string(&self).unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -309,6 +295,7 @@ impl Files {
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn hasher_works() {
|
fn hasher_works() {
|
||||||
delete_file();
|
delete_file();
|
||||||
let types = vec![
|
let types = vec![
|
||||||
|
@ -349,6 +336,7 @@ pub mod tests {
|
||||||
let _ = fs::remove_file(&CACHE_BUSTER_DATA_FILE);
|
let _ = fs::remove_file(&CACHE_BUSTER_DATA_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #[test]
|
||||||
fn prefix_works() {
|
fn prefix_works() {
|
||||||
delete_file();
|
delete_file();
|
||||||
let types = vec![
|
let types = vec![
|
||||||
|
@ -421,28 +409,32 @@ pub mod tests {
|
||||||
.is_err())
|
.is_err())
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn no_specific_mime() {
|
fn no_specific_mime() {
|
||||||
// let no_hash = vec!["858fd6c482cc75111d54.module.wasm"];
|
let no_hash = vec!["858fd6c482cc75111d54.module.wasm"];
|
||||||
// let config = BusterBuilder::default()
|
let config = BusterBuilder::default()
|
||||||
// .source("./dist")
|
.source("./dist")
|
||||||
// .result("/tmp/prod2ii")
|
.result("/tmp/prod2ii")
|
||||||
// .copy(true)
|
.copy(true)
|
||||||
// .follow_links(true)
|
.follow_links(true)
|
||||||
// .no_hash(no_hash.clone())
|
.no_hash(no_hash.clone())
|
||||||
// .prefix("/test")
|
.build()
|
||||||
// .build()
|
.unwrap();
|
||||||
// .unwrap();
|
config.process().unwrap();
|
||||||
// config.process().unwrap();
|
let files = Files::load();
|
||||||
// let files = Files::load();
|
|
||||||
// files.map.iter().any(|(k, v)| {
|
assert!(files.map.iter().any(|(k, v)| {
|
||||||
// let dest = Path::new(&v[prefix.len()..]);
|
let source = Path::new(&config.source).join(k);
|
||||||
// let no_hash = Path::new(file);
|
let dest = Path::new(&v);
|
||||||
// k == file && dest.exists() && no_hash.file_name() == dest.file_name()
|
let no_hash = Path::new(&config.result).join(no_hash.first().unwrap());
|
||||||
// });
|
println!("destination: {:?}", dest);
|
||||||
//
|
dest.file_name() == no_hash.file_name()
|
||||||
// cleanup(&config);
|
&& dest.exists()
|
||||||
// }
|
&& source.file_name() == dest.file_name()
|
||||||
|
}));
|
||||||
|
|
||||||
|
cleanup(&config);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn runner() {
|
pub fn runner() {
|
||||||
prefix_works();
|
prefix_works();
|
||||||
|
|
Loading…
Reference in a new issue