11use std:: { env, fs, path:: Path , path:: PathBuf , process:: Command } ;
22
33fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
4- // Check if yarn is installed
5- let yarn_check = Command :: new ( "yarn" ) . arg ( "--version" ) . status ( ) ;
6- assert ! (
7- yarn_check. is_ok( ) && yarn_check. unwrap( ) . success( ) ,
8- "yarn is not installed, please install yarn to build this project"
9- ) ;
10-
114 // Get the output directory from the cargo environment variable
125 let target_dir = env:: var ( "OUT_DIR" ) ?;
136 let manifest_dir = env:: var ( "CARGO_MANIFEST_DIR" ) ?;
@@ -18,10 +11,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1811 fs:: remove_dir_all ( out_dir) ?;
1912 }
2013
14+ let project_root = PathBuf :: from ( manifest_dir. clone ( ) ) . join ( "../../.." ) ;
15+ let hub_path = project_root. join ( "frontend/apps/hub" ) ;
16+
17+ // Build hub
2118 if std:: env:: var ( "RIVET_BUILD_HUB" ) . map_or ( false , |x| x == "1" ) {
22- // Build hub
23- let project_root = PathBuf :: from ( manifest_dir. clone ( ) ) . join ( "../../.." ) ;
24- let hub_path = project_root. join ( "frontend/apps/hub" ) ;
19+ // Check if yarn is installed
20+ let yarn_check = Command :: new ( "yarn" ) . arg ( "--version" ) . status ( ) ;
21+ assert ! (
22+ yarn_check. is_ok( ) && yarn_check. unwrap( ) . success( ) ,
23+ "yarn is not installed, please install yarn to build this project"
24+ ) ;
2525
2626 println ! ( "Running yarn install" ) ;
2727 let output = Command :: new ( "yarn" )
@@ -42,21 +42,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4242 println ! ( "stdout:\n {}" , String :: from_utf8_lossy( & output. stdout) ) ;
4343 println ! ( "stderr:\n {}" , String :: from_utf8_lossy( & output. stderr) ) ;
4444 assert ! ( output. status. success( ) , "hub build failed" ) ;
45-
46- // Copy dist directory to out_dir
47- let dist_path = hub_path. join ( "dist" ) ;
48- fs_extra:: dir:: copy (
49- dist_path. clone ( ) ,
50- out_dir,
51- & fs_extra:: dir:: CopyOptions :: new ( ) . content_only ( true ) ,
52- ) ?;
53-
54- println ! ( "cargo:rerun-if-changed={}" , hub_path. display( ) ) ;
55- println ! ( "cargo:rerun-if-env-changed=FONTAWESOME_PACKAGE_TOKEN" ) ;
56- } else {
57- // Create empty dist dir
58- std:: fs:: create_dir_all ( out_dir) ?;
5945 }
46+
47+ // Copy dist directory to out_dir
48+ let dist_path = hub_path. join ( "dist" ) ;
49+ fs_extra:: dir:: copy (
50+ dist_path. clone ( ) ,
51+ out_dir,
52+ & fs_extra:: dir:: CopyOptions :: new ( ) . content_only ( true ) ,
53+ ) ?;
54+
55+ println ! ( "cargo:rerun-if-changed={}" , hub_path. display( ) ) ;
56+ println ! ( "cargo:rerun-if-env-changed=FONTAWESOME_PACKAGE_TOKEN" ) ;
6057
6158 // Set the path in the env
6259 println ! ( "cargo:rustc-env=HUB_PATH={}" , out_dir. display( ) ) ;
0 commit comments