Browse Source

Create css/js folders and copy them right into /public

master
Dylan Baker 5 years ago
parent
commit
38a55e6f2f
3 changed files with 29 additions and 1 deletions
  1. 7
    0
      Cargo.lock
  2. 1
    0
      Cargo.toml
  3. 21
    1
      src/main.rs

+ 7
- 0
Cargo.lock View File

@@ -77,6 +77,11 @@ name = "entities"
77 77
 version = "1.0.1"
78 78
 source = "registry+https://github.com/rust-lang/crates.io-index"
79 79
 
80
+[[package]]
81
+name = "fs_extra"
82
+version = "1.1.0"
83
+source = "registry+https://github.com/rust-lang/crates.io-index"
84
+
80 85
 [[package]]
81 86
 name = "fuchsia-zircon"
82 87
 version = "0.3.3"
@@ -244,6 +249,7 @@ version = "0.1.0"
244 249
 dependencies = [
245 250
  "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
246 251
  "comrak 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
252
+ "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
247 253
  "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
248 254
  "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
249 255
  "uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -334,6 +340,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
334 340
 "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
335 341
 "checksum comrak 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a9bd60be8877a3343d25b9a3dadbaf7f02f9ac843b54e663ecef73e29e8b9c6b"
336 342
 "checksum entities 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5320ae4c3782150d900b79807611a59a99fc9a1d61d686faafc24b93fc8d7ca"
343
+"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
337 344
 "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
338 345
 "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
339 346
 "checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"

+ 1
- 0
Cargo.toml View File

@@ -6,6 +6,7 @@ authors = ["Dylan Baker"]
6 6
 [dependencies]
7 7
 clap = "2.32.0"
8 8
 comrak = "0.3"
9
+fs_extra = "1.1.0"
9 10
 lazy_static = "1.2.0"
10 11
 regex = "1"
11 12
 uuid = { version = "0.7", features = ["v4"] }

+ 21
- 1
src/main.rs View File

@@ -1,5 +1,6 @@
1 1
 extern crate clap;
2 2
 extern crate comrak;
3
+extern crate fs_extra;
3 4
 #[macro_use]
4 5
 extern crate lazy_static;
5 6
 extern crate regex;
@@ -8,6 +9,7 @@ extern crate uuid;
8 9
 use std::{env, fs};
9 10
 
10 11
 use clap::{App, Arg};
12
+use fs_extra::dir;
11 13
 
12 14
 use post::{parse_post, read_posts_dir};
13 15
 use write::{write_post, write_post_listing};
@@ -57,6 +59,12 @@ fn build() {
57 59
         &post_item_template,
58 60
         &posts,
59 61
     );
62
+
63
+    fs_extra::copy_items(
64
+        &vec![cwd.join("css"), cwd.join("js")],
65
+        cwd.join("public"),
66
+        &dir::CopyOptions::new(),
67
+    ).expect("Couldn't copy css/js directories");
60 68
 }
61 69
 
62 70
 fn new(name: &str) {
@@ -65,11 +73,15 @@ fn new(name: &str) {
65 73
 
66 74
     fs::create_dir(&project_path).expect(&format!("Couldn't create directory '{}'", &name));
67 75
 
68
-    for dir in &["posts", "public", "templates"] {
76
+    for dir in &["posts", "public", "templates", "css", "js"] {
69 77
         fs::create_dir(&project_path.join(&dir))
70 78
             .expect(&format!("Couldn't create {} directory", &dir));
71 79
     }
72 80
 
81
+    fs::write(project_path.join("css").join("style.css"), "")
82
+        .expect("Couldn't create css/style.css");
83
+    fs::write(project_path.join("js").join("index.js"), "").expect("Couldn't create js/index.js");
84
+
73 85
     for file in &["layout", "post_listing", "post", "post_listing_item"] {
74 86
         fs::write(
75 87
             &project_path
@@ -141,6 +153,14 @@ mod tests {
141 153
             "",
142 154
             fs::read_to_string(&project_dir.join("templates").join("post.html")).unwrap()
143 155
         );
156
+        assert_eq!(
157
+            "",
158
+            fs::read_to_string(&project_dir.join("css").join("style.css")).unwrap()
159
+        );
160
+        assert_eq!(
161
+            "",
162
+            fs::read_to_string(&project_dir.join("js").join("index.js")).unwrap()
163
+        );
144 164
 
145 165
         fs::remove_dir_all(project_dir).unwrap();
146 166
     }

Loading…
Cancel
Save