Skip to content

Commit 2492ae1

Browse files
authored
Merge pull request #5 from baekteun/3-internal-dependency-append-method-change
🔀 :: 내부 의존성 연결 방식 개편
2 parents c4cf522 + 9e0c6cd commit 2492ae1

File tree

6 files changed

+96
-101
lines changed

6 files changed

+96
-101
lines changed

Plugin/DependencyPlugin/ProjectDescriptionHelpers/Dependency+Target.swift

Lines changed: 0 additions & 45 deletions
This file was deleted.

Plugin/DependencyPlugin/ProjectDescriptionHelpers/ModulePaths.swift

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,63 @@ public enum ModulePaths {
99
case userInterface(UserInterface)
1010
}
1111

12+
extension ModulePaths: MicroTargetPathConvertable {
13+
public func targetName(type: MicroTargetType) -> String {
14+
switch self {
15+
case let .feature(module as any MicroTargetPathConvertable),
16+
let .domain(module as any MicroTargetPathConvertable),
17+
let .core(module as any MicroTargetPathConvertable),
18+
let .shared(module as any MicroTargetPathConvertable),
19+
let .userInterface(module as any MicroTargetPathConvertable):
20+
return module.targetName(type: type)
21+
}
22+
}
23+
}
24+
1225
public extension ModulePaths {
13-
enum Feature: String {
26+
enum Feature: String, MicroTargetPathConvertable {
1427
case BaseFeature
15-
16-
func targetName(type: MicroTargetType) -> String {
17-
"\(self.rawValue)\(type.rawValue)"
18-
}
1928
}
2029
}
2130

2231
public extension ModulePaths {
23-
enum Domain: String {
32+
enum Domain: String, MicroTargetPathConvertable {
2433
case BaseDomain
25-
26-
func targetName(type: MicroTargetType) -> String {
27-
"\(self.rawValue)\(type.rawValue)"
28-
}
2934
}
3035
}
3136

3237
public extension ModulePaths {
33-
enum Core: String {
38+
enum Core: String, MicroTargetPathConvertable {
3439
case CoreKit
35-
36-
func targetName(type: MicroTargetType) -> String {
37-
"\(self.rawValue)\(type.rawValue)"
38-
}
3940
}
4041
}
4142

4243
public extension ModulePaths {
43-
enum Shared: String {
44+
enum Shared: String, MicroTargetPathConvertable {
4445
case GlobalThirdPartyLibrary
45-
46-
func targetName(type: MicroTargetType) -> String {
47-
"\(self.rawValue)\(type.rawValue)"
48-
}
4946
}
5047
}
5148

5249
public extension ModulePaths {
53-
enum UserInterface: String {
50+
enum UserInterface: String, MicroTargetPathConvertable {
5451
case DesignSystem
55-
56-
func targetName(type: MicroTargetType) -> String {
57-
"\(self.rawValue)\(type.rawValue)"
58-
}
5952
}
6053
}
6154

6255
public enum MicroTargetType: String {
6356
case interface = "Interface"
6457
case sources = ""
6558
case testing = "Testing"
59+
case unitTest = "Tests"
60+
case demo = "Demo"
61+
}
62+
63+
public protocol MicroTargetPathConvertable {
64+
func targetName(type: MicroTargetType) -> String
65+
}
66+
67+
public extension MicroTargetPathConvertable where Self: RawRepresentable {
68+
func targetName(type: MicroTargetType) -> String {
69+
"\(self.rawValue)\(type.rawValue)"
70+
}
6671
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import Foundation
2+
import ProjectDescription
3+
4+
public extension TargetDependency {
5+
static func feature(
6+
target: ModulePaths.Feature,
7+
type: MicroTargetType = .sources
8+
) -> TargetDependency {
9+
.project(
10+
target: target.targetName(type: type),
11+
path: .relativeToFeature(target.rawValue)
12+
)
13+
}
14+
15+
static func domain(
16+
target: ModulePaths.Domain,
17+
type: MicroTargetType = .sources
18+
) -> TargetDependency {
19+
.project(
20+
target: target.targetName(type: type),
21+
path: .relativeToDomain(target.rawValue)
22+
)
23+
}
24+
25+
static func core(
26+
target: ModulePaths.Core,
27+
type: MicroTargetType = .sources
28+
) -> TargetDependency {
29+
.project(
30+
target: target.targetName(type: type),
31+
path: .relativeToCore(target.rawValue)
32+
)
33+
}
34+
35+
static func shared(
36+
target: ModulePaths.Shared,
37+
type: MicroTargetType = .sources
38+
) -> TargetDependency {
39+
.project(
40+
target: target.targetName(type: type),
41+
path: .relativeToShared(target.rawValue)
42+
)
43+
}
44+
45+
static func userInterface(
46+
target: ModulePaths.UserInterface,
47+
type: MicroTargetType = .sources
48+
) -> TargetDependency {
49+
.project(
50+
target: target.targetName(type: type),
51+
path: .relativeToUserInterface(target.rawValue)
52+
)
53+
}
54+
}

Projects/Domain/BaseDomain/Project.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ let project = Project.makeModule(
77
product: .framework,
88
targets: [.unitTest],
99
internalDependencies: [
10-
.Shared.GlobalThirdPartyLibrary,
11-
.Shared.UtilityModule
10+
.shared(target: .GlobalThirdPartyLibrary)
1211
]
1312
)

Projects/Feature/BaseFeature/Project.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ let project = Project.makeModule(
77
product: .framework,
88
targets: [.unitTest],
99
internalDependencies: [
10-
.Core.DesignSystem,
11-
.Shared.GlobalThirdPartyLibrary,
12-
.Shared.UtilityModule
10+
.userInterface(target: .DesignSystem),
11+
.shared(target: .GlobalThirdPartyLibrary)
1312
]
1413
)

Scripts/GenerateModule.swift

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ func registerModuleDependency() {
2626
registerModulePaths()
2727
makeProjectDirectory()
2828
registerXCConfig()
29-
registerMicroTarget(target: .sources)
3029
var targetString = "["
3130
if hasInterface {
32-
registerMicroTarget(target: .interface)
3331
makeScaffold(target: .interface)
3432
targetString += ".\(MicroTargetType.interface), "
3533
}
3634
if hasTesting {
37-
registerMicroTarget(target: .testing)
3835
makeScaffold(target: .testing)
3936
targetString += ".\(MicroTargetType.testing), "
4037
}
@@ -61,27 +58,12 @@ func registerModuleDependency() {
6158
func registerModulePaths() {
6259
updateFileContent(
6360
filePath: currentPath + "Plugin/DependencyPlugin/ProjectDescriptionHelpers/ModulePaths.swift",
64-
finding: "enum \(layer.rawValue): String {\n",
61+
finding: "enum \(layer.rawValue): String, MicroTargetPathConvertable {\n",
6562
inserting: " case \(moduleName)\n"
6663
)
6764
print("Register \(moduleName) to ModulePaths.swift")
6865
}
6966

70-
func registerMicroTarget(target: MicroTargetType) {
71-
let targetString = """
72-
static let \(moduleName)\(target.rawValue) = TargetDependency.project(
73-
target: ModulePaths.\(layer.rawValue).\(moduleName).targetName(type: .\(target)),
74-
path: .relativeTo\(layer.rawValue)(ModulePaths.\(layer.rawValue).\(moduleName).rawValue)
75-
)\n
76-
"""
77-
updateFileContent(
78-
filePath: currentPath + "Plugin/DependencyPlugin/ProjectDescriptionHelpers/Dependency+Target.swift",
79-
finding: "public extension TargetDependency.\(layer.rawValue) {\n",
80-
inserting: targetString
81-
)
82-
print("Register \(moduleName) \(target.rawValue) target to Dependency+Target.swift")
83-
}
84-
8567
func registerXCConfig() {
8668
makeDirectory(path: currentPath + "XCConfig/\(moduleName)")
8769
let xcconfigContent = "#include \"../Shared.xcconfig\""
@@ -220,18 +202,19 @@ print("This module has a 'Demo' Target? (y\\n, default = n)", terminator: " : ")
220202
let hasDemo = readLine()?.lowercased() == "y"
221203

222204
print("")
205+
print("""
206+
------------------------------------------------------------------------------------------------------------------------
207+
Layer: \(layer.rawValue)
208+
Module name: \(moduleName)
209+
interface: \(hasInterface), testing: \(hasTesting), unitTests: \(hasUnitTests), uiTests: \(hasUITests), demo: \(hasDemo)
210+
------------------------------------------------------------------------------------------------------------------------
211+
""")
212+
print("🔄 Module is creating ...")
223213

224214
registerModuleDependency()
225215

226-
print("")
227-
print("------------------------------------------------------------------------------------------------------------------------")
228-
print("Layer: \(layer.rawValue)")
229-
print("Module name: \(moduleName)")
230-
print("interface: \(hasInterface), testing: \(hasTesting), unitTests: \(hasUnitTests), uiTests: \(hasUITests), demo: \(hasDemo)")
231-
print("------------------------------------------------------------------------------------------------------------------------")
232216
print("✅ Module is created successfully!")
233217

234-
235218
// MARK: - Bash
236219
protocol CommandExecuting {
237220
func run(commandName: String, arguments: [String]) throws -> String

0 commit comments

Comments
 (0)