Skip to content

Commit

Permalink
refactor crate structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rbtying committed Apr 4, 2020
1 parent d59ea06 commit c01efe9
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
/target
**/target
.DS_Store
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 5 additions & 21 deletions Cargo.toml
@@ -1,21 +1,5 @@
[package]
name = "shengji"
version = "0.1.0"
authors = ["Robert Ying <rbtying@aeturnalus.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
dynamic = []

[dependencies]
anyhow = "1.0"
futures = { version = "0.3" }
lazy_static = "1.4.0"
rand = "0.7.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
tokio = { version = "0.2", features = ["macros"] }
warp = "0.2"
[workspace]
members = [
"core",
"backend",
]
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -20,7 +20,7 @@ with `nginx`).

```
cd frontend && yarn build
cargo run --features dynamic
cd backend && cargo run --features dynamic
```

# Technical details
Expand Down
19 changes: 19 additions & 0 deletions backend/Cargo.toml
@@ -0,0 +1,19 @@
[package]
name = "shengji"
version = "0.1.0"
authors = ["Robert Ying <rbtying@aeturnalus.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
dynamic = []

[dependencies]
futures = { version = "0.3" }
lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "0.2", features = ["macros"] }
warp = "0.2"
shengji-core = { path = "../core" }
File renamed without changes.
22 changes: 9 additions & 13 deletions src/main.rs → backend/src/main.rs
Expand Up @@ -15,11 +15,7 @@ use tokio::sync::{mpsc, Mutex};
use warp::ws::{Message, WebSocket};
use warp::Filter;

pub mod game_state;
pub mod hands;
pub mod interactive;
pub mod trick;
pub mod types;
use shengji_core::{game_state, interactive, types};

/// Our global unique user id counter.
static NEXT_USER_ID: AtomicUsize = AtomicUsize::new(1);
Expand Down Expand Up @@ -125,13 +121,13 @@ async fn main() {
});

#[cfg(feature = "dynamic")]
let index = warp::path::end().and(warp::fs::file("index.html"));
let index = warp::path::end().and(warp::fs::file("static/index.html"));
#[cfg(feature = "dynamic")]
let rules = warp::path("rules").and(warp::fs::file("rules.html"));
let rules = warp::path("rules").and(warp::fs::file("static/rules.html"));
#[cfg(feature = "dynamic")]
let js = warp::path("game.js").and(warp::fs::file("game.js"));
let js = warp::path("game.js").and(warp::fs::file("generated/game.js"));
#[cfg(feature = "dynamic")]
let css = warp::path("style.css").and(warp::fs::file("style.css"));
let css = warp::path("style.css").and(warp::fs::file("static/style.css"));

let cards = warp::path("cards.js").map(|| {
warp::http::Response::builder()
Expand Down Expand Up @@ -355,10 +351,10 @@ async fn user_disconnected(room: String, ws_id: usize, games: &Games) {
}

#[cfg(not(feature = "dynamic"))]
static INDEX_HTML: &str = include_str!("index.html");
static INDEX_HTML: &str = include_str!("../static/index.html");
#[cfg(not(feature = "dynamic"))]
static RULES_HTML: &str = include_str!("rules.html");
static RULES_HTML: &str = include_str!("../static/rules.html");
#[cfg(not(feature = "dynamic"))]
static JS: &str = include_str!("game.js");
static JS: &str = include_str!("../generated/game.js");
#[cfg(not(feature = "dynamic"))]
static CSS: &str = include_str!("style.css");
static CSS: &str = include_str!("../static/style.css");
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions core/Cargo.toml
@@ -0,0 +1,14 @@
[package]
name = "shengji-core"
version = "0.1.0"
authors = ["Robert Ying <rbtying@aeturnalus.com>"]
edition = "2018"

[dependencies]
anyhow = "1.0"
futures = { version = "0.3" }
lazy_static = "1.4.0"
rand = "0.7.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions core/src/lib.rs
@@ -0,0 +1,10 @@
#![deny(warnings)]
#![feature(async_closure)]
#![feature(const_fn)]
#![feature(const_if_match)]

pub mod game_state;
pub mod hands;
pub mod interactive;
pub mod trick;
pub mod types;
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion frontend/tsconfig.json
Expand Up @@ -13,7 +13,7 @@
"resolveJsonModule": true,
"jsx": "react",
"isolatedModules": false,
"outFile": "../src/game.js"
"outFile": "../backend/generated/game.js"
},
"include": ["src"],
"exclude": ["node_modules"]
Expand Down

0 comments on commit c01efe9

Please sign in to comment.