Browse Source

Start refactoring Rust code into separate crates

Eric Zhang 4 years ago
parent
commit
fa3fcb5e69

+ 11 - 2
Cargo.lock

@@ -801,13 +801,22 @@ dependencies = [
 ]
 ]
 
 
 [[package]]
 [[package]]
-name = "rustpad"
+name = "rustpad-core"
+version = "0.1.0"
+dependencies = [
+ "operational-transform",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "rustpad-server"
 version = "0.1.0"
 version = "0.1.0"
 dependencies = [
 dependencies = [
  "dotenv",
  "dotenv",
  "futures",
  "futures",
  "log",
  "log",
- "operational-transform",
+ "parking_lot",
  "pretty_env_logger",
  "pretty_env_logger",
  "serde",
  "serde",
  "serde_json",
  "serde_json",

+ 5 - 18
Cargo.toml

@@ -1,19 +1,6 @@
-[package]
-name = "rustpad"
-version = "0.1.0"
-authors = ["Eric Zhang <ekzhang1@gmail.com>"]
-edition = "2018"
+[workspace]
 
 
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-dotenv = "0.15.0"
-futures = "0.3.15"
-log = "0.4.14"
-operational-transform = "0.6.0"
-pretty_env_logger = "0.4.0"
-serde = { version = "1.0.126", features = ["derive"] }
-serde_json = "1.0.64"
-tokio = { version = "1.6.1", features = ["full"] }
-tokio-stream = "0.1.6"
-warp = "0.3.1"
+members = [
+    "rustpad-server",
+    "rustpad-core",
+]

+ 2 - 5
Dockerfile

@@ -1,8 +1,5 @@
 FROM ekidd/rust-musl-builder:1.51.0 as backend
 FROM ekidd/rust-musl-builder:1.51.0 as backend
 WORKDIR /home/rust/src
 WORKDIR /home/rust/src
-COPY Cargo.toml Cargo.lock ./
-RUN mkdir src && echo "fn main() {}" > src/main.rs
-RUN cargo build --release
 COPY . .
 COPY . .
 RUN cargo test --release
 RUN cargo test --release
 RUN cargo build --release
 RUN cargo build --release
@@ -16,6 +13,6 @@ RUN npm run build
 
 
 FROM scratch
 FROM scratch
 COPY --from=frontend /usr/src/app/dist dist
 COPY --from=frontend /usr/src/app/dist dist
-COPY --from=backend /home/rust/src/target/x86_64-unknown-linux-musl/release/rustpad .
+COPY --from=backend /home/rust/src/target/x86_64-unknown-linux-musl/release/rustpad-server .
 USER 1000:1000
 USER 1000:1000
-CMD [ "./rustpad" ]
+CMD [ "./rustpad-server" ]

+ 2 - 2
index.html

@@ -2,7 +2,7 @@
 <html lang="en">
 <html lang="en">
   <head>
   <head>
     <meta charset="UTF-8" />
     <meta charset="UTF-8" />
-    <link rel="icon" type="image/svg+xml" href="/app/favicon.svg" />
+    <link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <title>Rustpad</title>
     <title>Rustpad</title>
     <meta
     <meta
@@ -19,6 +19,6 @@
   </head>
   </head>
   <body>
   <body>
     <div id="root"></div>
     <div id="root"></div>
-    <script type="module" src="/app/main.tsx"></script>
+    <script type="module" src="/src/main.tsx"></script>
   </body>
   </body>
 </html>
 </html>

+ 10 - 0
rustpad-core/Cargo.toml

@@ -0,0 +1,10 @@
+[package]
+name = "rustpad-core"
+version = "0.1.0"
+authors = ["Eric Zhang <ekzhang1@gmail.com>"]
+edition = "2018"
+
+[dependencies]
+operational-transform = "0.6.0"
+serde = { version = "1.0.126", features = ["derive"] }
+serde_json = "1.0.64"

+ 7 - 0
rustpad-core/src/lib.rs

@@ -0,0 +1,7 @@
+#[cfg(test)]
+mod tests {
+    #[test]
+    fn it_works() {
+        assert_eq!(2 + 2, 4);
+    }
+}

+ 17 - 0
rustpad-server/Cargo.toml

@@ -0,0 +1,17 @@
+[package]
+name = "rustpad-server"
+version = "0.1.0"
+authors = ["Eric Zhang <ekzhang1@gmail.com>"]
+edition = "2018"
+
+[dependencies]
+dotenv = "0.15.0"
+futures = "0.3.15"
+log = "0.4.14"
+pretty_env_logger = "0.4.0"
+serde = { version = "1.0.126", features = ["derive"] }
+serde_json = "1.0.64"
+tokio = { version = "1.6.1", features = ["full"] }
+tokio-stream = "0.1.6"
+warp = "0.3.1"
+parking_lot = "0.11.1"

+ 0 - 0
src/main.rs → rustpad-server/src/main.rs


+ 0 - 0
src/server.rs → rustpad-server/src/server.rs


+ 0 - 0
app/App.tsx → src/App.tsx


+ 0 - 0
app/css/normalize.css → src/css/normalize.css


+ 0 - 0
app/css/skeleton.css → src/css/skeleton.css


+ 0 - 0
app/favicon.svg → src/favicon.svg


+ 0 - 0
app/main.tsx → src/main.tsx


+ 0 - 0
app/vite-env.d.ts → src/vite-env.d.ts


+ 1 - 1
tsconfig.json

@@ -15,5 +15,5 @@
     "noEmit": true,
     "noEmit": true,
     "jsx": "react-jsx"
     "jsx": "react-jsx"
   },
   },
-  "include": ["app"]
+  "include": ["src"]
 }
 }