output.rs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. use crate::server::Diagnostic;
  2. use colored::Colorize;
  3. use dioxus_cli_config::{crate_root, CrateConfig};
  4. use std::{path::PathBuf, process::Command};
  5. #[derive(Debug, Default)]
  6. pub struct PrettierOptions {
  7. pub changed: Vec<PathBuf>,
  8. pub warnings: Vec<Diagnostic>,
  9. pub elapsed_time: u128,
  10. }
  11. #[derive(Debug, Clone)]
  12. pub struct WebServerInfo {
  13. pub ip: String,
  14. pub port: u16,
  15. }
  16. pub fn print_console_info(
  17. config: &CrateConfig,
  18. options: PrettierOptions,
  19. web_info: Option<WebServerInfo>,
  20. ) {
  21. // Don't clear the screen if the user has set the DIOXUS_LOG environment variable to "trace" so that we can see the logs
  22. if Some("trace") != std::env::var("DIOXUS_LOG").ok().as_deref() {
  23. if let Ok(native_clearseq) = Command::new(if cfg!(target_os = "windows") {
  24. "cls"
  25. } else {
  26. "clear"
  27. })
  28. .output()
  29. {
  30. print!("{}", String::from_utf8_lossy(&native_clearseq.stdout));
  31. } else {
  32. // Try ANSI-Escape characters
  33. print!("\x1b[2J\x1b[H");
  34. }
  35. }
  36. let mut profile = if config.release { "Release" } else { "Debug" }.to_string();
  37. if config.custom_profile.is_some() {
  38. profile = config.custom_profile.as_ref().unwrap().to_string();
  39. }
  40. let hot_reload = if config.hot_reload { "RSX" } else { "Normal" };
  41. let crate_root = crate_root().unwrap();
  42. let custom_html_file = if crate_root.join("index.html").is_file() {
  43. "Custom [index.html]"
  44. } else {
  45. "None"
  46. };
  47. let url_rewrite = if config.dioxus_config.web.watcher.index_on_404 {
  48. "True"
  49. } else {
  50. "False"
  51. };
  52. let proxies = &config.dioxus_config.web.proxy;
  53. if options.changed.is_empty() {
  54. println!(
  55. "{} @ v{} [{}]",
  56. "Dioxus".bold().green(),
  57. clap::crate_version!(),
  58. chrono::Local::now().format("%H:%M:%S").to_string().dimmed()
  59. );
  60. } else {
  61. println!(
  62. "Project Reloaded: {}\n",
  63. format!(
  64. "Changed {} files. [{}]",
  65. options.changed.len(),
  66. chrono::Local::now().format("%H:%M:%S").to_string().dimmed()
  67. )
  68. .purple()
  69. .bold()
  70. );
  71. }
  72. if let Some(WebServerInfo { ip, port }) = web_info {
  73. if config.dioxus_config.web.https.enabled == Some(true) {
  74. println!(
  75. " > Local address: {}",
  76. format!("https://localhost:{}/", port).blue()
  77. );
  78. println!(
  79. " > Network address: {}",
  80. format!("https://{}:{}/", ip, port).blue()
  81. );
  82. println!(" > HTTPS: {}", "Enabled".to_string().green());
  83. } else {
  84. println!(
  85. " > Local address: {}",
  86. format!("http://localhost:{}/", port).blue()
  87. );
  88. println!(
  89. " > Network address: {}",
  90. format!("http://{}:{}/", ip, port).blue()
  91. );
  92. println!(" > HTTPS status: {}", "Disabled".to_string().red());
  93. }
  94. }
  95. println!();
  96. println!(" > Hot Reload Mode: {}", hot_reload.cyan());
  97. if !proxies.is_empty() {
  98. println!(" > Proxies :");
  99. for proxy in proxies {
  100. println!(" - {}", proxy.backend.blue());
  101. }
  102. }
  103. println!(" > Custom index.html: {}", custom_html_file.green());
  104. println!(" > Serve index.html on 404: {}", url_rewrite.purple());
  105. println!();
  106. println!(
  107. " > Build Features: [ {} ]",
  108. config
  109. .features
  110. .clone()
  111. .unwrap_or_default()
  112. .join(", ")
  113. .green()
  114. );
  115. println!(" > Build Profile: {}", profile.green());
  116. println!(
  117. " > Build took: {} millis",
  118. options.elapsed_time.to_string().green().bold()
  119. );
  120. println!();
  121. if options.warnings.is_empty() {
  122. log::info!("{}\n", "A perfect compilation!".green().bold());
  123. } else {
  124. log::warn!(
  125. "{}",
  126. format!(
  127. "There were {} warning messages during the build. Run `cargo check` to see them.",
  128. options.warnings.len() - 1
  129. )
  130. .yellow()
  131. .bold()
  132. );
  133. }
  134. }