forked from OffchainLabs/cargo-stylus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::{fs, path::PathBuf}; | ||
|
||
use eyre::{Context, OptionExt, Result}; | ||
|
||
pub mod rust; | ||
|
||
/// Type alias for templates - file names paired up with their respective content | ||
pub type Template = Vec<(PathBuf, String)>; | ||
|
||
/// Bring a template to life in a given directory | ||
pub fn realise(template: Template) -> Result<()> { | ||
template.into_iter().try_for_each(|(path, contents)| { | ||
fs::create_dir_all( | ||
path.parent() | ||
.ok_or_eyre(format!("Could not get parent of {}", path.display()))?, | ||
) | ||
.wrap_err(format!( | ||
"Could not create needed directories for {}", | ||
path.display() | ||
))?; | ||
fs::write(&path, contents).wrap_err(format!("Failed to write file {}", path.display()))?; | ||
println!("Created file {}", path.display()); | ||
Ok(()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#![allow(clippy::useless_format)] | ||
|
||
use std::path::Path; | ||
|
||
use eyre::Result; | ||
use indoc::indoc; | ||
|
||
use super::Template; | ||
|
||
pub fn basic_template(name: String, base: impl AsRef<Path>) -> Result<Template> { | ||
let base = base.as_ref(); | ||
|
||
Ok(vec![ | ||
( | ||
base.join("Cargo.toml"), | ||
format!( | ||
indoc! {r#" | ||
[package] | ||
name = "{}" | ||
version = "0.1.0" | ||
edition = "2021" | ||
[dependencies] | ||
alloy-primitives = "0.4.0" | ||
eyre = "0.6.12" | ||
"#}, | ||
name | ||
), | ||
), | ||
( | ||
base.join("src/main.rs"), | ||
format!( | ||
indoc! {r#" | ||
use eyre::Result; | ||
pub fn main() -> Result<()> {{ | ||
println!("{{}}", "{}"); | ||
Ok(()) | ||
}} | ||
"#}, | ||
"Hello" | ||
), | ||
), | ||
( | ||
base.join("Makefile"), | ||
// NOTE: beware of the tab literals | ||
format!( | ||
indoc! {r#" | ||
run: build | ||
cargo run | ||
build: | ||
cargo build | ||
love: | ||
@echo "not war" | ||
"#} | ||
), | ||
), | ||
]) | ||
} |