Repository: Wulf/create-rust-app (language: rust)

Issue:
Using chmod on windows
When running this on windows, `chmod` is used, causing the instalation to fail sometwhat (Some files are still copied).


Discussion / hints:

Fix patch:
diff --git a/src/git.rs b/src/git.rs
new file mode 100644
index 00000000..e604a6fb
--- /dev/null
+++ b/src/git.rs
@@ -0,0 +1,25 @@
+use std::path::PathBuf;
+use std::process::{Command, Stdio};
+
+pub fn check_config(project_dir: &PathBuf, config_item: &str) -> bool {
+    Command::new("git")
+        .current_dir(project_dir)
+        .arg("config")
+        .arg(config_item)
+        .stdout(Stdio::null())
+        .status()
+        .expect("failed to execute process")
+        .success()
+}
+
+pub fn set_config(project_dir: &PathBuf, config_item: &str, config_value: &str) -> bool {
+    Command::new("git")
+        .current_dir(project_dir)
+        .arg("config")
+        .arg(config_item)
+        .arg(config_value)
+        .stdout(Stdio::null())
+        .status()
+        .expect("failed to execute process")
+        .success()
+}
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 0d78fefe..1db02b5a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,9 +2,10 @@ extern crate inflector;
 
 mod db;
 mod fs;
-mod logger;
+mod git;
 mod mail;
 mod model;
+mod logger;
 mod plugins;
 mod project;
 mod service;
diff --git a/src/project.rs b/src/project.rs
index 4c8fce19..be793fa4 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -1,10 +1,11 @@
 use crate::logger::{command_msg, dependency_msg, error, exit, file_msg, message};
 use anyhow::Result;
 use console::style;
-use dialoguer::{theme::ColorfulTheme, Confirm};
+use dialoguer::{theme::ColorfulTheme, Confirm, Input};
 use inflector::Inflector;
 use rust_embed::RustEmbed;
 use std::path::PathBuf;
+use crate::git;
 
 #[derive(RustEmbed)]
 #[folder = "template"]
@@ -267,19 +268,6 @@ pub fn create(project_name: &str) -> Result<()> {
         std::fs::write(file_path, file_contents)?;
     }
 
-    command_msg("chmod +x ./bin/tsync.sh");
-
-    let chmod_tsync = std::process::Command::new("chmod")
-        .current_dir(&project_dir)
-        .arg("+x")
-        .arg("./bin/tsync.sh")
-        .status()
-        .expect("failed to execute process");
-
-    if !chmod_tsync.success() {
-        error("Failed to execute `chmod +x ./bin/tsync.sh`");
-    }
-
     /*
         Finalize; create the initial commit.
     */
@@ -298,6 +286,65 @@ pub fn create(project_name: &str) -> Result<()> {
         std::process::exit(1);
     }
 
+    command_msg("git config user.name");
+
+    let git_config_user_name = git::check_config(&project_dir, "user.name");
+    
+    if !git_config_user_name {
+        message("You do not have a git user name set.");
+
+        let mut valid_user_name = false;
+        let mut invalid_input = false;
+        
+        while !valid_user_name {
+            let prompt_message = if (invalid_input) {
+                "(try again) Choose a name to use when committing:"
+            } else {
+                "Choose a name to use when committing:"
+            };
+            let input : String = Input::new()
+                .with_prompt(prompt_message)
+                .interact()?;
+
+            command_msg(&format!("git config user.name {:#?}", &input));
+            
+            if input.len() > 0 && git::set_config(&project_dir, "user.name", &input) && git::check_config(&project_dir, "user.name") {
+                valid_user_name = true;
+            } else {
+                invalid_input = true;
+            }
+        }
+    }
+
+    let git_config_user_email = git::check_config(&project_dir, "user.email");
+    
+    if !git_config_user_email {
+        message("You do not have a git user email set.");
+
+        let mut valid_user_email = false;
+        let mut invalid_input = false;
+        
+        while !valid_user_email {
+            let prompt_message = if (invalid_input) {
+                "(try again) Choose an email to use when committing:"
+            } else {
+                "Choose an email to use when committing:"
+            };
+            let input : String = Input::new()
+                .with_prompt(prompt_message)
+                .interact()?;
+
+            command_msg(&format!("git config user.email {:#?}", &input));
+            
+            if input.len() > 0 && git::set_config(&project_dir, "user.email", &input) && git::check_config(&project_dir, "user.email") {
+                valid_user_email = true;
+            } else {
+                invalid_input = true;
+            }
+        }
+        
+    }
+
     command_msg("git add -A");
 
     let git_add = std::process::Command::new("git")
diff --git a/template/frontend/package.json b/template/frontend/package.json
index 234bc3a6..80537bc7 100644
--- a/template/frontend/package.json
+++ b/template/frontend/package.json
@@ -24,7 +24,7 @@
     "fullstack": "yarn install && yarn concurrently --prefix-colors cyan,magenta --kill-others -n backend,frontend \"cargo --color always watch -x run -i frontend\" \"yarn start\"",
     "test": "react-scripts test",
     "eject": "react-scripts eject",
-    "tsync": "../bin/tsync.sh"
+    "tsync": "tsync -i ../backend -o ./src/types/rust.d.ts"
   },
   "eslintConfig": {
     "extends": [


Test patch: