@@ -56,36 +56,44 @@ fn concat_files(
5656 files : & [ & str ] ,
5757 directory : & str ,
5858 extension : & str ,
59+ prefix : & str ,
5960) -> anyhow:: Result < String > {
6061 let mut concatted = String :: new ( ) ;
6162 for filestem in files {
62- let vendor_path = root_dir
63+ let file_path = root_dir
6364 . join ( "static" )
6465 . join ( directory)
6566 . join ( format ! ( "{filestem}.{extension}" ) ) ;
66- let contents = fs:: read_to_string ( vendor_path )
67- . with_context ( || anyhow:: anyhow!( "couldn't read vendor {extension}" ) ) ?;
67+ let contents = fs:: read_to_string ( file_path )
68+ . with_context ( || anyhow:: anyhow!( "couldn't read {prefix} {extension}" ) ) ?;
6869 concatted. push_str ( & contents) ;
6970 }
7071
71- let file_sha = format ! ( "vendor_ {}" , hash_string( & concatted) ) ;
72+ let file_sha = format ! ( "{prefix}_ {}" , hash_string( & concatted) ) ;
7273 let out_file_path = out_dir
7374 . join ( "static" )
7475 . join ( directory)
7576 . join ( format ! ( "{file_sha}.{extension}" ) ) ;
7677
7778 write_file ( Path :: new ( & out_file_path) , concatted. as_bytes ( ) )
78- . with_context ( || anyhow:: anyhow!( "couldn't write vendor {extension}" ) ) ?;
79+ . with_context ( || anyhow:: anyhow!( "couldn't write {prefix} {extension}" ) ) ?;
7980
8081 relative_url ( & out_file_path, out_dir)
8182}
8283
8384fn concat_vendor_css ( root_dir : & Path , out_dir : & Path , files : Vec < & str > ) -> anyhow:: Result < String > {
84- concat_files ( root_dir, out_dir, & files, "styles" , "css" )
85+ concat_files ( root_dir, out_dir, & files, "styles" , "css" , "vendor" )
8586}
8687
87- fn concat_app_js ( root_dir : & Path , out_dir : & Path , files : Vec < & str > ) -> anyhow:: Result < String > {
88- concat_files ( root_dir, out_dir, & files, "scripts" , "js" )
88+ fn build_js_file ( root_dir : & Path , out_dir : & Path , file : & str ) -> anyhow:: Result < String > {
89+ concat_files (
90+ root_dir,
91+ out_dir,
92+ & [ file] ,
93+ "scripts" ,
94+ "js" ,
95+ Path :: new ( file) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ,
96+ )
8997}
9098
9199#[ derive( Serialize , Debug ) ]
@@ -97,7 +105,8 @@ pub struct CSSFiles {
97105
98106#[ derive( Serialize , Debug ) ]
99107pub struct JSFiles {
100- app : String ,
108+ tools_install : String ,
109+ funding_shuffle : String ,
101110}
102111
103112#[ derive( Serialize , Debug ) ]
@@ -116,7 +125,8 @@ pub fn compile_assets(
116125 let app_css_file = compile_sass ( root_dir, out_dir, "app" , base_url) ?;
117126 let fonts_css_file = compile_sass ( root_dir, out_dir, "fonts" , base_url) ?;
118127 let vendor_css_file = concat_vendor_css ( root_dir, out_dir, vec ! [ "tachyons" ] ) ?;
119- let app_js_file = concat_app_js ( root_dir, out_dir, vec ! [ "tools-install" ] ) ?;
128+ let tools_install_js = build_js_file ( root_dir, out_dir, "tools-install" ) ?;
129+ let funding_shuffle_js = build_js_file ( root_dir, out_dir, "funding-shuffle" ) ?;
120130
121131 Ok ( AssetFiles {
122132 css : CSSFiles {
@@ -125,7 +135,8 @@ pub fn compile_assets(
125135 vendor : format ! ( "{base_url}/{vendor_css_file}" ) ,
126136 } ,
127137 js : JSFiles {
128- app : format ! ( "{base_url}/{app_js_file}" ) ,
138+ tools_install : format ! ( "{base_url}/{tools_install_js}" ) ,
139+ funding_shuffle : format ! ( "{base_url}/{funding_shuffle_js}" ) ,
129140 } ,
130141 } )
131142}
0 commit comments