Skip to content

Commit

Permalink
build process change + review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
archeoss committed Oct 5, 2023
1 parent 2bbccfc commit 387d9b8
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Bob Management GUI changelog
#### Added

- Initial project structure (#1)
- Initial project stricture, frontend (#10)
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,35 @@ Management UI for Bob

## Commands

Build backend server:

```sh
cargo build-backend
```

Run backend server:

```sh
cargo run-backend
```

Build frontend and move it into the backend's executable directory:

```sh
cargo build-frontend
```

---

Run debug build:
Run debug build (Backend + Frontend):

```sh
cargo run -- --default
```

---

Make release build:
Make release build (Backend + Frontend):

```sh
cargo build --profile=release-lto
Expand Down
6 changes: 4 additions & 2 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "backend"
default-run = "backend"
build = "../build.rs"
description = "Bob Management GUI: Backend"
publish = false
keywords = [ "BOB", "Management", "GUI" ]
Expand Down Expand Up @@ -43,7 +42,10 @@ utoipa-rapidoc = { version = "0.1", features = ["axum"], optional = true }
## CLI
cli = { path = "../cli" }

## Frontend
frontend = { path = "../frontend", optional = true }

[features]
default = [ "swagger", "frontend-bundle" ]
swagger = [ "dep:utoipa", "dep:utoipa-swagger-ui" , "dep:utoipa-redoc", "dep:utoipa-rapidoc" ]
frontend-bundle = [ ]
frontend-bundle = [ "dep:frontend" ]
1 change: 1 addition & 0 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn init_tracer(_log_file: &Option<PathBuf>, trace_level: Level) {
fn router(cors: CorsLayer) -> Router {
let mut frontend = env::current_exe().expect("Couldn't get current executable path.");
frontend.pop();
frontend.pop();
frontend.push("dist");
tracing::info!("serving frontend at: {frontend:?}");
// Add api
Expand Down
31 changes: 0 additions & 31 deletions build.rs

This file was deleted.

23 changes: 23 additions & 0 deletions frontend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ pub fn build_frontend() {
// Only build frontend when building a release
// #[cfg(not(debug_assertions))]
shell("yarn build");

let mut dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); // OUT_DIR == <project_dir>/target/<traget_profile>/build/bob_management-<HASH>/out
dir.pop();
dir.pop();
dir.pop();
dir.pop();
let mut project_dir = dir.clone();
project_dir.pop();
println!("cargo:warning=Moving /dist to: {dir:?}");
println!("cargo:warning=PROJECT DIR: {project_dir:?}");
println!(
"cargo:warning=cp: {:?}",
Command::new("cp")
.args([
"-rf",
&format!("{}/frontend/dist", project_dir.to_string_lossy()),
dir.to_str().unwrap()
])
.output()
.expect("Couldn't move frontend build artifacts")
);
// println!("cargo:rerun-if-changed=frontend");
println!("cargo:rerun-if-changed=NULL");
}

#[allow(dead_code)]
Expand Down

0 comments on commit 387d9b8

Please sign in to comment.