ソースを参照

Create the function to recursively retrieve files.
Bug: seem to not be retrieving them properly yet.

Lee Morgan 3 ヶ月 前
コミット
222d5d7bb9
7 ファイル変更192 行追加19 行削除
  1. 108 0
      Cargo.lock
  2. 2 0
      Cargo.toml
  3. 14 2
      src/build_dev.rs
  4. 3 2
      src/create.rs
  5. 8 3
      src/main.rs
  6. 25 0
      src/options.rs
  7. 32 12
      src/routes_map.rs

+ 108 - 0
Cargo.lock

@@ -98,12 +98,34 @@ version = "1.0.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
 
+[[package]]
+name = "equivalent"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
+
+[[package]]
+name = "hashbrown"
+version = "0.16.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
+
 [[package]]
 name = "heck"
 version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
 
+[[package]]
+name = "indexmap"
+version = "2.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "45a8a2b9cb3e0b0c1803dbb0758ffac5de2f425b23c28f518faabd9d805342ff"
+dependencies = [
+ "equivalent",
+ "hashbrown",
+]
+
 [[package]]
 name = "is_terminal_polyfill"
 version = "1.70.2"
@@ -115,6 +137,8 @@ name = "neovan-cli"
 version = "0.1.0"
 dependencies = [
  "clap",
+ "serde",
+ "toml",
 ]
 
 [[package]]
@@ -141,6 +165,45 @@ dependencies = [
  "proc-macro2",
 ]
 
+[[package]]
+name = "serde"
+version = "1.0.228"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
+dependencies = [
+ "serde_core",
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_core"
+version = "1.0.228"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.228"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "serde_spanned"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
+dependencies = [
+ "serde_core",
+]
+
 [[package]]
 name = "strsim"
 version = "0.11.1"
@@ -158,6 +221,45 @@ dependencies = [
  "unicode-ident",
 ]
 
+[[package]]
+name = "toml"
+version = "1.1.2+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee"
+dependencies = [
+ "indexmap",
+ "serde_core",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_parser",
+ "toml_writer",
+ "winnow",
+]
+
+[[package]]
+name = "toml_datetime"
+version = "1.1.1+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7"
+dependencies = [
+ "serde_core",
+]
+
+[[package]]
+name = "toml_parser"
+version = "1.1.2+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526"
+dependencies = [
+ "winnow",
+]
+
+[[package]]
+name = "toml_writer"
+version = "1.1.1+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db"
+
 [[package]]
 name = "unicode-ident"
 version = "1.0.24"
@@ -184,3 +286,9 @@ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
 dependencies = [
  "windows-link",
 ]
+
+[[package]]
+name = "winnow"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09dac053f1cd375980747450bfc7250c264eaae0583872e845c0c7cd578872b5"

+ 2 - 0
Cargo.toml

@@ -5,3 +5,5 @@ edition = "2024"
 
 [dependencies]
 clap = { version = "4.6.0", features = ["derive"] }
+serde = { version = "1.0.228", features = ["derive"] }
+toml = "1.1.2"

+ 14 - 2
src/build_dev.rs

@@ -1,6 +1,10 @@
-use std::path::Path;
+use std::env;
+use crate::{
+    options::Options,
+    routes_map::FileType
+};
 
-pub fn build_dev() {
+pub fn build_dev(opt: Options) {
     //Create path for routes dir
     //
     //Recursive build list of files (FileType)
@@ -8,5 +12,13 @@ pub fn build_dev() {
     //Bundle each file
     //Create route for index files
 
+    let current_dir = env::current_dir().expect("Error");
+    let routes = FileType::get_all(current_dir.join(opt.routes_dir));
 
+    println!("something");
+    for route in routes {
+        match route {
+            _ => println!("{:#?}", route)
+        };
+    }
 }

+ 3 - 2
src/create.rs

@@ -1,8 +1,9 @@
 use std::fs;
 use std::path::Path;
 
-pub fn create(project_name: String) {
-    let path = Path::new(&project_name);
+pub fn create(project_name: Option<String>) {
+    let name = project_name.unwrap();
+    let path = Path::new(&name);
     let fail_msg = "Creation failed";
 
     fs::create_dir(path).expect(fail_msg);

+ 8 - 3
src/main.rs

@@ -1,17 +1,20 @@
 use clap::Parser;
 use crate::{
     create::create,
-    build_dev::build_dev
+    build_dev::build_dev,
+    options::Options
 };
 
 mod create;
 mod build_dev;
+mod options;
+mod routes_map;
 
 #[derive(Parser)]
 #[command(version, about, long_about = None)]
 struct Cli {
     operation: String,
-    arg1: String
+    arg1: Option<String>
 }
 
 fn main() {
@@ -19,7 +22,9 @@ fn main() {
 
     match cli.operation.as_str() {
         "create" => create(cli.arg1),
-        "build-dev" => build_dev(),
+        "build-dev" => {
+            build_dev(Options::retrieve());
+        },
         a => eprintln!("Unknown command: {}", a)
     }
 }

+ 25 - 0
src/options.rs

@@ -0,0 +1,25 @@
+use std::{env, fs};
+use serde::Deserialize;
+use toml;
+
+#[derive(Deserialize)]
+pub struct Config {
+    pub options: Options
+}
+
+#[derive(Deserialize)]
+pub struct Options {
+    pub routes_dir: String,
+    pub build_dir: String,
+    pub assets_dir: String,
+    pub assets_route: String
+}
+
+impl Options {
+    pub fn retrieve() -> Options {
+        let current_dir = env::current_dir().expect("Error");
+        let opt_file = fs::read_to_string(current_dir.join("neovan.toml")).expect("Error reading 'neovan.toml'");
+        let config: Config = toml::from_str(&opt_file).expect("Error parsing options");
+        config.options
+    }
+}

+ 32 - 12
src/routes_map.rs

@@ -1,22 +1,42 @@
-use std::path::Path;
+use std::path::PathBuf;
 use std::fs;
 
+#[derive(Debug)]
 pub enum FileType {
-    HtmlIndex(Path),
-    NeovanIndex(Path),
-    Component(Path)
+    HtmlIndex(PathBuf),
+    NeovanIndex(PathBuf),
+    HtmlComponent(PathBuf),
+    NeovanComponent(PathBuf)
 }
 
 impl FileType {
-    pub fn build(dir: Path) -> FileStructure {
-        let items = fs::read_dir(dir).expect("Create failed");
+    pub fn get_all(dir: PathBuf) -> Vec<FileType> {
+        let entries = fs::read_dir(dir).expect("Create failed");
+        let mut files = Vec::new();
 
-        items.
-            .map(|f| {
-                match f {
-                    println!("{}", f);
+        for entry in entries {
+            let path = entry.expect("Failed to read directory").path();
+
+            if path.is_dir() {
+                files.append(&mut FileType::get_all(path));
+            } else if path.is_file() {
+                if let Some(filename) = path.file_name() {
+                    let name = filename.to_string_lossy();
+                    if name == "index.html" {
+                        files.push(FileType::HtmlIndex(path))
+                    } else if name == "neovan.html" {
+                        files.push(FileType::NeovanIndex(path))
+                    }
+                } else if let Some(ext) = path.extension() {
+                    if ext == "html" {
+                        files.push(FileType::HtmlComponent(path))
+                    } else if ext == "neovan" {
+                        files.push(FileType::NeovanComponent(path))
+                    }
                 }
-            })
-            .collect()
+            }
+        }
+
+        files
     }
 }