Skip to content

Commit e9f32ac

Browse files
committed
8.1.0 fixes
1 parent 9653671 commit e9f32ac

File tree

26 files changed

+558
-586
lines changed

26 files changed

+558
-586
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<a href="https://crates.io/crates/create-rust-app"><img src="https://img.shields.io/crates/v/create-rust-app.svg?style=for-the-badge" height="20" alt="License: MIT OR Apache-2.0" /></a>
44

5-
Set up a modern rust+react web app by running one command.
5+
Set up a modern rust+react web app by running one command. [Join us on discord](https://discord.gg/tm6Ey33ZPN).
66

77
[create-rust-app.dev](https://create-rust-app.dev)
88

@@ -15,7 +15,7 @@ Set up a modern rust+react web app by running one command.
1515
- Note that for SQLite, if you don't wish to dynamically link `diesel_cli` with your system's `libsqlite3`, you may run `cargo install diesel_cli --no-default-features --features sqlite-bundled`.
1616
- Stable rust
1717
- ```rustup install stable``` (nightly is fine too)
18-
18+
1919
# Install
2020

2121
```sh
@@ -47,6 +47,7 @@ $ create-rust-app <project_name>
4747
- Rust backend
4848
- One of the following frameworks: `actix-web`, `poem` or let us know which one you want to use!
4949
- Database migrations (using diesel.rs)
50+
- Generate diesel structs and types by running `cargo dsync` in your project (see codegen section below).
5051
- Sending mail
5152
- PostgreSQL, SQLite 3.35+ support
5253
- ViteJS (blazing fast frontend compile speeds)
@@ -56,7 +57,7 @@ $ create-rust-app <project_name>
5657
- Automatically route to your single page application(s)
5758
- Use `create_rust_app::render_single_page_application("/app","your_spa.html")`
5859
- React frontend (or install your own framework!)
59-
- Typescript, with backend type definition generation (via `tsync`)
60+
- Typescript, with backend type definition generation (run `cargo tsync` in your project folder; see codegen section below)
6061
- Routing (via `react-router-dom`)
6162
- Typed `react-query` hooks generation (`$ cd my_project && create-rust-app`, then select "Generate react-query hooks")
6263

@@ -110,6 +111,19 @@ $ create-rust-app <project_name>
110111

111112

112113
### 2. Code-gen to reduce boilerplate
114+
115+
````
116+
$ cargo dsync
117+
````
118+
119+
* Run this commmand to generate diesel model structs and queries in your `backend/models` folder!
120+
121+
```
122+
$ cargo tsync
123+
```
124+
125+
* Run this command to generate typescript types for your rust code marked with `#[tsync::tsync]`. You'll find the output for this command here: `frontend/src/types/rust.d.ts`.
126+
113127
```
114128
$ cd my_project && create-rust-app
115129
```
@@ -123,8 +137,11 @@ $ cd my_project && create-rust-app
123137
124138
[![Gif](docs/create-rust-app-v2.gif)](https://github.com/Wulf/create-rust-app/blob/main/docs/create-rust-app-v2.mp4)
125139
140+
* This video is a little outdated
141+
126142
# Contributing
127143
128144
Questions and comments are welcome in the issues section!
129145
130146
If you're experiencing slow compilation time, make sure there isn't any bloat in the template files (look for `node_modules` or typescript / parcel caches and delete them).
147+
Moreover, you can try using the [mold](https://github.com/rui314/mold) linker which may also improve compilation times.

create-rust-app/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "create-rust-app"
33
description = "Set up a modern rust+react web app by running one command."
4-
version = "8.0.2"
4+
version = "8.1.0"
55
edition = "2018"
66
authors = ["Haris <[email protected]>"]
77
readme = "../README.md"
@@ -48,7 +48,6 @@ aws-config = { optional=true, version="0.8.0" }
4848
aws-types = { optional=true, version="0.8.0" }
4949
aws-endpoint = { optional=true, version="0.8.0" }
5050
aws-sdk-s3 = { optional=true, version="0.8.0" }
51-
tokio = { optional=true, version = "1", features = ["full"] }
5251
futures-util = { optional=true, version="0.3.21" }
5352
http = { optional=true, version="0.2.6" }
5453
diesel_derives = { optional=true, version="1.4.1" }
@@ -78,6 +77,7 @@ env_logger = { optional=true, version= "0.9.0" }
7877

7978
mime_guess = { optional=true, version="2.0.4" } # backend_poem, plugin_storage
8079
anyhow = { optional=true, version="1.0.57" } # backend_poem, plugin_auth
80+
tokio = { optional=true, version = "1", features = ["full"] } # backend_poem, plugin-storage
8181

8282
[features]
8383
default = ["backend_actix-web", "database_postgres", "plugin_auth", "plugin_container", "plugin_dev", "plugin_graphql", "plugin_storage"]
@@ -86,7 +86,7 @@ plugin_container = []
8686
plugin_auth = ["anyhow", "argonautica", "jsonwebtoken", "chrono", "tsync"]
8787
plugin_storage = [ "aws-config", "aws-types", "aws-endpoint", "aws-sdk-s3", "tokio", "futures-util", "http", "diesel_derives", "uuid", "md5", "mime_guess", "base64" ]
8888
plugin_graphql = []
89-
backend_poem = ["poem", "anyhow", "mime_guess"]
89+
backend_poem = ["poem", "anyhow", "mime_guess", "tokio"]
9090
backend_actix-web = ["actix-web", "actix-http", "actix-files", "actix-multipart", "actix-web-httpauth","derive_more", "futures", "env_logger"]
9191
database_sqlite = ["diesel/sqlite", "libsqlite3-sys/bundled"]
9292
database_postgres = ["diesel/postgres"]

create-rust-app/src/database.rs renamed to create-rust-app/src/database/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ impl Database {
2727
pool: database_pool,
2828
}
2929
}
30+
31+
pub fn get_connection(&self) -> Connection {
32+
self.pool.get().unwrap()
33+
}
3034
}

create-rust-app/src/util/poem_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use http::{StatusCode, Uri};
1+
use poem::http::{StatusCode, Uri};
22
use poem::middleware::{AddData, AddDataEndpoint};
33
use poem::web::Data;
44
use poem::{handler, Body, EndpointExt, IntoResponse, Response, Route};

create-rust-app_cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "create-rust-app_cli"
33
description = "Set up a modern rust+react web app by running one command."
4-
version = "8.0.2"
4+
version = "8.1.0"
55
authors = ["Haris <[email protected]>"]
66
edition = "2018"
77
readme = "../README.md"
@@ -20,7 +20,7 @@ indoc = "1.0.3"
2020
rust-embed = "5.9.0"
2121
structopt = "0.3.22"
2222
toml = "0.5.8"
23-
tsync = "1.2.1"
23+
tsync = "1"
2424

2525
# check cli version
2626
update-informer = "0.5.0"

create-rust-app_cli/src/content/project.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct Asset;
4141
// version.to_string()
4242
// }
4343
fn get_current_cra_lib_version() -> String {
44-
"8.0.2".to_string()
44+
"8".to_string()
4545
}
4646

4747
fn add_bins_to_cargo_toml(project_dir: &std::path::PathBuf) -> Result<(), std::io::Error> {
@@ -87,6 +87,10 @@ path = ".cargo/bin/fullstack.rs"
8787
name = "tsync"
8888
path = ".cargo/bin/tsync.rs"
8989
90+
[[bin]]
91+
name = "dsync"
92+
path = ".cargo/bin/dsync.rs"
93+
9094
[[bin]]
9195
name = "{project_name}"
9296
path = "backend/main.rs"
@@ -344,7 +348,9 @@ pub fn create(project_name: &str, creation_options: CreationOptions) -> Result<(
344348
"chrono",
345349
r#"chrono = { version = "0.4.19", features = ["serde"] }"#,
346350
)?;
347-
add_dependency(&project_dir, "tsync", r#"tsync = "1.2.1""#)?;
351+
// todo: move these deps to the helper crate (./create-rust-app/Cargo.toml) behind feature flags
352+
add_dependency(&project_dir, "tsync", r#"tsync = "1""#)?;
353+
add_dependency(&project_dir, "dsync", r#"dsync = "0""#)?;
348354
add_dependency(
349355
&project_dir,
350356
"diesel",
@@ -418,6 +424,37 @@ pub fn create(project_name: &str, creation_options: CreationOptions) -> Result<(
418424
std::fs::write(env_file, contents.clone())?;
419425
}
420426

427+
/*
428+
Initial code gen (dsync, tsync)
429+
*/
430+
logger::command_msg("cargo dsync");
431+
432+
let cargo_dsync = std::process::Command::new("cargo")
433+
.current_dir(&project_dir)
434+
.arg("dsync")
435+
.stdout(std::process::Stdio::null())
436+
.status()
437+
.expect("failed to execute process");
438+
439+
if !cargo_dsync.success() {
440+
logger::error("failed to execute process");
441+
std::process::exit(1);
442+
}
443+
444+
logger::command_msg("cargo tsync");
445+
446+
let cargo_tsync = std::process::Command::new("cargo")
447+
.current_dir(&project_dir)
448+
.arg("tsync")
449+
.stdout(std::process::Stdio::null())
450+
.status()
451+
.expect("failed to execute process");
452+
453+
if !cargo_tsync.success() {
454+
logger::error("failed to execute process");
455+
std::process::exit(1);
456+
}
457+
421458
/*
422459
Finalize; create the initial commit.
423460
*/

0 commit comments

Comments
 (0)