| 17 | } |
| 18 | |
| 19 | pub fn generate(&self) -> Result<(), String> { |
| 20 | // Check if directory already exists |
| 21 | if self.project_path.exists() { |
| 22 | return Err(format!( |
| 23 | "Error: Directory '{}' already exists", |
| 24 | self.project_name |
| 25 | )); |
| 26 | } |
| 27 | |
| 28 | // Create project directory |
| 29 | fs::create_dir_all(&self.project_path).map_err(|e| { |
| 30 | format!( |
| 31 | "Failed to create project directory '{}': {}", |
| 32 | self.project_name, e |
| 33 | ) |
| 34 | })?; |
| 35 | |
| 36 | // Create standard directories |
| 37 | self.create_directories()?; |
| 38 | |
| 39 | // Create project.toml |
| 40 | self.create_project_toml()?; |
| 41 | |
| 42 | // Create basic example file |
| 43 | self.create_example_file()?; |
| 44 | |
| 45 | println!( |
| 46 | "Successfully created new AIScript project: {}", |
| 47 | self.project_name |
| 48 | ); |
| 49 | println!("Project structure:"); |
| 50 | println!("{}", self.display_project_structure()); |
| 51 | println!(); |
| 52 | println!("Run `aiscript serve` to start the server."); |
| 53 | |
| 54 | Ok(()) |
| 55 | } |
| 56 | |
| 57 | fn create_directories(&self) -> Result<(), String> { |
| 58 | let dirs = vec!["lib", "routes"]; |