Skip to content

Commit fa3e3d3

Browse files
committed
WIP #689
1 parent ddecf1a commit fa3e3d3

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ trace-*.json
55
.DS_Store
66
.cargo
77
artifact
8+
server/assets_tmp
89

910
# Local Netlify folder
1011
.netlify

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ path = "src/bin.rs"
1717
[build-dependencies]
1818
static-files = "0.2"
1919
walkdir = "2"
20+
dircpy = "0.3.15"
2021

2122
[dependencies]
2223
actix = ">= 0.12, < 0.14"

server/build.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use std::time::SystemTime;
22

33
use static_files::resource_dir;
44

5-
const JS_DIST: &str = "../browser/data-browser/dist";
5+
const JS_DIST_SOURCE: &str = "../browser/data-browser/dist";
66
const SRC_BROWSER: &str = "../browser/data-browser/src";
77
const BROWSER_ROOT: &str = "../browser/";
8+
const JS_DIST_TMP: &str = "./assets_tmp";
89

910
macro_rules! p {
1011
($($tokens: tt)*) => {
@@ -16,20 +17,26 @@ fn main() -> std::io::Result<()> {
1617
println!("cargo:rerun-if-changed={}", BROWSER_ROOT);
1718

1819
if should_build() {
19-
build_js()
20+
build_js();
21+
// copy files to server folder
22+
dircpy::copy_dir(JS_DIST_SOURCE, JS_DIST_TMP)?;
2023
}
2124

22-
resource_dir(JS_DIST)
25+
resource_dir(JS_DIST_TMP)
2326
.build()
24-
.unwrap_or_else(|_| panic!("failed to open data browser assets from {}", JS_DIST));
27+
.unwrap_or_else(|e| panic!("failed to open data browser assets from {JS_DIST_TMP}. {e}"));
2528

2629
Ok(())
2730
}
2831

29-
/// Check if any JS files were modified since the last build
3032
fn should_build() -> bool {
31-
if let Ok(index_html) = std::fs::metadata(format!("{}/index.html", JS_DIST)) {
32-
let dist_time = index_html
33+
if !std::path::Path::new(BROWSER_ROOT).exists() {
34+
p!("Could not find browser folder, assuming this is a `cargo publish` run. Skipping JS build.");
35+
return false;
36+
}
37+
// Check if any JS files were modified since the last build
38+
if let Ok(tmp_dist_index_html) = std::fs::metadata(format!("{}/index.html", JS_DIST_TMP)) {
39+
let dist_time = tmp_dist_index_html
3340
.modified()
3441
.unwrap()
3542
.duration_since(SystemTime::UNIX_EPOCH)

0 commit comments

Comments
 (0)