1pub const CONFIG_FILE: &str = ".robin.json";
2const GITHUB_TEMPLATE_BASE: &str =
3 "https://raw.githubusercontent.com/cesarferreira/robin/refs/heads/main/templates";
4
5pub mod cli;
6pub mod config;
7pub mod scripts;
8pub mod tools;
9pub mod utils;
10
11pub use cli::{Cli, Commands};
12pub use config::RobinConfig;
13pub use scripts::{interactive_mode, list_commands, run_script};
14pub use tools::{check_environment, update_tools};
15pub use utils::{check_for_update, replace_variables, send_notification, split_command_and_args};
16
17use anyhow::{Context, Result, anyhow};
18
19#[cfg(not(feature = "test-utils"))]
20pub async fn fetch_template(template_name: &str) -> Result<RobinConfig> {
21 let url = format!("{}/{}.json", GITHUB_TEMPLATE_BASE, template_name);
22 let response = reqwest::get(&url)
23 .await
24 .with_context(|| format!("Failed to fetch template from: {}", url))?;
25
26 if !response.status().is_success() {
27 return Err(anyhow!("Template '{}' not found", template_name));
28 }
29
30 let content = response
31 .text()
32 .await
33 .with_context(|| "Failed to read template content")?;
34
35 let config: RobinConfig =
36 serde_json::from_str(&content).with_context(|| "Failed to parse template JSON")?;
37
38 Ok(config)
39}
40
41#[cfg(feature = "test-utils")]
42pub async fn fetch_template(_template_name: &str) -> Result<RobinConfig> {
43 use std::collections::HashMap;
44 let mut scripts = HashMap::new();
45 scripts.insert(
46 "start".to_string(),
47 serde_json::Value::String("npm start".to_string()),
48 );
49 Ok(RobinConfig {
50 scripts,
51 include: vec![],
52 })
53}