main.rs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #![doc = include_str!("../README.md")]
  2. #![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
  3. #![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
  4. #![cfg_attr(docsrs, feature(doc_cfg))]
  5. mod build;
  6. mod bundle_utils;
  7. mod cli;
  8. mod config;
  9. mod dioxus_crate;
  10. mod dx_build_info;
  11. mod error;
  12. mod fastfs;
  13. mod filemap;
  14. mod logging;
  15. mod metadata;
  16. mod platform;
  17. mod rustc;
  18. mod serve;
  19. mod settings;
  20. mod wasm_bindgen;
  21. mod wasm_opt;
  22. pub(crate) use build::*;
  23. pub(crate) use cli::*;
  24. pub(crate) use config::*;
  25. pub(crate) use dioxus_crate::*;
  26. pub(crate) use dioxus_dx_wire_format::*;
  27. pub(crate) use error::*;
  28. pub(crate) use filemap::*;
  29. pub(crate) use logging::*;
  30. pub(crate) use platform::*;
  31. pub(crate) use rustc::*;
  32. pub(crate) use settings::*;
  33. #[tokio::main]
  34. async fn main() {
  35. // If we're being ran as a linker (likely from ourselves), we want to act as a linker instead.
  36. if let Some(link_action) = link::LinkAction::from_env() {
  37. return link_action.run();
  38. }
  39. let args = TraceController::initialize();
  40. let result = match args.action {
  41. Commands::Translate(opts) => opts.translate(),
  42. Commands::New(opts) => opts.create(),
  43. Commands::Init(opts) => opts.init(),
  44. Commands::Config(opts) => opts.config(),
  45. Commands::Autoformat(opts) => opts.autoformat(),
  46. Commands::Check(opts) => opts.check().await,
  47. Commands::Clean(opts) => opts.clean().await,
  48. Commands::Build(opts) => opts.run_cmd().await,
  49. Commands::Serve(opts) => opts.serve().await,
  50. Commands::Bundle(opts) => opts.bundle().await,
  51. Commands::Run(opts) => opts.run().await,
  52. };
  53. // Provide a structured output for third party tools that can consume the output of the CLI
  54. match result {
  55. Ok(output) => {
  56. tracing::debug!(json = ?output);
  57. }
  58. Err(err) => {
  59. tracing::error!(
  60. ?err,
  61. json = ?StructuredOutput::Error {
  62. message: format!("{err:?}"),
  63. },
  64. );
  65. std::process::exit(1);
  66. }
  67. };
  68. }