diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..b155767
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/resolver.iml b/.idea/resolver.iml
new file mode 100644
index 0000000..cf84ae4
--- /dev/null
+++ b/.idea/resolver.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 8d2301c..6e161c2 100644
--- a/README.md
+++ b/README.md
@@ -48,8 +48,7 @@ resolver-cli get dfd project_name
The `scaffold` action is used to scaffold projects for different development tools and languages which includes:
-- ReactJS
-- ReactTs
+- React
- Hardhat
- NestJs
- Laravel
@@ -65,13 +64,13 @@ The `scaffold` action is used to scaffold projects for different development too
#### ReactJS
Creates a React project with JavaScript
```sh
-resolver-cli scaffold reactjs project_name
+resolver-cli scaffold react --lan=j
```
#### ReactTS
Creates a React project with TypeScript
```sh
-resolver-cli scaffold reactts project_name
+resolver-cli scaffold react --lan=t
```
#### Hardhat
diff --git a/install_resolver.sh b/install_resolver.sh
new file mode 100644
index 0000000..d3d89ec
--- /dev/null
+++ b/install_resolver.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+set -e
+echo -e "installing the resolver cli via curl"
+
+RED="\033[0;31m"
+GREEN="\033[0;32m"
+YELLOW="\033[0;33m"
+WHITE="\033[0m"
+
+# getting the operating system of the machine
+OS=$(uname -s)
+echo -e "${RED} RED first ,${GREEN} Green next, ${YELLOW} Yellow after"
+
+check_for_pkg_config_openssl() {
+ echo -e "checking if openssl and pkg_config are available"
+ if ! pkg-config --exists openssl; then
+ echo -e "could not find openssl and pkg_config"
+ #check for the os
+ echo -e "checking the machine OS and the installing the packages"
+ if [ "$OS" = "Darwin" ]; then
+ if ! command -v brew >/dev/null ; then
+ echo -e "homebrew is not installed, installing homebrew"
+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
+ fi
+ echo -e "installing openssl and pkg_config"
+ brew install openssl
+ brew install pkg-config
+
+ elif [ "$OS" = "Linux" ]; then
+ echo -e "updating linux packages"
+ sudo apt-get update -y || true
+ echo -e "installing openssl and pkg-config"
+ sudo apt-get install -y libssl-dev pkg-config
+
+ else
+ echo -e "Unsupported OS: ${OS} detected"
+ exit 1
+ fi
+ else
+ echo -e "${GREEN} openssl and pkg-config are already installed"
+ fi
+}
+
+echo -e "checking if curl already exists"
+if ! command -v curl >/dev/null; then
+ echo -e "${RED} curl is missing"
+ exit 1
+fi
+
+check_for_pkg_config_openssl
+
+echo -e "checking if rust is installed "
+if ! (command -v rustc >/dev/null && cargo >/dev/null); then
+ #install rust here if not installed
+ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y
+ source "$HOME/.cargo/env"
+else
+ echo -e "${GREEN} rust is already installed with ${YELLOW}$(rustc --version), ${YELLOW}$(cargo --version)"
+fi
+
+
+if ! command -v resolver-cli >/dev/null; then
+ # install resolver here
+ cargo install resolver-cli
+ echo -e "${GREEN}resolver-cli has been installed successfully"
+else
+ echo -e "${WHITE} resolver version ${YELLOW}$(resolver-cli --version) is already installed"
+fi
\ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
index f4e6c91..c81f546 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,9 +4,10 @@ use std::error::Error;
use colored::*;
pub mod utils;
-use utils::helpers::*;
-use utils::constants::*;
-pub use utils::command_arguments::*;
+pub use utils::{command_arguments::*,
+ constants::*,
+ helpers::{scaffold::*, installer::*
+ }};
pub fn resolve(args: ClapperArgs) -> Result<(), Box> {
@@ -61,21 +62,27 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box> {
},
EntityType::Scaffold(scaffold_command) => {
match scaffold_command.command {
- ScaffoldSubCommand::Reactjs(dir) => {
- match create_react_app(dir.dir_name.clone()) {
- 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);
- }
- }
+ ScaffoldSubCommand::React(user_choice) => {
+ match user_choice.lan {
+ ReactVariants::J => {
+ println!("javascript was chosen as the project language");
+ match create_react_app(user_choice.dir_name.clone()) {
+ Ok(_) => println!("{}", "Successfully created the React project!".bright_blue()),
+ Err(e) => {
+ return Err(e);
+ }
+ }
+ },
+ ReactVariants::T => {
+ println!("typescript was chosen as the project language");
+ match create_react_app_with_typescript(user_choice.dir_name.clone()) {
+ Ok(_) => println!("{}", "Successfully created the React project!".bright_blue()),
+ Err(e) => {
+ return Err(e);
+ }
+ }
+ },
+ }
},
ScaffoldSubCommand::Hardhat(dir) => {
match create_hardhat_project(dir.dir_name.clone()) {
@@ -188,7 +195,7 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box> {
return Err(e);
}
}
- }
+ },
}
},
EntityType::Install(install_command) => {
diff --git a/src/utils/command_arguments.rs b/src/utils/command_arguments.rs
index 4343245..ad20334 100644
--- a/src/utils/command_arguments.rs
+++ b/src/utils/command_arguments.rs
@@ -1,4 +1,4 @@
-use clap::{Args, Parser, Subcommand};
+use clap::{Args, Parser, Subcommand, ValueEnum};
#[derive(Debug, Parser)]
#[clap(author, version, about)]
@@ -53,9 +53,9 @@ 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),
+ // Reactjs(GetDir),
+ // /// Scaffolds a create-react-app TypeScript project
+ // Reactts(GetDir),
/// Scaffolds a Hardhat project
Hardhat(GetDir),
/// Scaffolds a NestJS project
@@ -84,6 +84,8 @@ pub enum ScaffoldSubCommand {
AnchorTS(GetDir),
/// Scaffold an Anchor project with Rust Tests
AnchorRust(GetDir),
+ // scaffold a react project
+ React(CreateReactSubCommand),
}
// ----------------
@@ -122,12 +124,32 @@ pub enum InstallSubCommand {
// --------------------------------------
// GetDir: For passing the directory name
// --------------------------------------
-#[derive(Debug, Args)]
+#[derive(Debug, Args,)]
pub struct GetDir {
/// Specifies the name of the project directory to initialize
pub dir_name: String,
}
+
+// for passing both the directory name and the language of choice
+// the args is an inbuilt library from clap used to take input from the terminal
+#[derive(Debug, Args,)]
+pub struct CreateReactSubCommand {
+ pub dir_name: String, // Specifies the name of the project directory to initialize
+
+ #[clap(long , short)] // this is used purposely for explicit choice when dealing with the argument via terminal hence --lan t or --lan=t
+ pub lan: ReactVariants, // specifies the language of choice for the project
+}
+
+// to choose the language variants
+// the valueEnum , just like the Args is a library from clap used to take argument from the terminal
+#[derive(Debug, ValueEnum, Clone)]
+pub enum ReactVariants {
+ J, // javascript
+ T, // typescript
+}
+
+
#[derive(Debug, Args)]
pub struct Version {
pub version_name: String,
diff --git a/src/utils/helpers.rs b/src/utils/helpers.rs
deleted file mode 100644
index 6b622ad..0000000
--- a/src/utils/helpers.rs
+++ /dev/null
@@ -1,569 +0,0 @@
-use std::error::Error;
-use std::fs;
-use std::io::Error as OutputError;
-use std::process::{Command, Output};
-
-// -------------------
-// Checker functions
-// -------------------
-pub fn is_node_installed() -> bool {
- let output = Command::new("node").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_npm_installed() -> bool {
- let output = Command::new("npm").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_nestjs_installed() -> bool {
- let output = Command::new("nest").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_php_installed() -> bool {
- let output = Command::new("php").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_composer_installed() -> bool {
- let output = Command::new("composer").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_scarb_installed() -> bool {
- let output = Command::new("scarb").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_forge_installed() -> bool {
- let output = Command::new("forge").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_python_installed() -> bool {
- //TODO: Check for python3 for macos
- let output = Command::new("python3").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_pip_installed() -> bool {
- let output = Command::new("pip3").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_starkli_installed() -> bool {
- let output = Command::new("starkli").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_brew_installed() -> bool {
- let output = Command::new("brew").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_choco_installed() -> bool {
- let output = Command::new("choco").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_nargo_installed() -> bool {
- let output = Command::new("noirup").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_solana_cli_installed() -> bool {
- let output = Command::new("solana").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn is_anchor_installed() -> bool {
- let output = Command::new("anchor").arg("--version").output();
-
- check_output(output)
-}
-
-pub fn get_os() -> String {
- let os_family = std::env::consts::OS;
-
- os_family.to_string()
-}
-
-fn check_output(output: Result