Skip to content

Commit 627eb0b

Browse files
committed
♻️ :: 의존성을 가져오는 방법 리팩토링
ex) .Feature.BaseFeature -> .feature(target: .BaseFeature)
1 parent c4cf522 commit 627eb0b

File tree

5 files changed

+87
-75
lines changed

5 files changed

+87
-75
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
)

0 commit comments

Comments
 (0)