summary refs log tree commit diff stats
path: root/src/new/project.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-03-31 21:57:01 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-03-31 21:57:01 +0200
commit2e5e4b5736c446198e36760e254b7c17dd987166 (patch)
treeb74915864a2c80dbc0a0ebe26a52140a934f45c5 /src/new/project.rs
parentdocs(example): Add an example directory (diff)
downloadlpm-2e5e4b5736c446198e36760e254b7c17dd987166.tar.gz
lpm-2e5e4b5736c446198e36760e254b7c17dd987166.zip
refactor(treewide): Improve code quality by working with a FileTree
The FileTree has been taken from the implementation written by my for the
Trinitrix project. It alleviates the problem, where functions had to do
many things themselves.
Diffstat (limited to 'src/new/project.rs')
-rw-r--r--src/new/project.rs111
1 files changed, 0 insertions, 111 deletions
diff --git a/src/new/project.rs b/src/new/project.rs
deleted file mode 100644
index 56edead..0000000
--- a/src/new/project.rs
+++ /dev/null
@@ -1,111 +0,0 @@
-use std::{
-    env,
-    fs::{self, File},
-    io::{self, Write},
-    path::PathBuf,
-    process::Command,
-};
-
-use convert_case::{Case, Casing};
-
-use crate::data::Data;
-
-use super::{CHAPTER, MAIN_FILE, TITLE_FILE};
-
-const NEEDED_DIRECTORYS: &'static [&'static str] =
-    &["build", "content", "headers", "references", "resources"];
-
-pub fn generate_new_project(
-    name: String,
-    first_chapter: String,
-    //first_section: String,
-    preamble_path: PathBuf,
-    resource_path: PathBuf,
-) -> io::Result<()> {
-    fs::create_dir(&name).unwrap();
-    env::set_current_dir(&name).unwrap();
-    let project_root = env::current_dir().unwrap();
-
-    for directory in NEEDED_DIRECTORYS {
-        fs::create_dir(directory).unwrap();
-    }
-
-    // content
-    env::set_current_dir(project_root.join("content")).unwrap();
-    fs::create_dir(&first_chapter.to_case(Case::Snake)).unwrap();
-    fs::create_dir("static").unwrap();
-
-    env::set_current_dir("static").unwrap();
-    let mut title_file = File::create("title.tex").unwrap();
-    title_file.write_all(TITLE_FILE.as_bytes()).unwrap();
-
-    env::set_current_dir(
-        project_root
-            .join("content")
-            .join(&first_chapter.to_case(Case::Snake)),
-    )
-    .unwrap();
-    fs::create_dir("sections").unwrap();
-    let mut chapter_file = File::create("chapter_01.tex").unwrap();
-    chapter_file
-        .write_all(
-            CHAPTER
-                .replace("REPLACEMENT_CHAPTER", &first_chapter)
-                .as_bytes(),
-        )
-        .unwrap();
-
-    //env::set_current_dir("sections").unwrap();
-    //let mut section_file = File::create(format!("{}.tex", &first_section)).unwrap();
-    //section_file
-    //    .write_all(SECTION.as_bytes())
-    //    .unwrap();
-
-    // headers
-    env::set_current_dir(project_root.join("headers")).unwrap();
-    File::create("preamble_local.tex").unwrap();
-    fs::copy(fs::canonicalize(preamble_path).unwrap(), "preamble.tex").unwrap();
-
-    // resources
-    env::set_current_dir(project_root.join("resources")).unwrap();
-    fs::canonicalize(resource_path)
-        .unwrap()
-        .read_dir()
-        .unwrap()
-        .map(|path| path.expect("The provided path should work"))
-        .for_each(|path| {
-            fs::copy(path.path(), path.file_name()).unwrap();
-        });
-
-    // root files
-    env::set_current_dir(project_root).unwrap();
-    let mut main_file = File::create("main.tex").unwrap();
-    main_file
-        .write_all(
-            MAIN_FILE
-                .replace("REPLACEMENT_CHAPTER", &first_chapter.to_case(Case::Snake))
-                .as_bytes(),
-        )
-        .unwrap();
-
-    let data_file = Data {
-        last_chapter: crate::data::LastChapter {
-            user_name: first_chapter.to_case(Case::Snake),
-            number: 1,
-        },
-    };
-    let mut lpm_file = File::create("lpm.toml").unwrap();
-    lpm_file
-        .write_all(toml::to_string(&data_file).unwrap().as_bytes())
-        .unwrap();
-
-    Command::new("git")
-        .arg("init")
-        .output()
-        .expect("failed to execute process");
-
-    let mut lpm_file = File::create(".gitignore").unwrap();
-    lpm_file.write_all(b"/build").unwrap();
-
-    Ok(())
-}