Skip to main content

robin/
lib.rs

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::{
13    RobinConfig, find_config_from, find_config_path, script_command, script_description,
14};
15pub use scripts::{
16    command_lines, interactive_mode, list_commands, resolve_task_command, run_script,
17    run_script_in,
18};
19pub use tools::{check_environment, update_tools};
20pub use utils::{
21    check_for_update, load_env_file, replace_variables, send_notification, split_command_and_args,
22};
23
24use anyhow::{Context, Result, anyhow};
25
26#[cfg(not(feature = "test-utils"))]
27pub async fn fetch_template(template_name: &str) -> Result<RobinConfig> {
28    let url = format!("{}/{}.json", GITHUB_TEMPLATE_BASE, template_name);
29    let response = reqwest::get(&url)
30        .await
31        .with_context(|| format!("Failed to fetch template from: {}", url))?;
32
33    if !response.status().is_success() {
34        return Err(anyhow!("Template '{}' not found", template_name));
35    }
36
37    let content = response
38        .text()
39        .await
40        .with_context(|| "Failed to read template content")?;
41
42    let config: RobinConfig =
43        serde_json::from_str(&content).with_context(|| "Failed to parse template JSON")?;
44
45    Ok(config)
46}
47
48#[cfg(feature = "test-utils")]
49pub async fn fetch_template(_template_name: &str) -> Result<RobinConfig> {
50    use std::collections::HashMap;
51    let mut scripts = HashMap::new();
52    scripts.insert(
53        "start".to_string(),
54        serde_json::Value::String("npm start".to_string()),
55    );
56    Ok(RobinConfig {
57        schema: None,
58        scripts,
59        include: vec![],
60    })
61}