cargo_tangle/command/create/
mod.rs

1pub use crate::command::create::error::Error;
2pub use crate::command::create::source::Source;
3pub use crate::command::create::types::BlueprintType;
4use crate::foundry::FoundryToolchain;
5use types::{BlueprintVariant, EigenlayerVariant};
6
7pub mod error;
8pub mod source;
9pub mod types;
10
11/// Generate a new blueprint from a template
12///
13/// # Errors
14///
15/// See [`cargo_generate::generate()`]
16pub fn new_blueprint(
17    name: &str,
18    source: Option<Source>,
19    blueprint_type: Option<BlueprintType>,
20) -> Result<(), Error> {
21    println!("Generating blueprint with name: {}", name);
22
23    let source = source.unwrap_or_default();
24    let blueprint_variant = blueprint_type.map(|t| t.get_type()).unwrap_or_default();
25    let template_path_opt: Option<cargo_generate::TemplatePath> = source.into();
26
27    let template_path = template_path_opt.unwrap_or_else(|| {
28        // TODO: Interactive selection (#352)
29        let template_repo: String = match blueprint_variant {
30            Some(BlueprintVariant::Tangle) | None => {
31                "https://github.com/tangle-network/blueprint-template".into()
32            }
33            Some(BlueprintVariant::Eigenlayer(EigenlayerVariant::BLS)) => {
34                "https://github.com/tangle-network/eigenlayer-bls-template".into()
35            }
36            Some(BlueprintVariant::Eigenlayer(EigenlayerVariant::ECDSA)) => {
37                "https://github.com/tangle-network/eigenlayer-ecdsa-template".into()
38            }
39        };
40
41        cargo_generate::TemplatePath {
42            git: Some(template_repo),
43            branch: Some(String::from("main")),
44            ..Default::default()
45        }
46    });
47
48    let path = cargo_generate::generate(cargo_generate::GenerateArgs {
49        template_path,
50        list_favorites: false,
51        name: Some(name.to_string()),
52        force: false,
53        verbose: false,
54        template_values_file: None,
55        silent: false,
56        config: None,
57        vcs: Some(cargo_generate::Vcs::Git),
58        lib: false,
59        bin: true,
60        ssh_identity: None,
61        gitconfig: None,
62        define: Vec::new(),
63        init: false,
64        destination: None,
65        force_git_init: false,
66        allow_commands: false,
67        overwrite: false,
68        skip_submodules: false,
69        other_args: Option::default(),
70        continue_on_error: false,
71        quiet: false,
72    })
73    .map_err(Error::GenerationFailed)?;
74
75    println!("Blueprint generated at: {}", path.display());
76
77    let foundry = FoundryToolchain::new();
78    if !foundry.forge.is_installed() {
79        blueprint_core::warn!("Forge not installed, skipping dependencies");
80        blueprint_core::warn!("NOTE: See <https://getfoundry.sh>");
81        blueprint_core::warn!(
82            "NOTE: After installing Forge, you can run `forge soldeer update -d` to install dependencies"
83        );
84        return Ok(());
85    }
86
87    std::env::set_current_dir(path)?;
88    if let Err(e) = foundry.forge.install_dependencies() {
89        blueprint_core::error!("{e}");
90    }
91
92    Ok(())
93}