Skip to content

Commit 7d49b47

Browse files
committed
8.1.0 fixes
1 parent bd256ac commit 7d49b47

File tree

27 files changed

+584
-586
lines changed

27 files changed

+584
-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

@@ -14,7 +14,7 @@ Set up a modern rust+react web app by running one command.
1414
- Instructions [here](http://diesel.rs/guides/getting-started#installing-diesel-cli)
1515
- Stable rust
1616
- ```rustup install stable``` (nightly is fine too)
17-
17+
1818
# Install
1919

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

@@ -109,6 +110,19 @@ $ create-rust-app <project_name>
109110

110111

111112
### 2. Code-gen to reduce boilerplate
113+
114+
````
115+
$ cargo dsync
116+
````
117+
118+
* Run this commmand to generate diesel model structs and queries in your `backend/models` folder!
119+
120+
```
121+
$ cargo tsync
122+
```
123+
124+
* 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`.
125+
112126
```
113127
$ cd my_project && create-rust-app
114128
```
@@ -122,8 +136,11 @@ $ cd my_project && create-rust-app
122136
123137
[![Gif](docs/create-rust-app-v2.gif)](https://github.com/Wulf/create-rust-app/blob/main/docs/create-rust-app-v2.mp4)
124138
139+
* This video is a little outdated
140+
125141
# Contributing
126142
127143
Questions and comments are welcome in the issues section!
128144
129145
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).
146+
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"
@@ -41,7 +41,6 @@ aws-config = { optional=true, version="0.8.0" }
4141
aws-types = { optional=true, version="0.8.0" }
4242
aws-endpoint = { optional=true, version="0.8.0" }
4343
aws-sdk-s3 = { optional=true, version="0.8.0" }
44-
tokio = { optional=true, version = "1", features = ["full"] }
4544
futures-util = { optional=true, version="0.3.21" }
4645
http = { optional=true, version="0.2.6" }
4746
diesel_derives = { optional=true, version="1.4.1" }
@@ -72,6 +71,7 @@ env_logger = { optional=true, version= "0.9.0" }
7271

7372
mime_guess = { optional=true, version="2.0.4" } # backend_poem, plugin_storage
7473
anyhow = { optional=true, version="1.0.57" } # backend_poem, plugin_auth
74+
tokio = { optional=true, version = "1", features = ["full"] } # backend_poem, plugin-storage
7575

7676
[features]
7777
default = ["backend_actix-web", "database_postgres", "plugin_auth", "plugin_container", "plugin_dev", "plugin_graphql", "plugin_storage"]
@@ -80,7 +80,7 @@ plugin_container = []
8080
plugin_auth = ["anyhow", "argonautica", "jsonwebtoken", "chrono", "tsync"]
8181
plugin_storage = [ "aws-config", "aws-types", "aws-endpoint", "aws-sdk-s3", "tokio", "futures-util", "http", "diesel_derives", "uuid", "md5", "mime_guess", "base64" ]
8282
plugin_graphql = []
83-
backend_poem = ["poem", "anyhow", "mime_guess"]
83+
backend_poem = ["poem", "anyhow", "mime_guess", "tokio"]
8484
backend_actix-web = ["actix-web", "actix-http", "actix-files", "actix-multipart", "actix-web-httpauth","derive_more", "futures", "env_logger"]
8585
database_sqlite = ["diesel/sqlite"]
8686
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"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM rust:alpine
2+
3+
RUN apt-get update -y
4+
RUN apt-get install -y nodejs npm
5+
6+
RUN npm i -g yarn
7+
RUN cargo install diesel_cli --no-default-features --features
8+
RUN cargo install tsync
9+
10+
# You can remove the next RUN step if you're not using the Create Rust App 'auth' plugin
11+
# For the argonautica crate, we need to install LLVM/Clang v3.9 or higher
12+
RUN apt-get install -y clang llvm-dev libclang-dev
13+
14+
# Since the official rust image doesn't have nightly variants, we're going to install it ourselves
15+
# This will make the image bigger than it needs to be -- you can try using another image if this is important to you
16+
RUN rustup update nightly;
17+
RUN rustup default nightly;
18+
19+
WORKDIR /app
20+
COPY . .
21+
22+
RUN cargo build --release
23+
24+
EXPOSE 3000
25+
26+
CMD ["cargo", "run", "--release"]

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)