output.rs 3.7 KB

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