@@ -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,7 @@ pub struct CSSFiles {
97105
98106#[ derive( Serialize , Debug ) ]
99107pub struct JSFiles {
100- app : String ,
108+ tools_install : String ,
101109}
102110
103111#[ derive( Serialize , Debug ) ]
@@ -116,7 +124,7 @@ pub fn compile_assets(
116124 let app_css_file = compile_sass ( root_dir, out_dir, "app" , base_url) ?;
117125 let fonts_css_file = compile_sass ( root_dir, out_dir, "fonts" , base_url) ?;
118126 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" ] ) ?;
127+ let tools_install_js = build_js_file ( root_dir, out_dir, "tools-install" ) ?;
120128
121129 Ok ( AssetFiles {
122130 css : CSSFiles {
@@ -125,7 +133,7 @@ pub fn compile_assets(
125133 vendor : format ! ( "{base_url}/{vendor_css_file}" ) ,
126134 } ,
127135 js : JSFiles {
128- app : format ! ( "{base_url}/{app_js_file }" ) ,
136+ tools_install : format ! ( "{base_url}/{tools_install_js }" ) ,
129137 } ,
130138 } )
131139}
0 commit comments