Переглянути джерело

Add all code for creating the base.

Lee Morgan 3 місяців тому
батько
коміт
820362b76b
2 змінених файлів з 40 додано та 13 видалено
  1. 37 0
      src/create.rs
  2. 3 13
      src/main.rs

+ 37 - 0
src/create.rs

@@ -0,0 +1,37 @@
+use std::fs;
+use std::path::Path;
+
+pub fn create(project_name: String) {
+    let path = Path::new(&project_name);
+    let fail_msg = "Creation failed";
+
+    fs::create_dir(path).expect(fail_msg);
+    fs::create_dir(path.join("routes")).expect(fail_msg);
+    fs::create_dir(path.join("assets")).expect(fail_msg);
+    fs::write(path.join(".gitignore"), "target/").expect(fail_msg);
+    fs::write(path.join("neovan.yml"), create_settings()).expect(fail_msg);
+    fs::write(path.join("routes").join("index.neovan"), hello_world_html()).expect(fail_msg);
+}
+
+fn create_settings() -> String {
+    r#"production: false
+routes_dir: routes
+build_dir: .build
+assets_dir: assets
+assets_route: /assets
+"#.to_string()
+}
+
+fn hello_world_html() -> String {
+    r#"<DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <title>NeoVan</title>
+    </head>
+    <body>
+        <h1>Hello, World!</h1>
+    </body>
+</html>
+"#.to_string()
+}

+ 3 - 13
src/main.rs

@@ -1,6 +1,7 @@
 use clap::Parser;
-use std::process::Command;
-use crate::create::;
+use crate::create::create;
+
+mod create;
 
 #[derive(Parser)]
 #[command(version, about, long_about = None)]
@@ -17,14 +18,3 @@ fn main() {
         a => eprintln!("Unknown command: {}", a)
     }
 }
-
-fn create(project_name: String) {
-    let output = Command::new("mkdir")
-        .arg(project_name)
-        .output()
-        .expect("failed");
-
-    if output.status.success() {
-        println!("created");
-    }
-}