spm_swift_package/domain/file/
project_templates.rs1pub struct ProjectTemplates;
2
3impl ProjectTemplates {
4 pub fn project_swift_content() -> String {
5 r#"// The Swift Programming Language
6// https://docs.swift.org/swift-book/
7"#
8 .to_string()
9 }
10
11 pub fn test_content(project_name: &str) -> String {
12 format!(
13 r#"import XCTest
14@testable import {}
15
16final class {}Tests: XCTestCase {{
17 func testExample() throws {{
18 // XCTest Documentation
19 // https://developer.apple.com/documentation/xctest
20
21 // Defining Test Cases and Test Methods
22 // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
23 }}
24}}
25"#,
26 project_name, project_name,
27 )
28 }
29
30 pub fn package_swift_content(project_name: &str, platform: &str, version: &str) -> String {
31 format!(
32 r#"// swift-tools-version: 6.2
33// The swift-tools-version declares the minimum version of Swift required to build this package.
34
35import PackageDescription
36
37let package = Package(
38 name: "{}",
39 platforms: [
40 .{}(.v{})
41 ],
42 products: [
43 // Products define the executables and libraries a package produces, making them visible to other packages.
44 .library(
45 name: "{}",
46 targets: ["{}"]),
47 ],
48 targets: [
49 // Targets are the basic building blocks of a package, defining a module or a test suite.
50 // Targets can depend on other targets in this package and products from dependencies.
51 .target(
52 name: "{}"),
53 .testTarget(
54 name: "{}Tests",
55 dependencies: ["{}"]
56 ),
57 ]
58)
59"#,
60 project_name,
61 platform,
62 version,
63 project_name,
64 project_name,
65 project_name,
66 project_name,
67 project_name,
68 )
69 }
70
71 pub fn changelog_content() -> String {
72 r#"# CHANGELOG
73
74## Version 1.0.0
75**2024-01-18**
76
77- First release
78"#
79 .to_string()
80 }
81
82 pub fn readme_content(project_name: &str) -> String {
83 format!(
84 r#"# {}
85"#,
86 project_name
87 )
88 }
89
90 pub fn spi_content(project_name: &str) -> String {
91 format!(
92 r#"version: 1
93builder:
94 configs:
95 - documentation_targets: [{}]
96 scheme: {}
97"#,
98 project_name, project_name
99 )
100 }
101
102 pub fn swiftlint_content() -> String {
103 r#"disabled_rules:
104 - line_length
105 - force_try
106 - identifier_name
107 - trailing_whitespace
108 - force_cast
109 - colon
110 - implicit_getter
111 - void_return
112 - unused_enumerated
113 - function_parameter_count
114 - file_length
115
116vertical_whitespace:
117 severity: error
118
119opt_in_rules:
120 - empty_count
121 - comma
122
123excluded:
124 - Pods
125 - Carthage
126 - Fastlane
127"#
128 .to_string()
129 }
130
131 pub fn mise_content(tag: &str) -> String {
132 format!(
133 r#"[tools]
134swiftlint = "{}"
135"#,
136 tag
137 )
138 }
139}