-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modifying build script to copy frontend to OUT_DIR and avoid building…
… the frontend.
- Loading branch information
Showing
4 changed files
with
25 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,28 @@ | ||
use std::process::Command; | ||
use std::path::{Path, PathBuf}; | ||
|
||
#[cfg(target_os = "windows")] | ||
fn build_frontend() { | ||
Command::new("powershell") | ||
.arg("-Command") | ||
.arg("yarn install") | ||
.current_dir("frontend") | ||
.output() | ||
.expect("Failed to install frontend dependencies (windows target)"); | ||
Command::new("powershell") | ||
.arg("-Command") | ||
.arg("yarn build") | ||
.current_dir("frontend") | ||
.output() | ||
.expect("Failed to build the frontend (windows target)"); | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
fn build_frontend() { | ||
Command::new("yarn") | ||
.arg("install") | ||
.current_dir("frontend") | ||
.output() | ||
.expect("Failed to install frontend dependencies (linux target)"); | ||
Command::new("yarn") | ||
.arg("build") | ||
.current_dir("frontend") | ||
.output() | ||
.expect("Failed to build the frontend (linux target)"); | ||
/// Copy files from source to destination recursively. | ||
pub fn copy_folder(source: impl AsRef<Path>, destination: impl AsRef<Path>) -> std::io::Result<()> { | ||
std::fs::create_dir_all(&destination)?; | ||
for entry in std::fs::read_dir(source)? { | ||
let entry = entry?; | ||
let filetype = entry.file_type()?; | ||
if filetype.is_dir() { | ||
copy_folder(entry.path(), destination.as_ref().join(entry.file_name()))?; | ||
} else { | ||
std::fs::copy(entry.path(), destination.as_ref().join(entry.file_name()))?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
if std::env::var("SKIP_BUILDING_FRONTEND").is_ok() { | ||
return; | ||
println!("cargo:rerun-if-changed=frontend/build"); | ||
let frontend_dist_folder = PathBuf::from("frontend/build"); | ||
if !frontend_dist_folder.exists() { | ||
eprintln!("You must build the Frontend first. please see the relevant script command in `frontend/package.json`."); | ||
} | ||
println!("cargo:rerun-if-changed=frontend/src"); | ||
eprintln!("Require yarn."); | ||
build_frontend() | ||
|
||
let frontend_dist_folder_out = | ||
PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("frontend_dist_folder"); | ||
copy_folder(frontend_dist_folder, frontend_dist_folder_out).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters