Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "2"

members = [
members = [
"edge-frame",
"kitchen-sink",
]
Expand All @@ -12,3 +12,9 @@ opt-level = "s"
[profile.dev]
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"

[workspace.dependencies]
yewdux-middleware = { version = "0.4.0" }
yewdux = { version = "0.12.0", default-features = false}
yew = { version = "0.22.0", default-features = false}
yew-router = { version = "0.19.0"}
8 changes: 4 additions & 4 deletions edge-frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ heapless = { version = "0.8", optional = true, default-features = false }
derive_more = { version = "0.99", optional = true }
wasm-logger = { version = "0.2", optional = true }
web-sys = { version = "0.3", optional = true, features = ["console"] }
yew = { version = "0.21", optional = true, default-features = false }
yew-router = { version = "0.18", optional = true }
yewdux = { version = "0.10", default-features = false, optional = true }
yewdux-middleware = { version = "0.3", optional = true }
yew = { workspace = true, optional = true, default-features = false }
yew-router = { workspace = true, optional = true }
yewdux = { workspace=true, default-features = false, optional = true }
yewdux-middleware = { workspace = true,optional = true }
serde = { version = "1", default-features = false, optional = true, features = ["derive"] }
enumset = { version = "1", default-features = false, optional = true, features = ["serde"] }
strum = { version = "0.25", default-features = false, optional = true, features = ["derive"] }
Expand Down
81 changes: 58 additions & 23 deletions edge-frame/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ pub mod serve {
#[cfg(feature = "assets-prepare")]
pub mod prepare {
use std::{
env, fs, io,
env,
fs::{self},
io,
iter::repeat,
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -259,16 +261,21 @@ pub mod prepare {
};

for (index, output_file) in output_files.iter().enumerate() {
let file_name = output_file.file_name().unwrap().to_str().unwrap();
let file = output_file.strip_prefix(&output_dir).unwrap();
let file_uri = file
.to_str()
.unwrap()
.replace(std::path::MAIN_SEPARATOR, "/");

if file_name == "__empty__" {
if file_uri == "__empty__" {
println!("cargo:rustc-env={}_EDGE_FRAME_ASSET_URI_{}=", module, index,);
} else {
let file = file;
println!(
"cargo:rustc-env={}_EDGE_FRAME_ASSET_URI_{}=/{}",
module,
index,
output_file.file_name().unwrap().to_str().unwrap()
file.display()
);
}

Expand All @@ -283,6 +290,19 @@ pub mod prepare {
Ok(())
}

fn visit_files(path: &Path) -> anyhow::Result<Vec<PathBuf>> {
if path.is_file() {
Ok(vec![path.to_owned()])
} else {
let mut paths = Vec::new();
for entry in fs::read_dir(path)? {
paths.extend(visit_files(&entry?.path())?);
}

Ok(paths)
}
}

pub fn compress(
assets_dir: impl AsRef<Path>,
output_dir: impl AsRef<Path>,
Expand All @@ -291,32 +311,47 @@ pub mod prepare {
let assets_dir = assets_dir.as_ref();
let output_dir = output_dir.as_ref();

let output_files = fs::read_dir(assets_dir)?
Comment thread
DaneSlattery marked this conversation as resolved.
.filter_map(|file| file.ok())
let output_files = visit_files(assets_dir)?
.into_iter()
.filter_map(|file| Some(file))
.filter(|file| file.metadata().map(|md| md.is_file()).unwrap_or(false))
.map(|file| {
track(&file.path());

let output_file =
output_dir.join(format!("{}.gz", file.file_name().to_str().unwrap()));

track(&output_file);

fs::create_dir_all(output_dir).unwrap();

io::copy(
&mut fs::File::open(file.path()).unwrap(),
&mut GzEncoder::new(
fs::File::create(&output_file).unwrap(),
Compression::best(),
),
)
.unwrap();
let output_file = compress_file(&track, output_dir, assets_dir, &file);


output_file
})
.collect::<Vec<_>>();

Ok(output_files)
}

/// Compress and write file
///
/// # Panics
///
/// Panics if .
fn compress_file(
track: impl Fn(&Path),
output_dir: &Path,
root: &Path,
file: &PathBuf,
) -> PathBuf {
track(&file);
let output_folder = output_dir.join(file.parent().unwrap().strip_prefix(root).unwrap());
let output_file =
output_dir.join(format!("{}.gz", file.strip_prefix(root).unwrap().display()));

track(&output_file);

fs::create_dir_all(output_folder).unwrap();

io::copy(
&mut fs::File::open(file).unwrap(),
&mut GzEncoder::new(fs::File::create(&output_file).unwrap(), Compression::best()),
)
.unwrap();

output_file
}
}
6 changes: 3 additions & 3 deletions kitchen-sink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ anyhow = "1"
log = "0.4"
derive_more = "0.99"
wasm-logger = "0.2"
yew = { version = "0.21", default-features = false, features = ["csr"] }
yew-router = "0.18"
yewdux-middleware = "0.3"
yew = { workspace = true, default-features = false, features = ["csr"] }
yew-router = {workspace = true}
yewdux-middleware = { workspace = true }
edge-frame = { path = "../edge-frame" }

# The `console_error_panic_hook` crate provides better debugging of panics by
Expand Down