Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue_raised_when_creating_a_react_project #31

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,10 @@ The `scaffold` action is used to scaffold projects for different development too
- ReactNative Expo
- Adonis.js

#### ReactJS
Creates a React project with JavaScript
#### React
Creates a React project with a prompt to choose the scaffold type either js or ts
```sh
resolver-cli scaffold reactjs project_name
```

#### ReactTS
Creates a React project with TypeScript
```sh
resolver-cli scaffold reactts project_name
resolver-cli scaffold react project_name
```

#### Hardhat
Expand Down
35 changes: 21 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fs;
use git2::Repository;
use std::error::Error;
use std::{error::Error, io as input_output};
use colored::*;

pub mod utils;
Expand Down Expand Up @@ -61,20 +61,15 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box<dyn Error>> {
},
EntityType::Scaffold(scaffold_command) => {
match scaffold_command.command {
ScaffoldSubCommand::Reactjs(dir) => {
match create_react_app(dir.dir_name.clone()) {
ScaffoldSubCommand::React(dir) => {
let result = match collect_arguement_from_the_terminal().trim() {
"j" => create_react_app(dir.dir_name.clone()),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The create_react_app() function returns a Result enum, you will have to have each variant

"t" => create_react_app_with_typescript(dir.dir_name.clone()),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly the create_react_app_with_typescript() returns a Result enum, handle all variants.

_ => Err("input not recognized".into()),
};
match result {
Ok(_) => println!("{}", "Successfully created the React project!".bright_blue()),
Err(e) => {
return Err(e);
}
}
},
ScaffoldSubCommand::Reactts(dir) => {
match create_react_app_with_typescript(dir.dir_name.clone()) {
Ok(_) => println!("{}", "Successfully created the TypeScript React project!".bright_blue()),
Err(e) => {
return Err(e);
}
Err(e) => { return Err(e); }
}
},
ScaffoldSubCommand::Hardhat(dir) => {
Expand Down Expand Up @@ -248,6 +243,18 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box<dyn Error>> {
Ok(())
}

fn collect_arguement_from_the_terminal() -> String {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already an existing pattern of getting command line inputs, don't reinvent the wheel.

println!("{}", "enter the project type t :: typescript, j :: javascript ".bold().bright_cyan());
let mut user_input = String::new();
input_output::stdin().read_line(&mut user_input).unwrap();
match user_input.trim() {
"j" => println!("choice entered is {}", "java_script"),
"t" => println!("choice entered is {}", "typescript"),
_ => println!("choice entere is not recognized"),
}
user_input
}

fn remove_git_dir(dir_name: &String) {
let git_dir = format!("{}/.git", dir_name);
if fs::remove_dir_all(&git_dir).is_err() {
Expand Down
8 changes: 3 additions & 5 deletions src/utils/command_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ pub struct ScaffoldCommand {

#[derive(Debug, Subcommand)]
pub enum ScaffoldSubCommand {
/// Scaffolds a create-react-app JavaScript project
Reactjs(GetDir),
/// Scaffolds a create-react-app TypeScript project
Reactts(GetDir),
/// Scaffolds a Hardhat project
Hardhat(GetDir),
/// Scaffolds a NestJS project
Expand All @@ -79,7 +75,9 @@ pub enum ScaffoldSubCommand {
/// Scafold a React-Native Expo project
ReactNativeExpo(GetDir),
/// Scafold an Adonis.js Project
Adonis(GetDir)
Adonis(GetDir),
/// Scaffolds a create-react-app project
React(GetDir),
}

// ----------------
Expand Down