From e464e25f1e9cea0af6074052ac60c0067f74c96f Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Sun, 29 Dec 2024 03:34:22 +0100 Subject: [PATCH 01/12] create react for ts and js merged into one --- .idea/.gitignore | 8 ++++++++ .idea/modules.xml | 8 ++++++++ .idea/resolver.iml | 11 +++++++++++ .idea/vcs.xml | 6 ++++++ 4 files changed, 33 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/resolver.iml create mode 100644 .idea/vcs.xml 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 From 7ad1aa32f1a2c9a14ecfcc10be49818830d2c95b Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Sun, 29 Dec 2024 03:34:34 +0100 Subject: [PATCH 02/12] create react for ts and js merged into one --- src/lib.rs | 24 +++++++++++++++++++++++- src/utils/command_arguments.rs | 23 +++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f4e6c91..d9cc5dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,6 +77,28 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box> { } } }, + ScaffoldSubCommand::React(user_choice) => { + match user_choice.lan { + ReactVariant::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); + } + } + }, + ReactVariant::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()) { Ok(_) => println!("{}", "Successfully created the Hardhat project!".bright_blue()), @@ -188,7 +210,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..175e622 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)] @@ -84,6 +84,7 @@ pub enum ScaffoldSubCommand { AnchorTS(GetDir), /// Scaffold an Anchor project with Rust Tests AnchorRust(GetDir), + React(CreateReactSubCommand), } // ---------------- @@ -122,12 +123,30 @@ 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 +#[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: ReactVariant, // specifies the language of choice for the project +} + +// to choose the language variants +#[derive(Debug, ValueEnum, Clone)] +pub enum ReactVariant { + J, // javascript + T, // typescript +} + + #[derive(Debug, Args)] pub struct Version { pub version_name: String, From 9911d0830fe4031a62ca4dc4a8e3e2df468ac77d Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Sun, 29 Dec 2024 03:41:02 +0100 Subject: [PATCH 03/12] create react for ts and js merged into one --- src/lib.rs | 4 ++-- src/utils/command_arguments.rs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d9cc5dc..54110f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box> { }, ScaffoldSubCommand::React(user_choice) => { match user_choice.lan { - ReactVariant::J => { + 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()), @@ -88,7 +88,7 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box> { } } }, - ReactVariant::T => { + 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()), diff --git a/src/utils/command_arguments.rs b/src/utils/command_arguments.rs index 175e622..cd7ffeb 100644 --- a/src/utils/command_arguments.rs +++ b/src/utils/command_arguments.rs @@ -84,6 +84,7 @@ pub enum ScaffoldSubCommand { AnchorTS(GetDir), /// Scaffold an Anchor project with Rust Tests AnchorRust(GetDir), + // scaffold a react project React(CreateReactSubCommand), } @@ -131,17 +132,19 @@ pub struct GetDir { // 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: ReactVariant, // specifies the language of choice for the project + 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 ReactVariant { +pub enum ReactVariants { J, // javascript T, // typescript } From 3ea6b94c211c17e4d1da0203fb6c709fcf3bb6f6 Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Sun, 29 Dec 2024 03:43:45 +0100 Subject: [PATCH 04/12] removal of the reactjs and the reactts variant from the lib --- src/lib.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 54110f6..864757f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,22 +61,6 @@ 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 => { From c02005e03ed20ec47ccc5409f56bcf1077dae8a1 Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Sun, 29 Dec 2024 03:44:50 +0100 Subject: [PATCH 05/12] removal of the reactjs and reactts variants from the scaffoldsubcommand --- src/utils/command_arguments.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/command_arguments.rs b/src/utils/command_arguments.rs index cd7ffeb..ad20334 100644 --- a/src/utils/command_arguments.rs +++ b/src/utils/command_arguments.rs @@ -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 From 425fb52967c39229cb3ef66ec10895c11c8508c1 Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Sun, 29 Dec 2024 03:49:08 +0100 Subject: [PATCH 06/12] updated the readme to cater the new update --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 From 4b79db221ff0575839ba5511aaa2815eca5b1837 Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Wed, 1 Jan 2025 12:34:24 +0100 Subject: [PATCH 07/12] creating new crates and modules --- src/utils/helpers/checkers.rs | 1 + src/utils/helpers/installer.rs | 0 src/utils/helpers/mod.rs | 4 ++++ src/utils/helpers/scaffold.rs | 1 + 4 files changed, 6 insertions(+) create mode 100644 src/utils/helpers/checkers.rs create mode 100644 src/utils/helpers/installer.rs create mode 100644 src/utils/helpers/mod.rs create mode 100644 src/utils/helpers/scaffold.rs diff --git a/src/utils/helpers/checkers.rs b/src/utils/helpers/checkers.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/utils/helpers/checkers.rs @@ -0,0 +1 @@ + diff --git a/src/utils/helpers/installer.rs b/src/utils/helpers/installer.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/utils/helpers/mod.rs b/src/utils/helpers/mod.rs new file mode 100644 index 0000000..f16afe5 --- /dev/null +++ b/src/utils/helpers/mod.rs @@ -0,0 +1,4 @@ + +pub mod scaffold; +pub mod installer; +pub mod checkers; \ No newline at end of file diff --git a/src/utils/helpers/scaffold.rs b/src/utils/helpers/scaffold.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/utils/helpers/scaffold.rs @@ -0,0 +1 @@ + From 9ad6c6b3a27308f8d09fddbd323e7ed1abe12a6e Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Wed, 1 Jan 2025 12:35:16 +0100 Subject: [PATCH 08/12] moving all the checkers function to it crate --- src/utils/helpers/checkers.rs | 109 ++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/src/utils/helpers/checkers.rs b/src/utils/helpers/checkers.rs index 8b13789..2511c42 100644 --- a/src/utils/helpers/checkers.rs +++ b/src/utils/helpers/checkers.rs @@ -1 +1,110 @@ +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) -> bool { + match output { + Ok(output) => { + if output.status.success() { + true + } else { + false + } + } + _ => false, + } +} \ No newline at end of file From 28217c37283b88cdd5cd36403a414c3d921a037e Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Wed, 1 Jan 2025 12:41:31 +0100 Subject: [PATCH 09/12] moved the scaffold functions to scaffold crate --- src/utils/helpers.rs | 154 +++++++++++----------- src/utils/helpers/checkers.rs | 5 + src/utils/helpers/scaffold.rs | 236 ++++++++++++++++++++++++++++++++++ 3 files changed, 318 insertions(+), 77 deletions(-) diff --git a/src/utils/helpers.rs b/src/utils/helpers.rs index 6b622ad..ace1008 100644 --- a/src/utils/helpers.rs +++ b/src/utils/helpers.rs @@ -6,115 +6,115 @@ use std::process::{Command, Output}; // ------------------- // Checker functions // ------------------- -pub fn is_node_installed() -> bool { - let output = Command::new("node").arg("--version").output(); +// pub fn is_node_installed() -> bool { +// let output = Command::new("node").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_npm_installed() -> bool { - let output = Command::new("npm").arg("--version").output(); +// pub fn is_npm_installed() -> bool { +// let output = Command::new("npm").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_nestjs_installed() -> bool { - let output = Command::new("nest").arg("--version").output(); +// pub fn is_nestjs_installed() -> bool { +// let output = Command::new("nest").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_php_installed() -> bool { - let output = Command::new("php").arg("--version").output(); +// pub fn is_php_installed() -> bool { +// let output = Command::new("php").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_composer_installed() -> bool { - let output = Command::new("composer").arg("--version").output(); +// pub fn is_composer_installed() -> bool { +// let output = Command::new("composer").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_scarb_installed() -> bool { - let output = Command::new("scarb").arg("--version").output(); +// pub fn is_scarb_installed() -> bool { +// let output = Command::new("scarb").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_forge_installed() -> bool { - let output = Command::new("forge").arg("--version").output(); +// pub fn is_forge_installed() -> bool { +// let output = Command::new("forge").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_python_installed() -> bool { - //TODO: Check for python3 for macos - let output = Command::new("python3").arg("--version").output(); +// pub fn is_python_installed() -> bool { +// //TODO: Check for python3 for macos +// let output = Command::new("python3").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_pip_installed() -> bool { - let output = Command::new("pip3").arg("--version").output(); +// pub fn is_pip_installed() -> bool { +// let output = Command::new("pip3").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_starkli_installed() -> bool { - let output = Command::new("starkli").arg("--version").output(); +// pub fn is_starkli_installed() -> bool { +// let output = Command::new("starkli").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_brew_installed() -> bool { - let output = Command::new("brew").arg("--version").output(); +// pub fn is_brew_installed() -> bool { +// let output = Command::new("brew").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_choco_installed() -> bool { - let output = Command::new("choco").arg("--version").output(); +// pub fn is_choco_installed() -> bool { +// let output = Command::new("choco").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_nargo_installed() -> bool { - let output = Command::new("noirup").arg("--version").output(); +// pub fn is_nargo_installed() -> bool { +// let output = Command::new("noirup").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_solana_cli_installed() -> bool { - let output = Command::new("solana").arg("--version").output(); +// pub fn is_solana_cli_installed() -> bool { +// let output = Command::new("solana").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn is_anchor_installed() -> bool { - let output = Command::new("anchor").arg("--version").output(); +// pub fn is_anchor_installed() -> bool { +// let output = Command::new("anchor").arg("--version").output(); - check_output(output) -} +// check_output(output) +// } -pub fn get_os() -> String { - let os_family = std::env::consts::OS; +// pub fn get_os() -> String { +// let os_family = std::env::consts::OS; - os_family.to_string() -} +// os_family.to_string() +// } -fn check_output(output: Result) -> bool { - match output { - Ok(output) => { - if output.status.success() { - true - } else { - false - } - } - _ => false, - } -} +// fn check_output(output: Result) -> bool { +// match output { +// Ok(output) => { +// if output.status.success() { +// true +// } else { +// false +// } +// } +// _ => false, +// } +// } // ------------------- // Scaffold functions diff --git a/src/utils/helpers/checkers.rs b/src/utils/helpers/checkers.rs index 2511c42..f042cf3 100644 --- a/src/utils/helpers/checkers.rs +++ b/src/utils/helpers/checkers.rs @@ -1,4 +1,9 @@ +use std::error::Error; +use std::fs; +use std::io::Error as OutputError; +use std::process::{Command, Output}; + pub fn is_node_installed() -> bool { let output = Command::new("node").arg("--version").output(); diff --git a/src/utils/helpers/scaffold.rs b/src/utils/helpers/scaffold.rs index 8b13789..02aba62 100644 --- a/src/utils/helpers/scaffold.rs +++ b/src/utils/helpers/scaffold.rs @@ -1 +1,237 @@ +pub fn create_react_app(project_name: String) -> Result<(), Box> { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } else { + Command::new("npx") + .args(["create-react-app", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_react_app_with_typescript(project_name: String) -> Result<(), Box> { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } else { + Command::new("npx") + .args([ + "create-react-app", + project_name.as_str(), + "--template", + "typescript", + ]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_hardhat_project(project_name: String) -> Result<(), Box> { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } else { + fs::create_dir_all(project_name.as_str())?; + + Command::new("npm") + .args(["init", "--yes"]) + .current_dir(project_name.as_str()) + .spawn()? + .wait()?; + + Command::new("npx") + .args(["hardhat", "init"]) + .current_dir(project_name.as_str()) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_nestjs_app(project_name: String) -> Result<(), Box> { + if !is_nestjs_installed() { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } + + Command::new("npm") + .args(["i", "-g", "@nestjs/cli"]) + .spawn()? + .wait()?; + } + + Command::new("nest") + .args(["new", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) +} + +pub fn create_laravel_project(project_name: String) -> Result<(), Box> { + if !is_php_installed() && !is_composer_installed() { + return Err("You don't have PHP or Composer installed".into()); + } else { + println!("Creating Laravel project: {}", project_name); + + Command::new("composer") + .args(["create-project", "laravel/laravel", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_next_app(project_name: String) -> Result<(), Box> { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } else { + Command::new("npx") + .args(["create-next-app@latest", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_new_foundry_project(project_name: String) -> Result<(), Box> { + if !is_forge_installed() { + return Err("You don't have Forge installed".into()); + } else { + Command::new("forge") + .args(["init", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_django_project(project_name: String) -> Result<(), Box> { + if !is_python_installed() && !is_pip_installed() { + return Err("You don't have Python installed".into()); + } else { + Command::new("django-admin") + .args(["startproject", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_vue_project(project_name: String) -> Result<(), Box> { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } else { + Command::new("npm") + .args(["create", "vue@latest", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_vite_project(project_name: String) -> Result<(), Box> { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } else { + Command::new("npm") + .args(["create", "vite@latest", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_noir_project(project_name: String) -> Result<(), Box> { + if !is_nargo_installed() { + return Err("You don't have nargo installed".into()); + } else { + Command::new("nargo") + .args(["new", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_starknet_foundry_project(project_name: String) -> Result<(), Box> { + if !is_forge_installed() { + return Err("You don't have Forge installed".into()); + } else { + Command::new("snforge") + .args(["init", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_expo_app(project_name: String) -> Result<(), Box> { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } else { + Command::new("npx") + .args(["create-expo-app", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_adonis_project(project_name: String) -> Result<(), Box> { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } else { + Command::new("npm") + .args(["init", "adonisjs@latest", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_anchor_project_ts(project_name: String) -> Result<(), Box> { + if !is_solana_cli_installed() { + return Err("You don't have the Solana CLI installed".into()); + } else if !is_anchor_installed() { + return Err("You don't have Anchor installed".into()); + } else if !is_node_installed() { + return Err("You don't have Node installed".into()); + } else { + Command::new("anchor") + .args(["init", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn create_anchor_project_rs(project_name: String) -> Result<(), Box> { + if !is_solana_cli_installed() { + return Err("You don't have the Solana CLI installed".into()); + } else if !is_anchor_installed() { + return Err("You don't have Anchor installed".into()); + } else { + Command::new("anchor") + .args(["init", "--test-template", "rust", project_name.as_str()]) + .spawn()? + .wait()?; + + Ok(()) + } +} \ No newline at end of file From 8cf8f4bbfb0716fa1be6b5fbcb45ab6fe024b2e9 Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Wed, 1 Jan 2025 12:43:00 +0100 Subject: [PATCH 10/12] moved the installer functions to the installer crate --- src/utils/helpers/installer.rs | 208 +++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) diff --git a/src/utils/helpers/installer.rs b/src/utils/helpers/installer.rs index e69de29..1d8ef32 100644 --- a/src/utils/helpers/installer.rs +++ b/src/utils/helpers/installer.rs @@ -0,0 +1,208 @@ + +pub fn install_brew() -> Result<(), Box> { + println!("Installing Homebrew..."); + + let script_url = "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"; + let command = format!("curl -fsSL {} | /bin/bash", script_url); + + Command::new("sh").arg("-c").arg(command).output()?; + + Ok(()) +} + +pub fn install_choco() -> Result<(), Box> { + println!("Installing Chocolatey..."); + + let powershell_script = r#" + Set-ExecutionPolicy Bypass -Scope Process -Force; + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; + iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) + "#; + + Command::new("powershell") + .arg("-Command") + .arg(powershell_script) + .output()?; + + Ok(()) +} + +pub fn install_node() -> Result<(), Box> { + println!("Installing the Latest Version of Node..."); + + // let os_family = std::env::consts::OS; + let os_family = get_os(); + + match os_family.as_str() { + "linux" => install_node_linux(), + "windows" => install_node_windows(), + "macos" => install_node_macos(), + _ => panic!("Unsupported OS"), + } +} + +pub fn install_node_linux() -> Result<(), Box> { + println!("Installing Node.js on Linux..."); + + Command::new("sudo") + .arg("apt-get") + .args(["update"]) + .status()?; + + Command::new("sudo") + .arg("apt-get") + .args(["install", "-y", "nodejs"]) + .status()?; + + Ok(()) +} + +pub fn install_node_macos() -> Result<(), Box> { + println!("Installing Node.js on macOS..."); + + if is_brew_installed() { + Command::new("brew").args(["install", "node"]).status()?; + } + + Ok(()) +} + +pub fn install_node_windows() -> Result<(), Box> { + println!("Installing Node.js on Windows..."); + + if is_choco_installed() { + Command::new("choco") + .args(["install", "nodejs", "-y"]) + .status()?; + } + + Ok(()) +} + +pub fn install_scarb() -> Result<(), Box> { + println!("Installing the Latest Version of Scarb..."); + + let install_cmd = + "curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh"; + + Command::new("sh").arg("-c").arg(install_cmd).output()?; + + Ok(()) +} + +pub fn install_starkli() -> Result<(), Box> { + println!("Installing the Latest Version of Starkli..."); + + Command::new("sh") + .arg("-c") + .arg("curl https://get.starkli.sh | sh") + .output()?; + + Command::new("sh").arg("-c").arg("starkliup").output()?; + + Ok(()) +} + +pub fn install_composer() {} + +pub fn install_forge() -> Result<(), Box> { + println!("Installing the Latest Version of Foundry..."); + + Command::new("sh") + .arg("-c") + .arg("curl -L https://foundry.paradigm.xyz | bash") + .output()?; + + Command::new("sh").arg("-c").arg("foundryup").output()?; + + Ok(()) +} + +pub fn install_nargo() -> Result<(), Box> { + println!("Installing the Latest Version of Noir..."); + + Command::new("sh") + .arg("-c") + .arg("curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash") + .output()?; + + Command::new("sh").arg("-c").arg("noirup").output()?; + + Ok(()) +} + +pub fn install_snforge(version: String) -> Result<(), Box> { + if version.eq("latest") { + println!("Installing the Latest Version of Starknet Foundry, Please wait..."); + + Command::new("sh") + .arg("-c") + .arg("curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh") + .output()?; + + Command::new("sh").arg("-c").arg("snfoundryup").output()?; + + Ok(()) + } else { + println!( + "Installing Version {} of Starknet Foundry, Please wait...", + version + ); + + Command::new("sh") + .args(["-c", "curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh"]) + .output()?; + + Command::new("sh") + .args(["-c", "snfoundryup", "-v", version.as_str()]) + .output()?; + + Ok(()) + } +} + +pub fn create_rainbowkit_wagmi_next_app(project_name: String) -> Result<(), Box> { + if !is_npm_installed() { + return Err("You don't have npm installed".into()); + } else { + Command::new("npm") + .args([ + "init", + "@rainbow-me/rainbowkit@latest", + project_name.as_str(), + ]) + .spawn()? + .wait()?; + + Ok(()) + } +} + +pub fn install_solana_cli() -> Result<(), Box> { + if is_solana_cli_installed() { + println!("You already have the Solana CLI installed"); + } else { + println!("Installing the Latest Version of the Solana CLI..."); + Command::new("sh") + .arg("-c") + .arg("curl -sSfL https://release.anza.xyz/stable/install | sh") + .status()?; + } + Ok(()) +} +pub fn install_anchor() -> Result<(), Box> { + println!("Installing Anchor..."); + + Command::new("cargo") + .args([ + "install", + "--git", + "https://github.com/coral-xyz/anchor", + "avm", + "--force", + ]) + .spawn()? + .wait()?; + + Ok(()) +} \ No newline at end of file From 918c6974cf376b83c19695f6e0a873e19bb4bb23 Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Wed, 1 Jan 2025 12:56:52 +0100 Subject: [PATCH 11/12] resolved the crate imports for the scaffold crate --- src/utils/helpers.rs | 569 --------------------------------- src/utils/helpers.txt | 569 +++++++++++++++++++++++++++++++++ src/utils/helpers/installer.rs | 4 + src/utils/helpers/scaffold.rs | 5 + 4 files changed, 578 insertions(+), 569 deletions(-) delete mode 100644 src/utils/helpers.rs create mode 100644 src/utils/helpers.txt diff --git a/src/utils/helpers.rs b/src/utils/helpers.rs deleted file mode 100644 index ace1008..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) -> bool { -// match output { -// Ok(output) => { -// if output.status.success() { -// true -// } else { -// false -// } -// } -// _ => false, -// } -// } - -// ------------------- -// Scaffold functions -// ------------------- -pub fn create_react_app(project_name: String) -> Result<(), Box> { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } else { - Command::new("npx") - .args(["create-react-app", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_react_app_with_typescript(project_name: String) -> Result<(), Box> { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } else { - Command::new("npx") - .args([ - "create-react-app", - project_name.as_str(), - "--template", - "typescript", - ]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_hardhat_project(project_name: String) -> Result<(), Box> { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } else { - fs::create_dir_all(project_name.as_str())?; - - Command::new("npm") - .args(["init", "--yes"]) - .current_dir(project_name.as_str()) - .spawn()? - .wait()?; - - Command::new("npx") - .args(["hardhat", "init"]) - .current_dir(project_name.as_str()) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_nestjs_app(project_name: String) -> Result<(), Box> { - if !is_nestjs_installed() { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } - - Command::new("npm") - .args(["i", "-g", "@nestjs/cli"]) - .spawn()? - .wait()?; - } - - Command::new("nest") - .args(["new", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) -} - -pub fn create_laravel_project(project_name: String) -> Result<(), Box> { - if !is_php_installed() && !is_composer_installed() { - return Err("You don't have PHP or Composer installed".into()); - } else { - println!("Creating Laravel project: {}", project_name); - - Command::new("composer") - .args(["create-project", "laravel/laravel", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_next_app(project_name: String) -> Result<(), Box> { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } else { - Command::new("npx") - .args(["create-next-app@latest", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_new_foundry_project(project_name: String) -> Result<(), Box> { - if !is_forge_installed() { - return Err("You don't have Forge installed".into()); - } else { - Command::new("forge") - .args(["init", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_django_project(project_name: String) -> Result<(), Box> { - if !is_python_installed() && !is_pip_installed() { - return Err("You don't have Python installed".into()); - } else { - Command::new("django-admin") - .args(["startproject", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_vue_project(project_name: String) -> Result<(), Box> { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } else { - Command::new("npm") - .args(["create", "vue@latest", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_vite_project(project_name: String) -> Result<(), Box> { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } else { - Command::new("npm") - .args(["create", "vite@latest", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_noir_project(project_name: String) -> Result<(), Box> { - if !is_nargo_installed() { - return Err("You don't have nargo installed".into()); - } else { - Command::new("nargo") - .args(["new", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_starknet_foundry_project(project_name: String) -> Result<(), Box> { - if !is_forge_installed() { - return Err("You don't have Forge installed".into()); - } else { - Command::new("snforge") - .args(["init", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_expo_app(project_name: String) -> Result<(), Box> { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } else { - Command::new("npx") - .args(["create-expo-app", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_adonis_project(project_name: String) -> Result<(), Box> { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } else { - Command::new("npm") - .args(["init", "adonisjs@latest", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_anchor_project_ts(project_name: String) -> Result<(), Box> { - if !is_solana_cli_installed() { - return Err("You don't have the Solana CLI installed".into()); - } else if !is_anchor_installed() { - return Err("You don't have Anchor installed".into()); - } else if !is_node_installed() { - return Err("You don't have Node installed".into()); - } else { - Command::new("anchor") - .args(["init", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn create_anchor_project_rs(project_name: String) -> Result<(), Box> { - if !is_solana_cli_installed() { - return Err("You don't have the Solana CLI installed".into()); - } else if !is_anchor_installed() { - return Err("You don't have Anchor installed".into()); - } else { - Command::new("anchor") - .args(["init", "--test-template", "rust", project_name.as_str()]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -// ------------------- -// Installer functions -// ------------------- - -pub fn install_brew() -> Result<(), Box> { - println!("Installing Homebrew..."); - - let script_url = "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"; - let command = format!("curl -fsSL {} | /bin/bash", script_url); - - Command::new("sh").arg("-c").arg(command).output()?; - - Ok(()) -} - -pub fn install_choco() -> Result<(), Box> { - println!("Installing Chocolatey..."); - - let powershell_script = r#" - Set-ExecutionPolicy Bypass -Scope Process -Force; - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; - iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) - "#; - - Command::new("powershell") - .arg("-Command") - .arg(powershell_script) - .output()?; - - Ok(()) -} - -pub fn install_node() -> Result<(), Box> { - println!("Installing the Latest Version of Node..."); - - // let os_family = std::env::consts::OS; - let os_family = get_os(); - - match os_family.as_str() { - "linux" => install_node_linux(), - "windows" => install_node_windows(), - "macos" => install_node_macos(), - _ => panic!("Unsupported OS"), - } -} - -pub fn install_node_linux() -> Result<(), Box> { - println!("Installing Node.js on Linux..."); - - Command::new("sudo") - .arg("apt-get") - .args(["update"]) - .status()?; - - Command::new("sudo") - .arg("apt-get") - .args(["install", "-y", "nodejs"]) - .status()?; - - Ok(()) -} - -pub fn install_node_macos() -> Result<(), Box> { - println!("Installing Node.js on macOS..."); - - if is_brew_installed() { - Command::new("brew").args(["install", "node"]).status()?; - } - - Ok(()) -} - -pub fn install_node_windows() -> Result<(), Box> { - println!("Installing Node.js on Windows..."); - - if is_choco_installed() { - Command::new("choco") - .args(["install", "nodejs", "-y"]) - .status()?; - } - - Ok(()) -} - -pub fn install_scarb() -> Result<(), Box> { - println!("Installing the Latest Version of Scarb..."); - - let install_cmd = - "curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh"; - - Command::new("sh").arg("-c").arg(install_cmd).output()?; - - Ok(()) -} - -pub fn install_starkli() -> Result<(), Box> { - println!("Installing the Latest Version of Starkli..."); - - Command::new("sh") - .arg("-c") - .arg("curl https://get.starkli.sh | sh") - .output()?; - - Command::new("sh").arg("-c").arg("starkliup").output()?; - - Ok(()) -} - -pub fn install_composer() {} - -pub fn install_forge() -> Result<(), Box> { - println!("Installing the Latest Version of Foundry..."); - - Command::new("sh") - .arg("-c") - .arg("curl -L https://foundry.paradigm.xyz | bash") - .output()?; - - Command::new("sh").arg("-c").arg("foundryup").output()?; - - Ok(()) -} - -pub fn install_nargo() -> Result<(), Box> { - println!("Installing the Latest Version of Noir..."); - - Command::new("sh") - .arg("-c") - .arg("curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash") - .output()?; - - Command::new("sh").arg("-c").arg("noirup").output()?; - - Ok(()) -} - -pub fn install_snforge(version: String) -> Result<(), Box> { - if version.eq("latest") { - println!("Installing the Latest Version of Starknet Foundry, Please wait..."); - - Command::new("sh") - .arg("-c") - .arg("curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh") - .output()?; - - Command::new("sh").arg("-c").arg("snfoundryup").output()?; - - Ok(()) - } else { - println!( - "Installing Version {} of Starknet Foundry, Please wait...", - version - ); - - Command::new("sh") - .args(["-c", "curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh"]) - .output()?; - - Command::new("sh") - .args(["-c", "snfoundryup", "-v", version.as_str()]) - .output()?; - - Ok(()) - } -} - -pub fn create_rainbowkit_wagmi_next_app(project_name: String) -> Result<(), Box> { - if !is_npm_installed() { - return Err("You don't have npm installed".into()); - } else { - Command::new("npm") - .args([ - "init", - "@rainbow-me/rainbowkit@latest", - project_name.as_str(), - ]) - .spawn()? - .wait()?; - - Ok(()) - } -} - -pub fn install_solana_cli() -> Result<(), Box> { - if is_solana_cli_installed() { - println!("You already have the Solana CLI installed"); - } else { - println!("Installing the Latest Version of the Solana CLI..."); - Command::new("sh") - .arg("-c") - .arg("curl -sSfL https://release.anza.xyz/stable/install | sh") - .status()?; - } - Ok(()) -} -pub fn install_anchor() -> Result<(), Box> { - println!("Installing Anchor..."); - - Command::new("cargo") - .args([ - "install", - "--git", - "https://github.com/coral-xyz/anchor", - "avm", - "--force", - ]) - .spawn()? - .wait()?; - - Ok(()) -} diff --git a/src/utils/helpers.txt b/src/utils/helpers.txt new file mode 100644 index 0000000..770be69 --- /dev/null +++ b/src/utils/helpers.txt @@ -0,0 +1,569 @@ +// 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) -> bool { +// // match output { +// // Ok(output) => { +// // if output.status.success() { +// // true +// // } else { +// // false +// // } +// // } +// // _ => false, +// // } +// // } + +// // ------------------- +// // Scaffold functions +// // ------------------- +// pub fn create_react_app(project_name: String) -> Result<(), Box> { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } else { +// Command::new("npx") +// .args(["create-react-app", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_react_app_with_typescript(project_name: String) -> Result<(), Box> { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } else { +// Command::new("npx") +// .args([ +// "create-react-app", +// project_name.as_str(), +// "--template", +// "typescript", +// ]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_hardhat_project(project_name: String) -> Result<(), Box> { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } else { +// fs::create_dir_all(project_name.as_str())?; + +// Command::new("npm") +// .args(["init", "--yes"]) +// .current_dir(project_name.as_str()) +// .spawn()? +// .wait()?; + +// Command::new("npx") +// .args(["hardhat", "init"]) +// .current_dir(project_name.as_str()) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_nestjs_app(project_name: String) -> Result<(), Box> { +// if !is_nestjs_installed() { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } + +// Command::new("npm") +// .args(["i", "-g", "@nestjs/cli"]) +// .spawn()? +// .wait()?; +// } + +// Command::new("nest") +// .args(["new", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } + +// pub fn create_laravel_project(project_name: String) -> Result<(), Box> { +// if !is_php_installed() && !is_composer_installed() { +// return Err("You don't have PHP or Composer installed".into()); +// } else { +// println!("Creating Laravel project: {}", project_name); + +// Command::new("composer") +// .args(["create-project", "laravel/laravel", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_next_app(project_name: String) -> Result<(), Box> { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } else { +// Command::new("npx") +// .args(["create-next-app@latest", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_new_foundry_project(project_name: String) -> Result<(), Box> { +// if !is_forge_installed() { +// return Err("You don't have Forge installed".into()); +// } else { +// Command::new("forge") +// .args(["init", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_django_project(project_name: String) -> Result<(), Box> { +// if !is_python_installed() && !is_pip_installed() { +// return Err("You don't have Python installed".into()); +// } else { +// Command::new("django-admin") +// .args(["startproject", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_vue_project(project_name: String) -> Result<(), Box> { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } else { +// Command::new("npm") +// .args(["create", "vue@latest", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_vite_project(project_name: String) -> Result<(), Box> { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } else { +// Command::new("npm") +// .args(["create", "vite@latest", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_noir_project(project_name: String) -> Result<(), Box> { +// if !is_nargo_installed() { +// return Err("You don't have nargo installed".into()); +// } else { +// Command::new("nargo") +// .args(["new", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_starknet_foundry_project(project_name: String) -> Result<(), Box> { +// if !is_forge_installed() { +// return Err("You don't have Forge installed".into()); +// } else { +// Command::new("snforge") +// .args(["init", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_expo_app(project_name: String) -> Result<(), Box> { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } else { +// Command::new("npx") +// .args(["create-expo-app", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_adonis_project(project_name: String) -> Result<(), Box> { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } else { +// Command::new("npm") +// .args(["init", "adonisjs@latest", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_anchor_project_ts(project_name: String) -> Result<(), Box> { +// if !is_solana_cli_installed() { +// return Err("You don't have the Solana CLI installed".into()); +// } else if !is_anchor_installed() { +// return Err("You don't have Anchor installed".into()); +// } else if !is_node_installed() { +// return Err("You don't have Node installed".into()); +// } else { +// Command::new("anchor") +// .args(["init", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn create_anchor_project_rs(project_name: String) -> Result<(), Box> { +// if !is_solana_cli_installed() { +// return Err("You don't have the Solana CLI installed".into()); +// } else if !is_anchor_installed() { +// return Err("You don't have Anchor installed".into()); +// } else { +// Command::new("anchor") +// .args(["init", "--test-template", "rust", project_name.as_str()]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// // ------------------- +// // Installer functions +// // ------------------- + +// pub fn install_brew() -> Result<(), Box> { +// println!("Installing Homebrew..."); + +// let script_url = "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"; +// let command = format!("curl -fsSL {} | /bin/bash", script_url); + +// Command::new("sh").arg("-c").arg(command).output()?; + +// Ok(()) +// } + +// pub fn install_choco() -> Result<(), Box> { +// println!("Installing Chocolatey..."); + +// let powershell_script = r#" +// Set-ExecutionPolicy Bypass -Scope Process -Force; +// [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; +// iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) +// "#; + +// Command::new("powershell") +// .arg("-Command") +// .arg(powershell_script) +// .output()?; + +// Ok(()) +// } + +// pub fn install_node() -> Result<(), Box> { +// println!("Installing the Latest Version of Node..."); + +// // let os_family = std::env::consts::OS; +// let os_family = get_os(); + +// match os_family.as_str() { +// "linux" => install_node_linux(), +// "windows" => install_node_windows(), +// "macos" => install_node_macos(), +// _ => panic!("Unsupported OS"), +// } +// } + +// pub fn install_node_linux() -> Result<(), Box> { +// println!("Installing Node.js on Linux..."); + +// Command::new("sudo") +// .arg("apt-get") +// .args(["update"]) +// .status()?; + +// Command::new("sudo") +// .arg("apt-get") +// .args(["install", "-y", "nodejs"]) +// .status()?; + +// Ok(()) +// } + +// pub fn install_node_macos() -> Result<(), Box> { +// println!("Installing Node.js on macOS..."); + +// if is_brew_installed() { +// Command::new("brew").args(["install", "node"]).status()?; +// } + +// Ok(()) +// } + +// pub fn install_node_windows() -> Result<(), Box> { +// println!("Installing Node.js on Windows..."); + +// if is_choco_installed() { +// Command::new("choco") +// .args(["install", "nodejs", "-y"]) +// .status()?; +// } + +// Ok(()) +// } + +// pub fn install_scarb() -> Result<(), Box> { +// println!("Installing the Latest Version of Scarb..."); + +// let install_cmd = +// "curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh"; + +// Command::new("sh").arg("-c").arg(install_cmd).output()?; + +// Ok(()) +// } + +// pub fn install_starkli() -> Result<(), Box> { +// println!("Installing the Latest Version of Starkli..."); + +// Command::new("sh") +// .arg("-c") +// .arg("curl https://get.starkli.sh | sh") +// .output()?; + +// Command::new("sh").arg("-c").arg("starkliup").output()?; + +// Ok(()) +// } + +// pub fn install_composer() {} + +// pub fn install_forge() -> Result<(), Box> { +// println!("Installing the Latest Version of Foundry..."); + +// Command::new("sh") +// .arg("-c") +// .arg("curl -L https://foundry.paradigm.xyz | bash") +// .output()?; + +// Command::new("sh").arg("-c").arg("foundryup").output()?; + +// Ok(()) +// } + +// pub fn install_nargo() -> Result<(), Box> { +// println!("Installing the Latest Version of Noir..."); + +// Command::new("sh") +// .arg("-c") +// .arg("curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash") +// .output()?; + +// Command::new("sh").arg("-c").arg("noirup").output()?; + +// Ok(()) +// } + +// pub fn install_snforge(version: String) -> Result<(), Box> { +// if version.eq("latest") { +// println!("Installing the Latest Version of Starknet Foundry, Please wait..."); + +// Command::new("sh") +// .arg("-c") +// .arg("curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh") +// .output()?; + +// Command::new("sh").arg("-c").arg("snfoundryup").output()?; + +// Ok(()) +// } else { +// println!( +// "Installing Version {} of Starknet Foundry, Please wait...", +// version +// ); + +// Command::new("sh") +// .args(["-c", "curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh"]) +// .output()?; + +// Command::new("sh") +// .args(["-c", "snfoundryup", "-v", version.as_str()]) +// .output()?; + +// Ok(()) +// } +// } + +// pub fn create_rainbowkit_wagmi_next_app(project_name: String) -> Result<(), Box> { +// if !is_npm_installed() { +// return Err("You don't have npm installed".into()); +// } else { +// Command::new("npm") +// .args([ +// "init", +// "@rainbow-me/rainbowkit@latest", +// project_name.as_str(), +// ]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } +// } + +// pub fn install_solana_cli() -> Result<(), Box> { +// if is_solana_cli_installed() { +// println!("You already have the Solana CLI installed"); +// } else { +// println!("Installing the Latest Version of the Solana CLI..."); +// Command::new("sh") +// .arg("-c") +// .arg("curl -sSfL https://release.anza.xyz/stable/install | sh") +// .status()?; +// } +// Ok(()) +// } +// pub fn install_anchor() -> Result<(), Box> { +// println!("Installing Anchor..."); + +// Command::new("cargo") +// .args([ +// "install", +// "--git", +// "https://github.com/coral-xyz/anchor", +// "avm", +// "--force", +// ]) +// .spawn()? +// .wait()?; + +// Ok(()) +// } diff --git a/src/utils/helpers/installer.rs b/src/utils/helpers/installer.rs index 1d8ef32..3472240 100644 --- a/src/utils/helpers/installer.rs +++ b/src/utils/helpers/installer.rs @@ -1,3 +1,7 @@ +use std::error::Error; +use std::fs; +use std::io::Error as OutputError; +use std::process::{Command, Output}; pub fn install_brew() -> Result<(), Box> { println!("Installing Homebrew..."); diff --git a/src/utils/helpers/scaffold.rs b/src/utils/helpers/scaffold.rs index 02aba62..49068eb 100644 --- a/src/utils/helpers/scaffold.rs +++ b/src/utils/helpers/scaffold.rs @@ -1,3 +1,8 @@ +use std::error::Error; +use std::fs; +use std::io::Error as OutputError; +use std::process::{Command, Output}; +use crate::utils::helpers::checkers::*; pub fn create_react_app(project_name: String) -> Result<(), Box> { if !is_npm_installed() { From b46d835b9ad60e60dbe8563f7d4e35ea4618ca01 Mon Sep 17 00:00:00 2001 From: whitewizardd Date: Wed, 1 Jan 2025 13:57:06 +0100 Subject: [PATCH 12/12] resolved the crate imports in the lib crate --- src/lib.rs | 7 +- src/utils/helpers.txt | 569 --------------------------------- src/utils/helpers/checkers.rs | 3 +- src/utils/helpers/installer.rs | 5 +- src/utils/helpers/scaffold.rs | 3 +- 5 files changed, 8 insertions(+), 579 deletions(-) delete mode 100644 src/utils/helpers.txt diff --git a/src/lib.rs b/src/lib.rs index 864757f..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> { diff --git a/src/utils/helpers.txt b/src/utils/helpers.txt deleted file mode 100644 index 770be69..0000000 --- a/src/utils/helpers.txt +++ /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) -> bool { -// // match output { -// // Ok(output) => { -// // if output.status.success() { -// // true -// // } else { -// // false -// // } -// // } -// // _ => false, -// // } -// // } - -// // ------------------- -// // Scaffold functions -// // ------------------- -// pub fn create_react_app(project_name: String) -> Result<(), Box> { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } else { -// Command::new("npx") -// .args(["create-react-app", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_react_app_with_typescript(project_name: String) -> Result<(), Box> { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } else { -// Command::new("npx") -// .args([ -// "create-react-app", -// project_name.as_str(), -// "--template", -// "typescript", -// ]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_hardhat_project(project_name: String) -> Result<(), Box> { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } else { -// fs::create_dir_all(project_name.as_str())?; - -// Command::new("npm") -// .args(["init", "--yes"]) -// .current_dir(project_name.as_str()) -// .spawn()? -// .wait()?; - -// Command::new("npx") -// .args(["hardhat", "init"]) -// .current_dir(project_name.as_str()) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_nestjs_app(project_name: String) -> Result<(), Box> { -// if !is_nestjs_installed() { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } - -// Command::new("npm") -// .args(["i", "-g", "@nestjs/cli"]) -// .spawn()? -// .wait()?; -// } - -// Command::new("nest") -// .args(["new", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } - -// pub fn create_laravel_project(project_name: String) -> Result<(), Box> { -// if !is_php_installed() && !is_composer_installed() { -// return Err("You don't have PHP or Composer installed".into()); -// } else { -// println!("Creating Laravel project: {}", project_name); - -// Command::new("composer") -// .args(["create-project", "laravel/laravel", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_next_app(project_name: String) -> Result<(), Box> { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } else { -// Command::new("npx") -// .args(["create-next-app@latest", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_new_foundry_project(project_name: String) -> Result<(), Box> { -// if !is_forge_installed() { -// return Err("You don't have Forge installed".into()); -// } else { -// Command::new("forge") -// .args(["init", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_django_project(project_name: String) -> Result<(), Box> { -// if !is_python_installed() && !is_pip_installed() { -// return Err("You don't have Python installed".into()); -// } else { -// Command::new("django-admin") -// .args(["startproject", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_vue_project(project_name: String) -> Result<(), Box> { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } else { -// Command::new("npm") -// .args(["create", "vue@latest", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_vite_project(project_name: String) -> Result<(), Box> { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } else { -// Command::new("npm") -// .args(["create", "vite@latest", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_noir_project(project_name: String) -> Result<(), Box> { -// if !is_nargo_installed() { -// return Err("You don't have nargo installed".into()); -// } else { -// Command::new("nargo") -// .args(["new", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_starknet_foundry_project(project_name: String) -> Result<(), Box> { -// if !is_forge_installed() { -// return Err("You don't have Forge installed".into()); -// } else { -// Command::new("snforge") -// .args(["init", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_expo_app(project_name: String) -> Result<(), Box> { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } else { -// Command::new("npx") -// .args(["create-expo-app", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_adonis_project(project_name: String) -> Result<(), Box> { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } else { -// Command::new("npm") -// .args(["init", "adonisjs@latest", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_anchor_project_ts(project_name: String) -> Result<(), Box> { -// if !is_solana_cli_installed() { -// return Err("You don't have the Solana CLI installed".into()); -// } else if !is_anchor_installed() { -// return Err("You don't have Anchor installed".into()); -// } else if !is_node_installed() { -// return Err("You don't have Node installed".into()); -// } else { -// Command::new("anchor") -// .args(["init", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn create_anchor_project_rs(project_name: String) -> Result<(), Box> { -// if !is_solana_cli_installed() { -// return Err("You don't have the Solana CLI installed".into()); -// } else if !is_anchor_installed() { -// return Err("You don't have Anchor installed".into()); -// } else { -// Command::new("anchor") -// .args(["init", "--test-template", "rust", project_name.as_str()]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// // ------------------- -// // Installer functions -// // ------------------- - -// pub fn install_brew() -> Result<(), Box> { -// println!("Installing Homebrew..."); - -// let script_url = "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"; -// let command = format!("curl -fsSL {} | /bin/bash", script_url); - -// Command::new("sh").arg("-c").arg(command).output()?; - -// Ok(()) -// } - -// pub fn install_choco() -> Result<(), Box> { -// println!("Installing Chocolatey..."); - -// let powershell_script = r#" -// Set-ExecutionPolicy Bypass -Scope Process -Force; -// [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; -// iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -// "#; - -// Command::new("powershell") -// .arg("-Command") -// .arg(powershell_script) -// .output()?; - -// Ok(()) -// } - -// pub fn install_node() -> Result<(), Box> { -// println!("Installing the Latest Version of Node..."); - -// // let os_family = std::env::consts::OS; -// let os_family = get_os(); - -// match os_family.as_str() { -// "linux" => install_node_linux(), -// "windows" => install_node_windows(), -// "macos" => install_node_macos(), -// _ => panic!("Unsupported OS"), -// } -// } - -// pub fn install_node_linux() -> Result<(), Box> { -// println!("Installing Node.js on Linux..."); - -// Command::new("sudo") -// .arg("apt-get") -// .args(["update"]) -// .status()?; - -// Command::new("sudo") -// .arg("apt-get") -// .args(["install", "-y", "nodejs"]) -// .status()?; - -// Ok(()) -// } - -// pub fn install_node_macos() -> Result<(), Box> { -// println!("Installing Node.js on macOS..."); - -// if is_brew_installed() { -// Command::new("brew").args(["install", "node"]).status()?; -// } - -// Ok(()) -// } - -// pub fn install_node_windows() -> Result<(), Box> { -// println!("Installing Node.js on Windows..."); - -// if is_choco_installed() { -// Command::new("choco") -// .args(["install", "nodejs", "-y"]) -// .status()?; -// } - -// Ok(()) -// } - -// pub fn install_scarb() -> Result<(), Box> { -// println!("Installing the Latest Version of Scarb..."); - -// let install_cmd = -// "curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh"; - -// Command::new("sh").arg("-c").arg(install_cmd).output()?; - -// Ok(()) -// } - -// pub fn install_starkli() -> Result<(), Box> { -// println!("Installing the Latest Version of Starkli..."); - -// Command::new("sh") -// .arg("-c") -// .arg("curl https://get.starkli.sh | sh") -// .output()?; - -// Command::new("sh").arg("-c").arg("starkliup").output()?; - -// Ok(()) -// } - -// pub fn install_composer() {} - -// pub fn install_forge() -> Result<(), Box> { -// println!("Installing the Latest Version of Foundry..."); - -// Command::new("sh") -// .arg("-c") -// .arg("curl -L https://foundry.paradigm.xyz | bash") -// .output()?; - -// Command::new("sh").arg("-c").arg("foundryup").output()?; - -// Ok(()) -// } - -// pub fn install_nargo() -> Result<(), Box> { -// println!("Installing the Latest Version of Noir..."); - -// Command::new("sh") -// .arg("-c") -// .arg("curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash") -// .output()?; - -// Command::new("sh").arg("-c").arg("noirup").output()?; - -// Ok(()) -// } - -// pub fn install_snforge(version: String) -> Result<(), Box> { -// if version.eq("latest") { -// println!("Installing the Latest Version of Starknet Foundry, Please wait..."); - -// Command::new("sh") -// .arg("-c") -// .arg("curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh") -// .output()?; - -// Command::new("sh").arg("-c").arg("snfoundryup").output()?; - -// Ok(()) -// } else { -// println!( -// "Installing Version {} of Starknet Foundry, Please wait...", -// version -// ); - -// Command::new("sh") -// .args(["-c", "curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh"]) -// .output()?; - -// Command::new("sh") -// .args(["-c", "snfoundryup", "-v", version.as_str()]) -// .output()?; - -// Ok(()) -// } -// } - -// pub fn create_rainbowkit_wagmi_next_app(project_name: String) -> Result<(), Box> { -// if !is_npm_installed() { -// return Err("You don't have npm installed".into()); -// } else { -// Command::new("npm") -// .args([ -// "init", -// "@rainbow-me/rainbowkit@latest", -// project_name.as_str(), -// ]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } -// } - -// pub fn install_solana_cli() -> Result<(), Box> { -// if is_solana_cli_installed() { -// println!("You already have the Solana CLI installed"); -// } else { -// println!("Installing the Latest Version of the Solana CLI..."); -// Command::new("sh") -// .arg("-c") -// .arg("curl -sSfL https://release.anza.xyz/stable/install | sh") -// .status()?; -// } -// Ok(()) -// } -// pub fn install_anchor() -> Result<(), Box> { -// println!("Installing Anchor..."); - -// Command::new("cargo") -// .args([ -// "install", -// "--git", -// "https://github.com/coral-xyz/anchor", -// "avm", -// "--force", -// ]) -// .spawn()? -// .wait()?; - -// Ok(()) -// } diff --git a/src/utils/helpers/checkers.rs b/src/utils/helpers/checkers.rs index f042cf3..98b9850 100644 --- a/src/utils/helpers/checkers.rs +++ b/src/utils/helpers/checkers.rs @@ -1,6 +1,5 @@ -use std::error::Error; -use std::fs; + use std::io::Error as OutputError; use std::process::{Command, Output}; diff --git a/src/utils/helpers/installer.rs b/src/utils/helpers/installer.rs index 3472240..5d3e316 100644 --- a/src/utils/helpers/installer.rs +++ b/src/utils/helpers/installer.rs @@ -1,7 +1,6 @@ use std::error::Error; -use std::fs; -use std::io::Error as OutputError; -use std::process::{Command, Output}; +use std::process::{Command, }; +use crate::utils::helpers::checkers::*; pub fn install_brew() -> Result<(), Box> { println!("Installing Homebrew..."); diff --git a/src/utils/helpers/scaffold.rs b/src/utils/helpers/scaffold.rs index 49068eb..619a4eb 100644 --- a/src/utils/helpers/scaffold.rs +++ b/src/utils/helpers/scaffold.rs @@ -1,7 +1,6 @@ use std::error::Error; use std::fs; -use std::io::Error as OutputError; -use std::process::{Command, Output}; +use std::process::{Command, }; use crate::utils::helpers::checkers::*; pub fn create_react_app(project_name: String) -> Result<(), Box> {