create-lamdera-app-rs 0.1.3

A CLI tool to scaffold Lamdera applications with Tailwind CSS, authentication, i18n, and testing
Documentation
use crate::error::Result;
use colored::*;
use std::path::Path;
use std::process::Command;

pub fn init_repository(project_path: &Path) -> Result<()> {
    let status = Command::new("git")
        .arg("init")
        .current_dir(project_path)
        .status()?;

    if !status.success() {
        return Err(anyhow::anyhow!("Failed to initialize git repository"));
    }

    println!("{}", "✓ Initialized git repository".green());
    Ok(())
}

pub fn add_remote(project_path: &Path, remote_url: &str) -> Result<()> {
    let status = Command::new("git")
        .args(["remote", "add", "origin", remote_url])
        .current_dir(project_path)
        .status()?;

    if !status.success() {
        return Err(anyhow::anyhow!("Failed to add git remote"));
    }

    Ok(())
}

pub fn initial_commit(project_path: &Path) -> Result<()> {
    // Add all files
    Command::new("git")
        .args(["add", "."])
        .current_dir(project_path)
        .status()?;

    // Create initial commit
    let status = Command::new("git")
        .args(["commit", "-m", "Initial commit"])
        .current_dir(project_path)
        .status()?;

    if !status.success() {
        return Err(anyhow::anyhow!("Failed to create initial commit"));
    }

    println!("{}", "✓ Created initial commit".green());
    Ok(())
}

pub fn push_to_remote(project_path: &Path) -> Result<()> {
    let status = Command::new("git")
        .args(["push", "-u", "origin", "main"])
        .current_dir(project_path)
        .status()?;

    if !status.success() {
        return Err(anyhow::anyhow!("Failed to push to remote"));
    }

    println!("{}", "✓ Pushed to remote repository".green());
    Ok(())
}

pub fn configure_hooks(project_path: &Path) -> Result<()> {
    let status = Command::new("git")
        .args(["config", "core.hooksPath", ".githooks"])
        .current_dir(project_path)
        .status()?;

    if status.success() {
        println!("{}", "✓ Configured git hooks".green());
    }

    Ok(())
}