Skip to content

Commit

Permalink
Merge pull request #5 from baekteun/3-internal-dependency-append-meth…
Browse files Browse the repository at this point in the history
…od-change

🔀 :: 내부 의존성 연결 방식 개편
  • Loading branch information
baekteun committed Jun 27, 2023
2 parents c4cf522 + 9e0c6cd commit 2492ae1
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 101 deletions.

This file was deleted.

55 changes: 30 additions & 25 deletions Plugin/DependencyPlugin/ProjectDescriptionHelpers/ModulePaths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,63 @@ public enum ModulePaths {
case userInterface(UserInterface)
}

extension ModulePaths: MicroTargetPathConvertable {
public func targetName(type: MicroTargetType) -> String {
switch self {
case let .feature(module as any MicroTargetPathConvertable),
let .domain(module as any MicroTargetPathConvertable),
let .core(module as any MicroTargetPathConvertable),
let .shared(module as any MicroTargetPathConvertable),
let .userInterface(module as any MicroTargetPathConvertable):
return module.targetName(type: type)
}
}
}

public extension ModulePaths {
enum Feature: String {
enum Feature: String, MicroTargetPathConvertable {
case BaseFeature

func targetName(type: MicroTargetType) -> String {
"\(self.rawValue)\(type.rawValue)"
}
}
}

public extension ModulePaths {
enum Domain: String {
enum Domain: String, MicroTargetPathConvertable {
case BaseDomain

func targetName(type: MicroTargetType) -> String {
"\(self.rawValue)\(type.rawValue)"
}
}
}

public extension ModulePaths {
enum Core: String {
enum Core: String, MicroTargetPathConvertable {
case CoreKit

func targetName(type: MicroTargetType) -> String {
"\(self.rawValue)\(type.rawValue)"
}
}
}

public extension ModulePaths {
enum Shared: String {
enum Shared: String, MicroTargetPathConvertable {
case GlobalThirdPartyLibrary

func targetName(type: MicroTargetType) -> String {
"\(self.rawValue)\(type.rawValue)"
}
}
}

public extension ModulePaths {
enum UserInterface: String {
enum UserInterface: String, MicroTargetPathConvertable {
case DesignSystem

func targetName(type: MicroTargetType) -> String {
"\(self.rawValue)\(type.rawValue)"
}
}
}

public enum MicroTargetType: String {
case interface = "Interface"
case sources = ""
case testing = "Testing"
case unitTest = "Tests"
case demo = "Demo"
}

public protocol MicroTargetPathConvertable {
func targetName(type: MicroTargetType) -> String
}

public extension MicroTargetPathConvertable where Self: RawRepresentable {
func targetName(type: MicroTargetType) -> String {
"\(self.rawValue)\(type.rawValue)"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Foundation
import ProjectDescription

public extension TargetDependency {
static func feature(
target: ModulePaths.Feature,
type: MicroTargetType = .sources
) -> TargetDependency {
.project(
target: target.targetName(type: type),
path: .relativeToFeature(target.rawValue)
)
}

static func domain(
target: ModulePaths.Domain,
type: MicroTargetType = .sources
) -> TargetDependency {
.project(
target: target.targetName(type: type),
path: .relativeToDomain(target.rawValue)
)
}

static func core(
target: ModulePaths.Core,
type: MicroTargetType = .sources
) -> TargetDependency {
.project(
target: target.targetName(type: type),
path: .relativeToCore(target.rawValue)
)
}

static func shared(
target: ModulePaths.Shared,
type: MicroTargetType = .sources
) -> TargetDependency {
.project(
target: target.targetName(type: type),
path: .relativeToShared(target.rawValue)
)
}

static func userInterface(
target: ModulePaths.UserInterface,
type: MicroTargetType = .sources
) -> TargetDependency {
.project(
target: target.targetName(type: type),
path: .relativeToUserInterface(target.rawValue)
)
}
}
3 changes: 1 addition & 2 deletions Projects/Domain/BaseDomain/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let project = Project.makeModule(
product: .framework,
targets: [.unitTest],
internalDependencies: [
.Shared.GlobalThirdPartyLibrary,
.Shared.UtilityModule
.shared(target: .GlobalThirdPartyLibrary)
]
)
5 changes: 2 additions & 3 deletions Projects/Feature/BaseFeature/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ let project = Project.makeModule(
product: .framework,
targets: [.unitTest],
internalDependencies: [
.Core.DesignSystem,
.Shared.GlobalThirdPartyLibrary,
.Shared.UtilityModule
.userInterface(target: .DesignSystem),
.shared(target: .GlobalThirdPartyLibrary)
]
)
35 changes: 9 additions & 26 deletions Scripts/GenerateModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ func registerModuleDependency() {
registerModulePaths()
makeProjectDirectory()
registerXCConfig()
registerMicroTarget(target: .sources)
var targetString = "["
if hasInterface {
registerMicroTarget(target: .interface)
makeScaffold(target: .interface)
targetString += ".\(MicroTargetType.interface), "
}
if hasTesting {
registerMicroTarget(target: .testing)
makeScaffold(target: .testing)
targetString += ".\(MicroTargetType.testing), "
}
Expand All @@ -61,27 +58,12 @@ func registerModuleDependency() {
func registerModulePaths() {
updateFileContent(
filePath: currentPath + "Plugin/DependencyPlugin/ProjectDescriptionHelpers/ModulePaths.swift",
finding: "enum \(layer.rawValue): String {\n",
finding: "enum \(layer.rawValue): String, MicroTargetPathConvertable {\n",
inserting: " case \(moduleName)\n"
)
print("Register \(moduleName) to ModulePaths.swift")
}

func registerMicroTarget(target: MicroTargetType) {
let targetString = """
static let \(moduleName)\(target.rawValue) = TargetDependency.project(
target: ModulePaths.\(layer.rawValue).\(moduleName).targetName(type: .\(target)),
path: .relativeTo\(layer.rawValue)(ModulePaths.\(layer.rawValue).\(moduleName).rawValue)
)\n
"""
updateFileContent(
filePath: currentPath + "Plugin/DependencyPlugin/ProjectDescriptionHelpers/Dependency+Target.swift",
finding: "public extension TargetDependency.\(layer.rawValue) {\n",
inserting: targetString
)
print("Register \(moduleName) \(target.rawValue) target to Dependency+Target.swift")
}

func registerXCConfig() {
makeDirectory(path: currentPath + "XCConfig/\(moduleName)")
let xcconfigContent = "#include \"../Shared.xcconfig\""
Expand Down Expand Up @@ -220,18 +202,19 @@ print("This module has a 'Demo' Target? (y\\n, default = n)", terminator: " : ")
let hasDemo = readLine()?.lowercased() == "y"

print("")
print("""
------------------------------------------------------------------------------------------------------------------------
Layer: \(layer.rawValue)
Module name: \(moduleName)
interface: \(hasInterface), testing: \(hasTesting), unitTests: \(hasUnitTests), uiTests: \(hasUITests), demo: \(hasDemo)
------------------------------------------------------------------------------------------------------------------------
""")
print("🔄 Module is creating ...")

registerModuleDependency()

print("")
print("------------------------------------------------------------------------------------------------------------------------")
print("Layer: \(layer.rawValue)")
print("Module name: \(moduleName)")
print("interface: \(hasInterface), testing: \(hasTesting), unitTests: \(hasUnitTests), uiTests: \(hasUITests), demo: \(hasDemo)")
print("------------------------------------------------------------------------------------------------------------------------")
print("✅ Module is created successfully!")


// MARK: - Bash
protocol CommandExecuting {
func run(commandName: String, arguments: [String]) throws -> String
Expand Down

0 comments on commit 2492ae1

Please sign in to comment.