vika_cli/commands/
init.rs1use crate::config::loader::save_config;
2use crate::config::model::Config;
3use crate::config::validator::validate_config;
4use crate::error::Result;
5use crate::generator::writer::{ensure_directory, write_http_client_template};
6use colored::*;
7use std::path::PathBuf;
8
9pub fn run() -> Result<()> {
10 println!("{}", "Initializing vika-cli project...".bright_cyan());
11
12 let config_path = PathBuf::from(".vika.json");
14 if config_path.exists() {
15 println!(
16 "{}",
17 "⚠️ .vika.json already exists. Skipping config creation.".yellow()
18 );
19 } else {
20 let config = Config::default();
21 validate_config(&config)?;
22 save_config(&config)?;
23 println!("{}", "✅ Created .vika.json".green());
24 }
25
26 let config = crate::config::loader::load_config()?;
28
29 let root_dir = PathBuf::from(&config.root_dir);
30 ensure_directory(&root_dir)?;
31
32 let schemas_dir = PathBuf::from(&config.schemas.output);
33 ensure_directory(&schemas_dir)?;
34
35 let apis_dir = PathBuf::from(&config.apis.output);
36 ensure_directory(&apis_dir)?;
37
38 let http_client_path = apis_dir.join("http.ts");
40 if !http_client_path.exists() {
41 write_http_client_template(&http_client_path)?;
42 println!(
43 "{}",
44 format!("✅ Created {}", http_client_path.display()).green()
45 );
46 } else {
47 println!(
48 "{}",
49 format!(
50 "⚠️ {} already exists. Skipping.",
51 http_client_path.display()
52 )
53 .yellow()
54 );
55 }
56
57 println!();
58 println!("{}", "✨ Project initialized successfully!".bright_green());
59 println!();
60 println!("Next steps:");
61 println!(" 1. Run: vika-cli generate --spec <path-or-url-to-swagger>");
62 println!(" 2. Select the modules you want to generate");
63
64 Ok(())
65}