Skip to content

Commit

Permalink
WIP #689
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Nov 20, 2023
1 parent 96f0720 commit 360e33f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ trace-*.json
**/.temp
.DS_Store
.cargo
server/assets_tmp
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"eslint.packageManager": "pnpm",
"eslint.quiet": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.eslint": "explicit"
},
"jest.enableInlineErrorMessages": true,
"jest.showCoverageOnLoad": true,
Expand Down
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ path = "src/bin.rs"
[build-dependencies]
static-files = "0.2"
walkdir = "2"
dircpy = "0.3.15"

[dependencies]
actix = ">= 0.12, < 0.14"
Expand Down
21 changes: 14 additions & 7 deletions server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use std::time::SystemTime;

use static_files::resource_dir;

const JS_DIST: &str = "../browser/data-browser/dist";
const JS_DIST_SOURCE: &str = "../browser/data-browser/dist";
const SRC_BROWSER: &str = "../browser/data-browser/src";
const BROWSER_ROOT: &str = "../browser/";
const JS_DIST_TMP: &str = "./assets_tmp";

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

if should_build() {
build_js()
build_js();
// copy files to server folder
dircpy::copy_dir(JS_DIST_SOURCE, JS_DIST_TMP)?;
}

resource_dir(JS_DIST)
resource_dir(JS_DIST_TMP)
.build()
.unwrap_or_else(|_| panic!("failed to open data browser assets from {}", JS_DIST));
.unwrap_or_else(|e| panic!("failed to open data browser assets from {JS_DIST_TMP}. {e}"));

Ok(())
}

/// Check if any JS files were modified since the last build
fn should_build() -> bool {
if let Ok(index_html) = std::fs::metadata(format!("{}/index.html", JS_DIST)) {
let dist_time = index_html
if !std::path::Path::new(BROWSER_ROOT).exists() {
p!("Could not find browser folder, assuming this is a `cargo publish` run. Skipping JS build.");
return false;
}
// Check if any JS files were modified since the last build
if let Ok(tmp_dist_index_html) = std::fs::metadata(format!("{}/index.html", JS_DIST_TMP)) {
let dist_time = tmp_dist_index_html
.modified()
.unwrap()
.duration_since(SystemTime::UNIX_EPOCH)
Expand Down

0 comments on commit 360e33f

Please sign in to comment.