diff --git a/README.md b/README.md index c936461..89cb81d 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ The `scaffold` action is used to scaffold projects for different development too - Foundry - Vue - Vite +- Starknet Foundry #### ReactJS Creates a React project with JavaScript @@ -112,6 +113,12 @@ Creates (Vanilla TypeScript, Vue, React, Preact, Lit, Svelte) project using Vite resolver-cli scaffold vite project_name ``` +#### Starknet Foundry +Creates a starknet project +```sh +resolver-cli scaffold snforge project_name +``` + The `install` action installs development tools like Node.js, Homebrew, Choco, Scarb, e.t.c. - To install node, run: @@ -126,4 +133,10 @@ The `install` action installs development tools like Node.js, Homebrew, Choco, S - To install scarb, run: ```resolver-cli install scarb``` +- To install latest version of starknet foundry, run: +```resolver-cli install snfoundry latest``` + +- To install a specific version of starknet foundry, run: +```resolver-cli install snfoundry $versionName``` + Run `resolver-cli install --help` to see all supported installation tools. diff --git a/src/lib.rs b/src/lib.rs index f6dbb84..4a63c1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,6 +140,14 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box> { return Err(e); } } + }, + ScaffoldSubCommand::Snforge(dir) => { + match create_starknet_foundry_project(dir.dir_name.clone()) { + Ok(_) => println!("{}", "Successfully created a starknet foundry project!".bright_blue()), + Err(e) => { + return Err(e); + } + } } } }, @@ -201,6 +209,22 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box> { } } }, + // InstallSubCommand::Snfoundry => { + // match install_snforge() { + // Ok(_) => println!("{}", "Starknet Foundry installatin successful!".bright_blue()), + // Err(e) => { + // return Err(e) + // } + // } + // }, + InstallSubCommand::Snfoundry(ver) => { + match install_snforge(ver.version_name.clone()) { + Ok(_) => println!("{}", "Starknet Foundry installation successful!".bright_blue()), + Err(e) => { + return Err(e) + } + } + } } } } diff --git a/src/utils/command_arguments.rs b/src/utils/command_arguments.rs index 954acdd..28ff4dd 100644 --- a/src/utils/command_arguments.rs +++ b/src/utils/command_arguments.rs @@ -73,6 +73,8 @@ pub enum ScaffoldSubCommand { Vite(GetDir), /// Scaffold a Noir project Noir(GetDir), + /// Scaffold a Starknet Foundry project + Snforge(GetDir), } // ---------------- @@ -99,7 +101,9 @@ pub enum InstallSubCommand { /// Installs Starkli Starkli, /// Installs Nargo - Noir + Noir, + // installs Starknet Foundry + Snfoundry(Version), } // -------------------------------------- @@ -110,3 +114,8 @@ pub struct GetDir { /// Specifies the name of the project directory to initialize pub dir_name: String } + +#[derive(Debug, Args)] +pub struct Version { + pub version_name: String +} diff --git a/src/utils/helpers.rs b/src/utils/helpers.rs index b3c5f05..b567007 100644 --- a/src/utils/helpers.rs +++ b/src/utils/helpers.rs @@ -295,62 +295,65 @@ pub fn create_noir_project(project_name: String) -> Result<(), Box> { } } +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(()) + } +} + // ------------------- // Installer functions // ------------------- pub fn install_brew() -> Result<(), Box> { - if is_brew_installed() { - return Err("Brew is already installed!".into()); - } else { - println!("Installing Homebrew..."); + println!("Installing Homebrew..."); - let script_url = "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"; - let command = format!("curl -fsSL {} | /bin/bash", script_url); + 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()?; + Command::new("sh") + .arg("-c") + .arg(command) + .output()?; - Ok(()) - } + Ok(()) } pub fn install_choco() -> Result<(), Box> { - if is_choco_installed() { - return Err("Chocolatey is already installed!".into()); - } else { - println!("Installing Chocolatey"); + 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')) - "#; + 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()?; + Command::new("powershell") + .arg("-Command") + .arg(powershell_script) + .output()?; - Ok(()) - } + Ok(()) } pub fn install_node() -> Result<(), Box> { - if is_node_installed() { - return Err("Node is already installed!".into()); - } else { - // 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") - } + 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") } } @@ -395,73 +398,96 @@ pub fn install_node_windows() -> Result<(), Box> { } pub fn install_scarb() -> Result<(), Box> { - if is_scarb_installed() { - return Err("Scarb is already installed!".into()); - } else { - let install_cmd = "curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh"; + println!("Installing the Latest Version of Scarb..."); - Command::new("sh") - .arg("-c") - .arg(install_cmd) - .output()?; + let install_cmd = "curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh"; - Ok(()) - } + Command::new("sh") + .arg("-c") + .arg(install_cmd) + .output()?; + + Ok(()) } pub fn install_starkli() -> Result<(), Box> { - if is_starkli_installed() { - return Err("Starkli is already installed!".into()); - } else { - Command::new("sh") - .arg("-c") - .arg("curl https://get.starkli.sh | sh") - .output()?; + println!("Installing the Latest Version of Starkli..."); - Command::new("sh") - .arg("-c") - .arg("starkliup") - .output()?; + Command::new("sh") + .arg("-c") + .arg("curl https://get.starkli.sh | sh") + .output()?; - Ok(()) - } + Command::new("sh") + .arg("-c") + .arg("starkliup") + .output()?; + + Ok(()) } pub fn install_composer() {} pub fn install_forge() -> Result<(), Box> { - if is_forge_installed() { - return Err("Forge is already installed!".into()); - } else { + 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://foundry.paradigm.xyz | bash") + .arg("curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh") .output()?; Command::new("sh") .arg("-c") - .arg("foundryup") + .arg("snfoundryup") .output()?; Ok(()) - } -} - - -pub fn install_nargo() -> Result<(), Box> { - if is_nargo_installed() { - return Err("nargo is already installed!".into()); } else { + println!("Installing Version {} of Starknet Foundry, Please wait...", version); + Command::new("sh") - .arg("-c") - .arg("curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash") + .args(["-c", "curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh"]) .output()?; Command::new("sh") - .arg("-c") - .arg("noirup") + .args(["-c", "snfoundryup", "-v", version.as_str()]) .output()?; Ok(()) } + }