1use anyhow::{Context, Result};
2use colored::Colorize;
3use std::process::Command;
4
5pub async fn deploy(provider: &str) -> Result<()> {
6 match provider.to_lowercase().as_str() {
7 "vercel" | "vercel.app" => deploy_to_vercel().await,
8 _ => {
9 println!(
10 "{}",
11 format!(" ⚠ Provider '{}' not yet supported", provider)
12 .yellow()
13 .dimmed()
14 );
15 println!("{}", " Supported providers: vercel".dimmed());
16 Ok(())
17 }
18 }
19}
20
21async fn deploy_to_vercel() -> Result<()> {
22 println!("{}", " Step 1: Building facilitator...".dimmed());
23
24 let build_result = Command::new("cargo")
25 .args(["build", "--release"])
26 .output()
27 .context("Failed to build project")?;
28
29 if !build_result.status.success() {
30 let error = String::from_utf8_lossy(&build_result.stderr);
31 anyhow::bail!("Build failed: {}", error);
32 }
33
34 println!("{}", " ✓ Build successful".green().dimmed());
35
36 println!(
37 "{}",
38 " Step 2: Checking for vercel installation...".dimmed()
39 );
40
41 let check_result = Command::new("vercel").arg("--version").output();
42
43 match check_result {
44 Ok(output) if output.status.success() => {
45 println!("{}", " ✓ Vercel CLI installed".green().dimmed());
46 }
47 _ => {
48 println!(
49 "{}",
50 " ℹ Vercel CLI not found. Installing...".yellow().dimmed()
51 );
52 println!("{}", " Run: npm install -g vercel".dimmed());
53 return Ok(());
54 }
55 }
56
57 println!("{}", " Step 3: Deploying facilitator...".dimmed());
58
59 let deploy_result = Command::new("vercel")
60 .args(["--prod"])
61 .output()
62 .context("Failed to execute vercel deploy")?;
63
64 let _output = String::from_utf8_lossy(&deploy_result.stdout);
65
66 if deploy_result.status.success() {
67 println!("{}", " ✓ Deployment initiated".green().dimmed());
68 println!(
69 "{}",
70 " Check Vercel dashboard for deployment status".dimmed()
71 );
72 println!("{}", " Typically: https://vercel.com/dashboard".dimmed());
73 } else {
74 let error = String::from_utf8_lossy(&deploy_result.stderr);
75 println!(
76 "{}",
77 format!(" ⚠ Deployment may have failed: {}", error)
78 .yellow()
79 .dimmed()
80 );
81 }
82
83 println!();
84 println!("{}", "Deployment Summary".cyan().bold());
85 println!(
86 "{}",
87 " Follow the Vercel CLI prompts to complete deployment".dimmed()
88 );
89 println!(
90 "{}",
91 " Your facilitator will be deployed with a public URL".dimmed()
92 );
93
94 Ok(())
95}