spm_swift_package/domain/file/
project_templates.rs1pub struct ProjectTemplates;
4
5impl ProjectTemplates {
6 pub fn project_swift_content() -> String {
9 r#"// The Swift Programming Language
10// https://docs.swift.org/swift-book/
11"#
12 .to_string()
13 }
14
15 pub fn test_content(project_name: &str) -> String {
18 format!(
19 r#"import XCTest
20@testable import {}
21
22final class {}Tests: XCTestCase {{
23 func testExample() throws {{
24 // XCTest Documentation
25 // https://developer.apple.com/documentation/xctest
26
27 // Defining Test Cases and Test Methods
28 // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
29 }}
30}}
31"#,
32 project_name, project_name,
33 )
34 }
35
36 pub fn package_swift_content(
44 project_name: &str,
45 platform: &str,
46 version: &str,
47 is_plugin: bool,
48 ) -> String {
49 if is_plugin {
50 format!(
51 r#"// swift-tools-version: 6.2
52// The swift-tools-version declares the minimum version of Swift required to build this package.
53
54import PackageDescription
55
56let package = Package(
57 name: "{}",
58 platforms: [
59 .{}(.v{})
60 ],
61 products: [
62 // Products define the executables and libraries a package produces, making them visible to other packages.
63 .library(
64 name: "{}",
65 targets: ["{}"]),
66 ],
67 dependencies: [
68 .package(url: "https://github.com/lukepistrol/SwiftLintPlugin", exact: "0.62.2")
69 ],
70 targets: [
71 // Targets are the basic building blocks of a package, defining a module or a test suite.
72 // Targets can depend on other targets in this package and products from dependencies.
73 .target(
74 name: "{}",
75 plugins: [
76 .plugin(name: "SwiftLint", package: "SwiftLintPlugin")
77 ]
78 ),
79 .testTarget(
80 name: "{}Tests",
81 dependencies: ["{}"]
82 ),
83 ]
84)
85"#,
86 project_name,
87 platform,
88 version,
89 project_name,
90 project_name,
91 project_name,
92 project_name,
93 project_name,
94 )
95 } else {
96 format!(
97 r#"// swift-tools-version: 6.2
98// The swift-tools-version declares the minimum version of Swift required to build this package.
99
100import PackageDescription
101
102let package = Package(
103 name: "{}",
104 platforms: [
105 .{}(.v{})
106 ],
107 products: [
108 // Products define the executables and libraries a package produces, making them visible to other packages.
109 .library(
110 name: "{}",
111 targets: ["{}"]),
112 ],
113 targets: [
114 // Targets are the basic building blocks of a package, defining a module or a test suite.
115 // Targets can depend on other targets in this package and products from dependencies.
116 .target(
117 name: "{}"
118 ),
119 .testTarget(
120 name: "{}Tests",
121 dependencies: ["{}"]
122 ),
123 ]
124)
125"#,
126 project_name,
127 platform,
128 version,
129 project_name,
130 project_name,
131 project_name,
132 project_name,
133 project_name,
134 )
135 }
136 }
137
138 pub fn changelog_content() -> String {
141 r#"# CHANGELOG
142
143## Version 1.0.0
144**2024-01-18**
145
146- First release
147"#
148 .to_string()
149 }
150
151 pub fn readme_content(project_name: &str) -> String {
154 format!(
155 r#"# {}
156"#,
157 project_name
158 )
159 }
160
161 pub fn spi_content(project_name: &str) -> String {
164 format!(
165 r#"version: 1
166builder:
167 configs:
168 - documentation_targets: [{}]
169 scheme: {}
170"#,
171 project_name, project_name
172 )
173 }
174
175 pub fn swiftlint_content() -> String {
178 r#"disabled_rules:
179 - trailing_whitespace
180
181vertical_whitespace:
182 severity: error
183
184opt_in_rules:
185 - empty_count
186 - comma
187
188excluded:
189 - Pods
190 - Carthage
191 - Fastlane
192"#
193 .to_string()
194 }
195}