Clean up build process

This commit is contained in:
Austen Adler 2023-03-12 00:54:16 -05:00
parent fb6604e19b
commit 5d2d075eef
8 changed files with 25 additions and 16 deletions

View File

@ -12,7 +12,7 @@
The goal of this document is to define the algorithm.
If you want to see the steps to get to this definition, go to link:DESIGN.html[DESIGN].
If you want to see the steps to get to this definition, go to link:/docs/DESIGN[DESIGN].
== Data format

View File

@ -12,7 +12,7 @@
The goal of this document is to walk through how the design was chosen.
If you want to see the algorithm definition, go to link:ALGORITHM.html[ALGORITHM].
If you want to see the algorithm definition, go to link:/docs/ALGORITHM[ALGORITHM].
== 10,000 meter view

View File

@ -11,9 +11,9 @@
== Pages
* link:..[xpin.app] - Go back to the xpin homepage
* link:ALGORITHM.html[ALGORITHM] - Algorithm definition
* link:DESIGN.html[DESIGN] - Algorithm design documentation
* link:WORDLIST.html[WORDLIST] - Wordlist design and implementation
* link:/docs/ALGORITHM[ALGORITHM] - Algorithm definition
* link:/docs/DESIGN[DESIGN] - Algorithm design documentation
* link:/docs/WORDLIST[WORDLIST] - Wordlist design and implementation
++++
<style>

View File

@ -1,15 +1,11 @@
build: fmt js-build
# Rust test needs to be built after because it depends on js-build
all: output-clean fmt build rust-build rust-test
rsync -ha ./web-frontend/build/ build/
du -shc build/* | sort -h
# Rust test needs to be built after because the web crate depends on js-build
build: fmt js-build rust-build rust-test
rust-test:
cargo test --all
cargo fmt --all --check
rust-build:
rust-build: output-clean js-build
cargo build --all
cargo build -p web --release --target x86_64-unknown-linux-musl
earthly +rust-image
@ -24,11 +20,13 @@ js-build: wasm-build docs-build
# mkdir -p ./web-frontend/static/docs/
# rsync -ha ./build/docs/ ./web-frontend/static/docs/
yarn --cwd ./web-frontend/ build
rsync -ha ./web-frontend/build/ ./build/
output-clean:
rm -vrf build
mkdir build
docs-build:
docs-build: output-clean
earthly +docs
cargo doc --all
@ -51,5 +49,7 @@ init:
yarn --cwd ./web-frontend/
cargo fetch
cargo install wasm-pack
init-python:
if [ ! -d "wordlist/venv" ]; then python3 -m virtualenv wordlist/venv -p "$(which python3)"; fi; export OSTYPE=linux-gnu && . wordlist/venv/bin/activate
export OSTYPE=linux-gnu && . wordlist/venv/bin/activate && pip install -r wordlist/requirements.txt && python -c 'import nltk; nltk.download('wordnet')'

View File

@ -30,7 +30,7 @@
<div class="text-sm">
<a href="/" class="block inline-block text-white hover:text-gray-500 mr-4 p-2"> Home </a>
<a
href="/docs"
href="/docs/"
rel="external"
class="block inline-block text-white hover:text-gray-500 mr-4 p-2"
>

3
web/build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("cargo:rerun-if-changed=../build");
}

View File

@ -9,7 +9,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Add the API
.mount("/api/v1", routes![api::get_address, api::get_coords])
// Add the webui frontend
.mount("/", routes![static_assets::dist])
.mount("/", routes![static_assets::index, static_assets::dist])
.launch()
.await?;

View File

@ -12,6 +12,7 @@ struct Asset;
#[get("/<file..>")]
pub(crate) fn dist(file: PathBuf) -> Option<(ContentType, Cow<'static, [u8]>)> {
eprintln!("file: {file:?}");
if let Some(a) = Asset::get(&format!("{}", file.display().to_string())) {
let content_type = file
.extension()
@ -22,8 +23,13 @@ pub(crate) fn dist(file: PathBuf) -> Option<(ContentType, Cow<'static, [u8]>)> {
return Some((content_type, a.data));
}
[".html", "index.html"].iter().find_map(|ext| {
[".html", "/index.html"].iter().find_map(|ext| {
Asset::get(&format!("{}{}", file.display().to_string(), ext))
.map(|a| (ContentType::HTML, a.data))
})
}
#[get("/")]
pub(crate) fn index() -> Option<(ContentType, Cow<'static, [u8]>)> {
Asset::get(&"index.html").map(|a| (ContentType::HTML, a.data))
}