Rust library to generate static websites
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: `is_dev()` export

+44 -11
+7
.sampo/changesets/jovial-firebringer-aurelien.md
··· 1 + --- 2 + packages: 3 + - maudit 4 + release: minor 5 + --- 6 + 7 + Add `is_dev()` function to allow one to toggle off things whenever running in dev
+2 -1
crates/maudit-cli/src/dev.rs
··· 25 25 // Do initial sync build 26 26 info!(name: "build", "Doing initial build…"); 27 27 let command = std::process::Command::new("cargo") 28 - .args(["run", "--quiet", "--", "--quiet"]) 28 + .args(["run", "--quiet"]) 29 + .envs([("MAUDIT_DEV", "true"), ("MAUDIT_QUIET", "true")]) 29 30 .output() 30 31 .unwrap(); 31 32 let duration = start_time.elapsed();
+6 -1
crates/maudit/src/assets/image.rs
··· 6 6 use thumbhash::{rgba_to_thumb_hash, thumb_hash_to_average_rgba, thumb_hash_to_rgba}; 7 7 8 8 use crate::assets::{Asset, InternalAsset}; 9 + use crate::is_dev; 9 10 10 11 #[derive(Clone, PartialEq, Eq, Hash)] 11 12 pub enum ImageFormat { ··· 130 131 131 132 let thumbhash_rgba = thumb_hash_to_rgba(&thumb_hash).ok().unwrap(); 132 133 let thumbhash_png = thumbhash_to_png(&thumbhash_rgba); 133 - let optimized_png = oxipng::optimize_from_memory(&thumbhash_png, &Default::default()).unwrap(); 134 + let optimized_png = if is_dev() { 135 + thumbhash_png 136 + } else { 137 + oxipng::optimize_from_memory(&thumbhash_png, &Default::default()).unwrap() 138 + }; 134 139 135 140 let base64 = base64::engine::general_purpose::STANDARD.encode(&optimized_png); 136 141 let data_uri = format!("data:image/png;base64,{}", base64);
+21 -9
crates/maudit/src/build.rs
··· 15 15 assets::{self}, 16 16 content::{Content, ContentSources}, 17 17 errors::BuildError, 18 + is_dev, 18 19 logging::print_title, 19 20 page::{DynamicRouteContext, FullPage, RenderResult, RouteContext, RouteParams, RouteType}, 20 21 route::{ ··· 71 72 .any(|entry| entry.canonicalize().unwrap().to_string_lossy() == args.id) 72 73 { 73 74 let start_tailwind = Instant::now(); 74 - let tailwind_output = 75 - Command::new(&self.tailwind_path) 76 - .args(["--input", args.id]) 77 - .arg("--minify") // TODO: Allow disabling minification 78 - .arg("--map") // TODO: Allow disabling source maps 79 - .output() 75 + let mut command = Command::new(&self.tailwind_path); 76 + command.args(["--input", args.id]); 77 + 78 + // Add minify in production, source maps in development 79 + if !crate::is_dev() { 80 + command.arg("--minify"); 81 + } 82 + if crate::is_dev() { 83 + command.arg("--map"); 84 + } 85 + 86 + let tailwind_output = command.output() 80 87 .unwrap_or_else(|e| { 81 88 // TODO: Return a proper error instead of panicking 89 + let args_str = if crate::is_dev() { 90 + format!("['--input', '{}', '--map']", args.id) 91 + } else { 92 + format!("['--input', '{}', '--minify']", args.id) 93 + }; 82 94 panic!( 83 - "Failed to execute Tailwind CSS command, is it installed and is the path to its binary correct?\nCommand: '{}', Args: ['--input', '{}', '--minify', '--map']. Error: {}", 95 + "Failed to execute Tailwind CSS command, is it installed and is the path to its binary correct?\nCommand: '{}', Args: {}. Error: {}", 84 96 &self.tailwind_path, 85 - args.id, 97 + args_str, 86 98 e 87 99 ) 88 100 }); ··· 381 393 let mut bundler = Bundler::with_plugins( 382 394 BundlerOptions { 383 395 input: Some(bundler_inputs), 384 - minify: Some(rolldown::RawMinifyOptions::Bool(true)), 396 + minify: Some(rolldown::RawMinifyOptions::Bool(!is_dev())), 385 397 dir: Some(assets_dir.to_string_lossy().to_string()), 386 398 module_types: Some(module_types_hashmap), 387 399
+8
crates/maudit/src/lib.rs
··· 59 59 use logging::init_logging; 60 60 use page::FullPage; 61 61 62 + pub fn is_dev() -> bool { 63 + if option_env!("MAUDIT_DEV") == Some("true") { 64 + return true; 65 + } 66 + 67 + env::var("MAUDIT_DEV").map(|v| v == "true").unwrap_or(false) 68 + } 69 + 62 70 #[macro_export] 63 71 /// Helps to define every route that should be build by [`coronate()`]. 64 72 ///