diff --git a/Cargo.toml b/Cargo.toml index 54098b89..dc95ffd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ bson = ["specta/bson"] [dependencies] specta = { version = "1.0.0", features = ["serde", "typescript"] } -httpz = { version = "0.0.4", optional = true } # TODO: Move back to crates.io release +httpz = { version = "0.0.4", optional = true } # TODO: Move back to crates.io release serde = { version = "1.0.152", features = ["derive"] } serde_json = "1.0.93" thiserror = "1.0.38" @@ -56,8 +56,4 @@ tracing = { version = "0.1.37", optional = true } async-stream = "0.3.4" [workspace] -members = [ - "./create-rspc-app", - "./examples", - "./examples/axum", -] +members = ["./examples", "./examples/axum"] diff --git a/create-rspc-app/Cargo.toml b/create-rspc-app/Cargo.toml deleted file mode 100644 index d9f4bba0..00000000 --- a/create-rspc-app/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "create-rspc-app" -version = "0.0.1" -edition = "2021" -publish = false - -[dependencies] -include_dir = "0.7.3" -requestty = "0.5.0" -strum = { version = "0.24.1", features = ["derive"] } -create-tauri-app = { git = "https://github.com/oscartbeaumont/create-tauri-app" } diff --git a/create-rspc-app/build.rs b/create-rspc-app/build.rs deleted file mode 100644 index 931b3029..00000000 --- a/create-rspc-app/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("cargo:rerun-if-changed=templates/"); -} diff --git a/create-rspc-app/src/framework.rs b/create-rspc-app/src/framework.rs deleted file mode 100644 index 3434e1b9..00000000 --- a/create-rspc-app/src/framework.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::{fs::create_dir, io, path::Path}; - -use crate::utils::replace_in_file; -use create_tauri_app::internal::{package_manager::PackageManager, template::Template}; -use include_dir::{include_dir, Dir}; -use strum::{Display, EnumIter, EnumString}; - -static AXUM_BASE_TEMPLATE: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/templates/axum_base"); -static TAURI_BASE_TEMPLATE: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/templates/tauri_base"); - -#[derive(Debug, Display, EnumIter, EnumString)] -pub enum Framework { - Axum, - Tauri, -} - -impl Framework { - pub fn render(&self, path: &Path, project_name: &str) -> io::Result<()> { - match self { - Self::Axum => { - create_dir(path).unwrap(); - AXUM_BASE_TEMPLATE.extract(path)?; - replace_in_file(path.join("Cargo.toml").as_path(), "{{name}}", project_name)?; - - println!( - "\nNow run `cd {}/ && cargo run` to get started with your new project!", - project_name - ); - } - Self::Tauri => { - // TODO: Don't hardcode Template and PackageManager - Template::ReactTs - .render(path, PackageManager::Pnpm, project_name) - .unwrap(); - - TAURI_BASE_TEMPLATE.extract(path)?; - - println!("\nNow run `cd {}/ && pnpm i && cargo tauri dev` to get started with your new project!", project_name); - } - } - - Ok(()) - } -} diff --git a/create-rspc-app/src/main.rs b/create-rspc-app/src/main.rs deleted file mode 100644 index 3102da1a..00000000 --- a/create-rspc-app/src/main.rs +++ /dev/null @@ -1,79 +0,0 @@ -use std::{env::current_dir, fs::remove_dir_all, str::FromStr}; - -use requestty::{prompt_one, Question}; -use strum::IntoEnumIterator; - -use crate::framework::Framework; - -mod framework; -mod utils; - -const BANNER: &str = r#"██████╗ ███████╗██████╗ ██████╗ -██╔══██╗██╔════╝██╔══██╗██╔════╝ -██████╔╝███████╗██████╔╝██║ -██╔══██╗╚════██║██╔═══╝ ██║ -██║ ██║███████║██║ ╚██████╗ -╚═╝ ╚═╝╚══════╝╚═╝ ╚═════╝"#; - -fn main() { - // TODO: Autoupdate - - println!("\n{}\n", BANNER); - - let project_name = prompt_one( - Question::input("project_name") - .message("What will your project be called?") - .default("my-app") - .build(), - ) - .unwrap(); - let project_name = project_name.as_string().unwrap(); - - if !project_name - .chars() - .all(|x| x.is_alphanumeric() || x == '-' || x == '_') - { - println!("Aborting your project name may only contain alphanumeric characters along with '-' and '_'..."); - } - - let path = current_dir().unwrap().join(project_name); - if path.exists() { - let force = prompt_one( - Question::confirm("force_delete") - .message(format!( - "{} directory is not empty, do you want to overwrite?", - project_name - )) - .default(false) - .build(), - ) - .unwrap(); - - match !force.as_bool().unwrap() { - true => { - println!("Aborting project creation..."); - return; - } - false => { - remove_dir_all(&path).unwrap(); - } - } - } - - let framework = prompt_one( - Question::select("framework") - .message("What framework would you like to use?") - .choices(Framework::iter().map(|v| v.to_string())) - .build(), - ) - .unwrap(); - let framework = Framework::from_str(&framework.as_list_item().unwrap().text).unwrap(); - - // TODO: Database selection - Prisma Client Rust, None - - // TODO: Frontend selection - React, SolidJS, None - - // TODO: Extras selection -> Multiselect - TailwindCSS, tracing - - framework.render(path.as_path(), project_name).unwrap(); -} diff --git a/create-rspc-app/src/utils.rs b/create-rspc-app/src/utils.rs deleted file mode 100644 index 56cd4b97..00000000 --- a/create-rspc-app/src/utils.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::{ - fs::File, - io::{self, Read, Write}, - path::Path, -}; - -pub fn replace_in_file(path: &Path, from: &str, to: &str) -> io::Result<()> { - let data = { - let mut src = File::open(path)?; - let mut data = String::new(); - src.read_to_string(&mut data)?; - data - }; - - let data = data.replace(from, to); - - { - let mut dst = File::create(path)?; - let _ = dst.write(data.as_bytes())?; - } - - Ok(()) -} diff --git a/create-rspc-app/templates/axum_base/.gitignore b/create-rspc-app/templates/axum_base/.gitignore deleted file mode 100644 index ea8c4bf7..00000000 --- a/create-rspc-app/templates/axum_base/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/create-rspc-app/templates/axum_base/Cargo.toml b/create-rspc-app/templates/axum_base/Cargo.toml deleted file mode 100644 index 9ca80033..00000000 --- a/create-rspc-app/templates/axum_base/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "{{name}}" -version = "0.1.0" -edition = "2021" - -[dependencies] -tokio = { version = "1.21.1", features = ["rt-multi-thread", "macros", "signal"] } -axum = "0.5.16" -rspc = { git = "https://github.com/oscartbeaumont/rspc", branch = "0.0.6", features = ["axum"] } diff --git a/create-rspc-app/templates/axum_base/src/api/mod.rs b/create-rspc-app/templates/axum_base/src/api/mod.rs deleted file mode 100644 index be6c5c1e..00000000 --- a/create-rspc-app/templates/axum_base/src/api/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub use rspc::RouterBuilder; - -#[derive(Clone)] -pub struct Ctx {} - -pub type Router = rspc::Router; - -pub(crate) fn new() -> RouterBuilder { - Router::new() // .query("version", |t| t(|_, _: ()| env!("CARGO_PKG_VERSION"))) -} diff --git a/create-rspc-app/templates/axum_base/src/main.rs b/create-rspc-app/templates/axum_base/src/main.rs deleted file mode 100644 index 92c60fd4..00000000 --- a/create-rspc-app/templates/axum_base/src/main.rs +++ /dev/null @@ -1,26 +0,0 @@ -use crate::api::Ctx; -use axum::routing::get; -use std::net::SocketAddr; - -mod api; -mod utils; - -fn router() -> axum::Router { - let router = api::new().build().arced(); - - axum::Router::new() - .route("/", get(|| async { "Welcome to your new rspc app!" })) - .route("/health", get(|| async { "Ok!" })) - .route("/rspc/:id", router.endpoint(|| Ctx {}).axum()) -} - -#[tokio::main] -async fn main() { - let addr = "[::]:9000".parse::().unwrap(); // This listens on IPv6 and IPv4 - println!("{} listening on http://{}", env!("CARGO_CRATE_NAME"), addr); - axum::Server::bind(&addr) - .serve(router().into_make_service()) - .with_graceful_shutdown(utils::axum_shutdown_signal()) - .await - .expect("Error with HTTP server!"); -} diff --git a/create-rspc-app/templates/axum_base/src/utils.rs b/create-rspc-app/templates/axum_base/src/utils.rs deleted file mode 100644 index 6f35af56..00000000 --- a/create-rspc-app/templates/axum_base/src/utils.rs +++ /dev/null @@ -1,28 +0,0 @@ -use tokio::signal; - -/// shutdown_signal will inform axum to gracefully shutdown when the process is asked to shutdown. -pub async fn axum_shutdown_signal() { - let ctrl_c = async { - signal::ctrl_c() - .await - .expect("failed to install Ctrl+C handler"); - }; - - #[cfg(unix)] - let terminate = async { - signal::unix::signal(signal::unix::SignalKind::terminate()) - .expect("failed to install signal handler") - .recv() - .await; - }; - - #[cfg(not(unix))] - let terminate = std::future::pending::<()>(); - - tokio::select! { - _ = ctrl_c => {}, - _ = terminate => {}, - } - - println!("signal received, starting graceful shutdown"); -} diff --git a/create-rspc-app/templates/tauri_base/src-tauri/Cargo.toml b/create-rspc-app/templates/tauri_base/src-tauri/Cargo.toml deleted file mode 100644 index d5c06ede..00000000 --- a/create-rspc-app/templates/tauri_base/src-tauri/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -name = "my-app" -version = "0.0.0" -description = "A Tauri App" -authors = ["you"] -license = "" -repository = "" -edition = "2021" -rust-version = "1.57" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[build-dependencies] -tauri-build = "1.1" - -[dependencies] -serde_json = "1.0" -serde = { version = "1.0", features = ["derive"] } -tauri = "1.1" -tokio = { version = "1.21.1", features = ["rt-multi-thread", "macros"] } -rspc = { version = "0.0.5", features = ["tauri"] } # TODO: Use crates.io release - -[features] -# by default Tauri runs in production mode -# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL -default = [ "custom-protocol" ] -# this feature is used used for production builds where `devPath` points to the filesystem -# DO NOT remove this -custom-protocol = [ "tauri/custom-protocol" ] diff --git a/create-rspc-app/templates/tauri_base/src-tauri/src/api/mod.rs b/create-rspc-app/templates/tauri_base/src-tauri/src/api/mod.rs deleted file mode 100644 index be6c5c1e..00000000 --- a/create-rspc-app/templates/tauri_base/src-tauri/src/api/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub use rspc::RouterBuilder; - -#[derive(Clone)] -pub struct Ctx {} - -pub type Router = rspc::Router; - -pub(crate) fn new() -> RouterBuilder { - Router::new() // .query("version", |t| t(|_, _: ()| env!("CARGO_PKG_VERSION"))) -} diff --git a/create-rspc-app/templates/tauri_base/src-tauri/src/main.rs b/create-rspc-app/templates/tauri_base/src-tauri/src/main.rs deleted file mode 100644 index 3affe43c..00000000 --- a/create-rspc-app/templates/tauri_base/src-tauri/src/main.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![cfg_attr( - all(not(debug_assertions), target_os = "windows"), - windows_subsystem = "windows" -)] - -use crate::api::Ctx; - -mod api; - -// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command -#[tauri::command] -fn greet(name: &str) -> String { - format!("Hello, {}! You've been greeted from Rust!", name) -} - -#[tokio::main] -async fn main() { - let router = api::new().build().arced(); - - tauri::Builder::default() - .plugin(rspc::integrations::tauri::plugin(router, || Ctx {})) - .invoke_handler(tauri::generate_handler![greet]) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); -}