Skip to content

Commit

Permalink
changes directory for examples in xtask
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazariglez committed Jun 8, 2024
1 parent 8b57a11 commit a842171
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 49 deletions.
28 changes: 1 addition & 27 deletions scripts/build_web_examples.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
#!/bin/bash
mkdir -p ./docs/examples/assets
cp -R ./examples/assets ./docs/examples

doc_body="<ul>\n"

compile() {
f=$1
f=${f/\.\/examples\//""}
f=${f/.rs/""}
./scripts/web_example.sh $f --release --no-assets

url="examples/${f}.html"
image="examples/images/${f}.jpg"
doc_body="${doc_body}\n<li><a href=\"${url}\"><div class=\"example-image\"><img src=\"${image}\" alt=\"${f}\"></div><div class=\"example-link\">${f}</div></a></li>"
}

for f in ./examples/*.rs; do
compile "$f"
done

wait

doc_body="${doc_body}\n</ul>"
cp ./scripts/docs.html ./docs/index.html
index=$(sed "s#{{ BODY }}#${doc_body}#g" "./scripts/docs.html")
echo "${index}" > ./docs/index.html
cargo xtask examples web --release
28 changes: 9 additions & 19 deletions xtask/src/cli_example_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ impl Example {
.join(wasm.as_str())
.to_string_lossy()
.into_owned();
let output = docs_web_dir(self.release, name_str)
.to_string_lossy()
.into_owned();
let output = docs_web_dir(name_str).to_string_lossy().into_owned();

let status = wasm_bindgen(input.as_str(), output.as_str(), !self.release)?;
if !status.success() {
Expand All @@ -34,7 +32,7 @@ impl Example {

if self.release {
let wasm_file = format!("{name_str}_bg.wasm");
let inout = docs_web_dir(self.release, name_str)
let inout = docs_web_dir(name_str)
.join(wasm_file.as_str())
.to_string_lossy()
.into_owned();
Expand All @@ -46,16 +44,16 @@ impl Example {

if self.gzip {
let wasm_gz = format!("{wasm_file}.gz");
let wasm_gz_output = docs_web_dir(self.release, name_str)
let wasm_gz_output = docs_web_dir(name_str)
.join(wasm_gz)
.to_string_lossy()
.into_owned();

let js_gz_input = docs_web_dir(self.release, name_str)
let js_gz_input = docs_web_dir(name_str)
.join(format!("{name_str}.js"))
.to_string_lossy()
.into_owned();
let js_gz_output = docs_web_dir(self.release, name_str)
let js_gz_output = docs_web_dir(name_str)
.join(format!("{name_str}.js.gz"))
.to_string_lossy()
.into_owned();
Expand All @@ -78,30 +76,22 @@ impl Example {
output_lines.push(line);
}

let mut file_out =
File::create(docs_web_dir(self.release, "").join(example_file.as_str()))?;
let mut file_out = File::create(docs_web_dir("").join(example_file.as_str()))?;

for line in &output_lines {
writeln!(file_out, "{}", line)?;
}

if !self.no_assets {
copy_assets(docs_web_dir(self.release, ""))
copy_assets(docs_web_dir(""))
}

Ok(())
}
}

pub fn docs_web_dir(release: bool, name: &str) -> PathBuf {
project_root()
.join("docs/web_examples/")
.join(match release {
true => "release",
false => "debug",
})
.join("examples")
.join(name)
pub fn docs_web_dir(name: &str) -> PathBuf {
project_root().join("docs").join("examples").join(name)
}

fn dist_web_dir(release: bool) -> PathBuf {
Expand Down
9 changes: 8 additions & 1 deletion xtask/src/cli_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ impl Examples {
.filter_map(Result::ok)
.filter_map(|entry| {
let metadata = entry.metadata().ok()?;
if metadata.is_file() {
let is_file = metadata.is_file();
let is_hidden = entry
.file_name()
.to_str()
.map(|name| name.starts_with("."))
.unwrap_or_default();
let is_valid = is_file && !is_hidden;
if is_valid {
Some(entry)
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions xtask/src/cli_examples_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{copy_assets, project_root, DynError};

impl Examples {
pub(crate) fn run_web(self) -> Result<(), DynError> {
copy_assets(docs_web_dir(self.release, "assets"));
copy_assets(docs_web_dir("assets"));

let mut doc_body = String::from("<ul>\n");

Expand Down Expand Up @@ -55,7 +55,7 @@ impl Examples {
output_lines.push(line);
}

let mut file_out = File::create(docs_web_dir(release, "").join("index.html"))?;
let mut file_out = File::create(docs_web_dir("../").join("index.html"))?;

for line in &output_lines {
writeln!(file_out, "{}", line)?;
Expand Down

0 comments on commit a842171

Please sign in to comment.