From 439b4757df52f6290ed853d9f7a8a7a4a0e8cb18 Mon Sep 17 00:00:00 2001 From: Valerio Ageno <51341197+Valerioageno@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:20:10 +0100 Subject: [PATCH] Turn `main.rs` into `app.rs` (#159) Co-authored-by: Valerio Ageno --- .../src/routes/documentation/application-state.mdx | 4 ++-- .../src/routes/documentation/tutorial/api-fetching.mdx | 4 ++-- crates/tuono/Cargo.toml | 2 +- crates/tuono/src/app.rs | 8 ++++---- crates/tuono/src/source_builder.rs | 8 ++++---- crates/tuono_lib/Cargo.toml | 4 ++-- crates/tuono_lib_macros/Cargo.toml | 2 +- examples/tuono-tutorial/src/{main.rs => app.rs} | 0 packages/fs-router-vite-plugin/package.json | 2 +- packages/lazy-fn-vite-plugin/package.json | 2 +- packages/router/package.json | 2 +- packages/tuono/package.json | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) rename examples/tuono-tutorial/src/{main.rs => app.rs} (100%) diff --git a/apps/documentation/src/routes/documentation/application-state.mdx b/apps/documentation/src/routes/documentation/application-state.mdx index 168c19e1..59de3fcf 100644 --- a/apps/documentation/src/routes/documentation/application-state.mdx +++ b/apps/documentation/src/routes/documentation/application-state.mdx @@ -14,11 +14,11 @@ import Breadcrumbs, { Element } from '../../components/breadcrumbs' The main reason Tuono is fast is that it loads just the features that are needed for the project. -To define them, you need to fill the `ApplicationState` struct in the `./src/main.rs` file, and +To define them, you need to fill the `ApplicationState` struct in the `./src/app.rs` file, and they will be automatically available in all the handlers you will define across the application. ```rs -// src/main.rs +// src/app.rs #[derive(Clone)] pub struct ApplicationState { diff --git a/apps/documentation/src/routes/documentation/tutorial/api-fetching.mdx b/apps/documentation/src/routes/documentation/tutorial/api-fetching.mdx index a83d7246..2f74b64c 100644 --- a/apps/documentation/src/routes/documentation/tutorial/api-fetching.mdx +++ b/apps/documentation/src/routes/documentation/tutorial/api-fetching.mdx @@ -70,7 +70,7 @@ Let's fix these in the next section. Compared to the common Javascript runtimes, Tuono is fast because only the features you need for your project will be loaded. -You can load them in the `ApplicationState` of your app inside the `./src/main.rs` file. This is the file that will be executed just once at the very beginning of your application. +You can load them in the `ApplicationState` of your app inside the `./src/app.rs` file. This is the file that will be executed just once at the very beginning of your application. > For the tutorial we will use [Reqwest](https://docs.rs/reqwest/latest/reqwest/) which is one of the most famous HTTP library. @@ -101,7 +101,7 @@ serde = { version = "1.0.202", features = ["derive"] } > The `Cargo.toml` is the manifest file of your application, in which you handle Rust's dependencies > (similarly as the package.json for Javascript). -Now let's define the `ApplicationState` in the `./src/main.rs` file. +Now let's define the `ApplicationState` in the `./src/app.rs` file. ```rs // Import here the just added reqwest library diff --git a/crates/tuono/Cargo.toml b/crates/tuono/Cargo.toml index d25a977a..a2112a26 100644 --- a/crates/tuono/Cargo.toml +++ b/crates/tuono/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tuono" -version = "0.14.1" +version = "0.14.2" edition = "2021" authors = ["V. Ageno "] description = "Superfast React fullstack framework" diff --git a/crates/tuono/src/app.rs b/crates/tuono/src/app.rs index d800444c..198000dc 100644 --- a/crates/tuono/src/app.rs +++ b/crates/tuono/src/app.rs @@ -20,11 +20,11 @@ const IGNORE_FILES: [&str; 1] = ["__root"]; pub struct App { pub route_map: HashMap, pub base_path: PathBuf, - pub has_main_file: bool, + pub has_app_state: bool, } -fn has_main_file(base_path: PathBuf) -> std::io::Result { - let file = File::open(base_path.join("src/main.rs"))?; +fn has_app_state(base_path: PathBuf) -> std::io::Result { + let file = File::open(base_path.join("src/app.rs"))?; let mut buf_reader = BufReader::new(file); let mut contents = String::new(); buf_reader.read_to_string(&mut contents)?; @@ -38,7 +38,7 @@ impl App { let mut app = App { route_map: HashMap::new(), base_path: base_path.clone(), - has_main_file: has_main_file(base_path).unwrap_or(false), + has_app_state: has_app_state(base_path).unwrap_or(false), }; app.collect_routes(); diff --git a/crates/tuono/src/source_builder.rs b/crates/tuono/src/source_builder.rs index 490660af..88a64233 100644 --- a/crates/tuono/src/source_builder.rs +++ b/crates/tuono/src/source_builder.rs @@ -149,8 +149,8 @@ fn generate_axum_source(app: &App, mode: Mode) -> String { .replace("/*MODE*/", mode.as_str()) .replace( "//MAIN_FILE_IMPORT//", - if app.has_main_file { - r#"#[path="../src/main.rs"] + if app.has_app_state { + r#"#[path="../src/app.rs"] mod tuono_main_state; "# } else { @@ -159,7 +159,7 @@ fn generate_axum_source(app: &App, mode: Mode) -> String { ) .replace( "//MAIN_FILE_DEFINITION//", - if app.has_main_file { + if app.has_app_state { "let user_custom_state = tuono_main_state::main();" } else { "" @@ -167,7 +167,7 @@ fn generate_axum_source(app: &App, mode: Mode) -> String { ) .replace( "//MAIN_FILE_USAGE//", - if app.has_main_file { + if app.has_app_state { ".with_state(user_custom_state)" } else { "" diff --git a/crates/tuono_lib/Cargo.toml b/crates/tuono_lib/Cargo.toml index f9e8eb1f..85a6575a 100644 --- a/crates/tuono_lib/Cargo.toml +++ b/crates/tuono_lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tuono_lib" -version = "0.14.1" +version = "0.14.2" edition = "2021" authors = ["V. Ageno "] description = "Superfast React fullstack framework" @@ -31,7 +31,7 @@ either = "1.13.0" tower-http = {version = "0.6.0", features = ["fs"]} colored = "2.1.0" -tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.14.1"} +tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.14.2"} # Match the same version used by axum tokio-tungstenite = "0.24.0" futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] } diff --git a/crates/tuono_lib_macros/Cargo.toml b/crates/tuono_lib_macros/Cargo.toml index 08fa3449..00060895 100644 --- a/crates/tuono_lib_macros/Cargo.toml +++ b/crates/tuono_lib_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tuono_lib_macros" -version = "0.14.1" +version = "0.14.2" edition = "2021" description = "Superfast React fullstack framework" homepage = "https://tuono.dev" diff --git a/examples/tuono-tutorial/src/main.rs b/examples/tuono-tutorial/src/app.rs similarity index 100% rename from examples/tuono-tutorial/src/main.rs rename to examples/tuono-tutorial/src/app.rs diff --git a/packages/fs-router-vite-plugin/package.json b/packages/fs-router-vite-plugin/package.json index a38ea897..66c5ea20 100644 --- a/packages/fs-router-vite-plugin/package.json +++ b/packages/fs-router-vite-plugin/package.json @@ -1,6 +1,6 @@ { "name": "tuono-fs-router-vite-plugin", - "version": "0.14.1", + "version": "0.14.2", "description": "Plugin for the tuono's file system router. Tuono is the react/rust fullstack framework", "homepage": "https://tuono.dev", "scripts": { diff --git a/packages/lazy-fn-vite-plugin/package.json b/packages/lazy-fn-vite-plugin/package.json index 5570c3dc..2403214d 100644 --- a/packages/lazy-fn-vite-plugin/package.json +++ b/packages/lazy-fn-vite-plugin/package.json @@ -1,6 +1,6 @@ { "name": "tuono-lazy-fn-vite-plugin", - "version": "0.14.1", + "version": "0.14.2", "description": "Plugin for the tuono's lazy fn. Tuono is the react/rust fullstack framework", "homepage": "https://tuono.dev", "scripts": { diff --git a/packages/router/package.json b/packages/router/package.json index 4a55985e..83f68d0d 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -1,6 +1,6 @@ { "name": "tuono-router", - "version": "0.14.1", + "version": "0.14.2", "description": "React routing component for the framework tuono. Tuono is the react/rust fullstack framework", "homepage": "https://tuono.dev", "scripts": { diff --git a/packages/tuono/package.json b/packages/tuono/package.json index e4c51cbc..00014316 100644 --- a/packages/tuono/package.json +++ b/packages/tuono/package.json @@ -1,6 +1,6 @@ { "name": "tuono", - "version": "0.14.1", + "version": "0.14.2", "description": "Superfast React fullstack framework", "homepage": "https://tuono.dev", "scripts": {