Skip to content

Commit 0022dc5

Browse files
feat: build frontend artifacts in OUT_DIR (#154)
1 parent 4509db6 commit 0022dc5

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 0.12.1 (2025-11-11)
44

5+
- Fixed release workflow by storing frontend artifacts in `OUT_DIR` (([#154](https://github.com/0xMiden/miden-faucet/pull/154))).
56
- Added `api-public-url` CLI param to fix the backend and frontend communication ([#153](https://github.com/0xMiden/miden-faucet/pull/153)).
67

78
## 0.12.0 (2025-11-10)

bin/faucet/build.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
1+
use std::path::Path;
12
use std::process::Command;
3+
use std::{env, fs};
24

35
fn main() {
46
println!("cargo:rerun-if-changed=frontend/index.js");
57
println!("cargo:rerun-if-changed=frontend/package.json");
68
println!("cargo:rerun-if-changed=frontend/package-lock.json");
79

10+
let build_dir = env::var("OUT_DIR").expect("OUT_DIR should be set");
11+
let target_dir = Path::new(&build_dir).join("frontend");
12+
13+
fs::create_dir_all(&target_dir).expect("target directory should be created");
14+
copy_dir_all(Path::new("frontend"), &target_dir)
15+
.expect("frontend directory should be copied to target directory");
16+
817
let npm_install = Command::new("npm")
918
.arg("install")
10-
.current_dir("frontend")
19+
.current_dir(&target_dir)
1120
.status()
12-
.expect("Failed to execute npm install");
21+
.expect("npm install should succeed");
1322

1423
assert!(npm_install.success(), "npm install failed");
1524

1625
let npm_build = Command::new("npm")
1726
.arg("run")
1827
.arg("build")
19-
.current_dir("frontend")
28+
.current_dir(&target_dir)
2029
.status()
21-
.expect("Failed to execute npm run build");
30+
.expect("npm run build should succeed");
2231

2332
assert!(npm_build.success(), "npm run build failed");
2433
}
34+
35+
/// Copy all files from source directory to destination directory. Skips inner directories.
36+
fn copy_dir_all(src: &Path, dst: &Path) -> std::io::Result<()> {
37+
for entry in fs::read_dir(src)? {
38+
let entry = entry?;
39+
if entry.file_type()?.is_file() {
40+
fs::copy(entry.path(), dst.join(entry.file_name()))?;
41+
}
42+
}
43+
Ok(())
44+
}

bin/faucet/src/frontend.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,52 +47,52 @@ pub async fn serve_frontend(url: Url, api_public_url: Url, node_url: String) ->
4747
}
4848

4949
pub async fn get_index_html() -> Html<&'static str> {
50-
Html(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/frontend/index.html")))
50+
Html(include_str!(concat!(env!("OUT_DIR"), "/frontend/index.html")))
5151
}
5252

5353
pub async fn get_miden_client_web_wasm() -> Response {
5454
(
5555
[(header::CONTENT_TYPE, header::HeaderValue::from_static("application/wasm"))],
5656
include_bytes!(concat!(
57-
env!("CARGO_MANIFEST_DIR"),
57+
env!("OUT_DIR"),
5858
"/frontend/node_modules/@demox-labs/miden-sdk/dist/assets/miden_client_web.wasm"
5959
),),
6060
)
6161
.into_response()
6262
}
6363

6464
pub async fn get_not_found_html() -> Html<&'static str> {
65-
Html(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/frontend/not_found.html")))
65+
Html(include_str!(concat!(env!("OUT_DIR"), "/frontend/not_found.html")))
6666
}
6767

6868
pub async fn get_bundle_js() -> JavaScript<&'static str> {
69-
JavaScript(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/frontend/bundle.js")))
69+
JavaScript(include_str!(concat!(env!("OUT_DIR"), "/frontend/bundle.js")))
7070
}
7171

7272
pub async fn get_index_css() -> Css<&'static str> {
73-
Css(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/frontend/index.css")))
73+
Css(include_str!(concat!(env!("OUT_DIR"), "/frontend/index.css")))
7474
}
7575

7676
pub async fn get_background() -> Response {
7777
(
7878
[(header::CONTENT_TYPE, header::HeaderValue::from_static("image/png"))],
79-
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/frontend/background.png"),),
79+
include_bytes!(concat!(env!("OUT_DIR"), "/frontend/background.png"),),
8080
)
8181
.into_response()
8282
}
8383

8484
pub async fn get_wallet_icon() -> Response {
8585
(
8686
[(header::CONTENT_TYPE, header::HeaderValue::from_static("image/png"))],
87-
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/frontend/wallet-icon.png"),),
87+
include_bytes!(concat!(env!("OUT_DIR"), "/frontend/wallet-icon.png"),),
8888
)
8989
.into_response()
9090
}
9191

9292
pub async fn get_favicon() -> Response {
9393
(
9494
[(header::CONTENT_TYPE, header::HeaderValue::from_static("image/x-icon"))],
95-
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/frontend/favicon.ico"),),
95+
include_bytes!(concat!(env!("OUT_DIR"), "/frontend/favicon.ico"),),
9696
)
9797
.into_response()
9898
}

0 commit comments

Comments
 (0)