spm_swift_package/domain/builder/
spm_builder.rs

1use crate::domain::file::project_file::*;
2use crate::domain::platform::platform_validator::*;
3
4/// Handles the creation of all project components based on selected options
5pub struct SpmBuilder;
6
7impl SpmBuilder {
8	/// Builds the project structure, templates, and optional configuration files
9	pub async fn builder(
10		project_name: &str,
11		selected_file: Vec<&str>,
12		platform: Vec<&str>,
13	) -> Result<(), String> {
14		ProjectFile::create_project(project_name)?;
15		ProjectFile::create_test_folder(project_name)?;
16
17		if selected_file.contains(&"SwiftLint") {
18			PlatformValidator::generate_platform(project_name, platform, true);
19			ProjectFile::create_swiftlint(project_name)?;
20		} else {
21			PlatformValidator::generate_platform(project_name, platform, false);
22		}
23
24		Self::validate_selected_file(project_name, selected_file).await
25	}
26
27	/// Validates which optional files must be generated based on user selection
28	async fn validate_selected_file(
29		project_name: &str,
30		selected_file: Vec<&str>,
31	) -> Result<(), String> {
32		if selected_file.contains(&"Changelog") {
33			ProjectFile::create_changelog(project_name)?;
34		}
35
36		if selected_file.contains(&"Readme") {
37			ProjectFile::create_readme(project_name)?;
38		}
39
40		if selected_file.contains(&"Swift Package Index") {
41			ProjectFile::create_spi(project_name)?;
42		}
43
44		Ok(())
45	}
46}