Skip to content

Commit

Permalink
Merge pull request #23 from Realkayzee/feat/starknet-foundry
Browse files Browse the repository at this point in the history
Feat/starknet foundry
  • Loading branch information
casweeney authored Apr 28, 2024
2 parents f68209d + 72fe263 commit 884d333
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 79 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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.
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box<dyn Error>> {
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);
}
}
}
}
},
Expand Down Expand Up @@ -201,6 +209,22 @@ pub fn resolve(args: ClapperArgs) -> Result<(), Box<dyn Error>> {
}
}
},
// 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)
}
}
}
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/utils/command_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub enum ScaffoldSubCommand {
Vite(GetDir),
/// Scaffold a Noir project
Noir(GetDir),
/// Scaffold a Starknet Foundry project
Snforge(GetDir),
}

// ----------------
Expand All @@ -99,7 +101,9 @@ pub enum InstallSubCommand {
/// Installs Starkli
Starkli,
/// Installs Nargo
Noir
Noir,
// installs Starknet Foundry
Snfoundry(Version),
}

// --------------------------------------
Expand All @@ -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
}
182 changes: 104 additions & 78 deletions src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,62 +295,65 @@ pub fn create_noir_project(project_name: String) -> Result<(), Box<dyn Error>> {
}
}

pub fn create_starknet_foundry_project(project_name: String) -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
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<dyn Error>> {
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<dyn Error>> {
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")
}
}

Expand Down Expand Up @@ -395,73 +398,96 @@ pub fn install_node_windows() -> Result<(), Box<dyn Error>> {
}

pub fn install_scarb() -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
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<dyn Error>> {
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<dyn Error>> {
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<dyn Error>> {
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<dyn Error>> {
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(())
}

}

0 comments on commit 884d333

Please sign in to comment.