@@ -109,7 +109,7 @@ fn process_release(manifest_dir: &Path, static_dir: &Path, out_dir: &Path) {
109109 fs:: write ( dist_dir. join ( "css" ) . join ( & css_name) , & css_bundle) . expect ( "write css bundle" ) ;
110110
111111 // ── 4. Minify ALL individual CSS in static-dist/ ─────────────────────────
112- minify_tree_css ( & dist_dir. join ( "css" ) , & css_name ) ;
112+ minify_tree_css ( & dist_dir. join ( "css" ) ) ;
113113
114114 // ── 5. Build JS bundle for index.html ────────────────────────────────────
115115 let index_html = fs:: read_to_string ( static_dir. join ( "index.html" ) ) . expect ( "read index.html" ) ;
@@ -120,11 +120,11 @@ fn process_release(manifest_dir: &Path, static_dir: &Path, out_dir: &Path) {
120120 fs:: write ( dist_dir. join ( "js" ) . join ( & js_name) , & js_bundle) . expect ( "write js bundle" ) ;
121121
122122 // ── 6. Minify ALL individual JS in static-dist/ ──────────────────────────
123- minify_tree_js ( & dist_dir. join ( "js" ) , & js_name ) ;
123+ minify_tree_js ( & dist_dir. join ( "js" ) ) ;
124124
125125 // ── 7. Inline theme-init.js & rewrite index.html ──────────────────────
126- let theme_init = fs :: read_to_string ( static_dir . join ( "js/core/theme-init.js" ) )
127- . unwrap_or_default ( ) ;
126+ let theme_init =
127+ fs :: read_to_string ( static_dir . join ( "js/core/theme-init.js" ) ) . unwrap_or_default ( ) ;
128128 let theme_init_min = js_minify_safe ( & theme_init) ;
129129 let rewritten_index = rewrite_index_html (
130130 & index_html,
@@ -153,9 +153,7 @@ fn process_release(manifest_dir: &Path, static_dir: &Path, out_dir: &Path) {
153153 // index.html too (future use / embedded route)
154154 fs:: write ( out_dir. join ( "index.html" ) , & rewritten_index) . expect ( "write out index.html" ) ;
155155
156- eprintln ! (
157- "cargo:warning=OxiCloud static-dist built ✓ CSS: {css_name} JS: {js_name}"
158- ) ;
156+ eprintln ! ( "cargo:warning=OxiCloud static-dist built ✓ CSS: {css_name} JS: {js_name}" ) ;
159157}
160158
161159// ═══════════════════════════════════════════════════════════════════════════════
@@ -206,8 +204,8 @@ fn css_minify_safe(source: &str) -> String {
206204fn css_minify ( source : & str ) -> Result < String , String > {
207205 use lightningcss:: stylesheet:: { ParserOptions , PrinterOptions , StyleSheet } ;
208206
209- let mut sheet = StyleSheet :: parse ( source , ParserOptions :: default ( ) )
210- . map_err ( |e| format ! ( "{e}" ) ) ?;
207+ let mut sheet =
208+ StyleSheet :: parse ( source , ParserOptions :: default ( ) ) . map_err ( |e| format ! ( "{e}" ) ) ?;
211209
212210 sheet
213211 . minify ( Default :: default ( ) )
@@ -224,12 +222,14 @@ fn css_minify(source: &str) -> Result<String, String> {
224222}
225223
226224/// Walk a directory and minify every `.css` in-place (skips generated bundles).
227- fn minify_tree_css ( dir : & Path , skip_prefix : & str ) {
228- let Ok ( entries) = fs:: read_dir ( dir) else { return } ;
225+ fn minify_tree_css ( dir : & Path ) {
226+ let Ok ( entries) = fs:: read_dir ( dir) else {
227+ return ;
228+ } ;
229229 for entry in entries. flatten ( ) {
230230 let p = entry. path ( ) ;
231231 if p. is_dir ( ) {
232- minify_tree_css ( & p, skip_prefix ) ;
232+ minify_tree_css ( & p) ;
233233 } else if p. extension ( ) . is_some_and ( |e| e == "css" ) {
234234 let fname = p. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
235235 // Skip the generated bundle and already-processed main.css
@@ -336,12 +336,14 @@ fn js_minify(source: &str) -> Result<String, String> {
336336}
337337
338338/// Walk a directory and minify every `.js` in-place (skips generated bundles).
339- fn minify_tree_js ( dir : & Path , skip_prefix : & str ) {
340- let Ok ( entries) = fs:: read_dir ( dir) else { return } ;
339+ fn minify_tree_js ( dir : & Path ) {
340+ let Ok ( entries) = fs:: read_dir ( dir) else {
341+ return ;
342+ } ;
341343 for entry in entries. flatten ( ) {
342344 let p = entry. path ( ) ;
343345 if p. is_dir ( ) {
344- minify_tree_js ( & p, skip_prefix ) ;
346+ minify_tree_js ( & p) ;
345347 } else if p. extension ( ) . is_some_and ( |e| e == "js" ) {
346348 let fname = p. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
347349 if fname. starts_with ( "app." ) {
@@ -359,13 +361,15 @@ fn minify_tree_js(dir: &Path, skip_prefix: &str) {
359361// ═══════════════════════════════════════════════════════════════════════════════
360362
361363fn minify_tree_json ( dir : & Path ) {
362- let Ok ( entries) = fs:: read_dir ( dir) else { return } ;
364+ let Ok ( entries) = fs:: read_dir ( dir) else {
365+ return ;
366+ } ;
363367 for entry in entries. flatten ( ) {
364368 let p = entry. path ( ) ;
365- if p. extension ( ) . is_some_and ( |e| e == "json" ) {
366- if let Ok ( src) = fs:: read_to_string ( & p) {
367- let _ = fs :: write ( & p , json_minify ( & src ) ) ;
368- }
369+ if p. extension ( ) . is_some_and ( |e| e == "json" )
370+ && let Ok ( src) = fs:: read_to_string ( & p)
371+ {
372+ let _ = fs :: write ( & p , json_minify ( & src ) ) ;
369373 }
370374 }
371375}
@@ -407,12 +411,7 @@ fn json_minify(source: &str) -> String {
407411// ═══════════════════════════════════════════════════════════════════════════════
408412
409413/// Rewrite index.html: single CSS bundle, inline theme-init, single JS bundle.
410- fn rewrite_index_html (
411- html : & str ,
412- css_path : & str ,
413- js_path : & str ,
414- inline_theme_js : & str ,
415- ) -> String {
414+ fn rewrite_index_html ( html : & str , css_path : & str , js_path : & str , inline_theme_js : & str ) -> String {
416415 let mut out: Vec < String > = Vec :: with_capacity ( html. lines ( ) . count ( ) ) ;
417416 let mut css_done = false ;
418417 let mut defer_done = false ;
@@ -423,29 +422,22 @@ fn rewrite_index_html(
423422 // ── Replace all stylesheet <link>s with single bundle ────────────────
424423 if t. starts_with ( "<link" ) && t. contains ( "stylesheet" ) && t. contains ( "href=\" /css/" ) {
425424 if !css_done {
426- out. push ( format ! (
427- " <link rel=\" stylesheet\" href=\" {css_path}\" >"
428- ) ) ;
425+ out. push ( format ! ( " <link rel=\" stylesheet\" href=\" {css_path}\" >" ) ) ;
429426 css_done = true ;
430427 }
431428 continue ;
432429 }
433430
434431 // ── Replace sync theme-init.js with inline <script> ─────────────────
435- if t. starts_with ( "<script" )
436- && !t. contains ( "defer" )
437- && t. contains ( "theme-init" )
438- {
432+ if t. starts_with ( "<script" ) && !t. contains ( "defer" ) && t. contains ( "theme-init" ) {
439433 out. push ( format ! ( " <script>{inline_theme_js}</script>" ) ) ;
440434 continue ;
441435 }
442436
443437 // ── Replace all defer <script>s with single bundle ──────────────────
444438 if t. starts_with ( "<script" ) && t. contains ( "defer" ) && t. contains ( "src=\" " ) {
445439 if !defer_done {
446- out. push ( format ! (
447- " <script defer src=\" {js_path}\" ></script>"
448- ) ) ;
440+ out. push ( format ! ( " <script defer src=\" {js_path}\" ></script>" ) ) ;
449441 defer_done = true ;
450442 }
451443 continue ;
0 commit comments