Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#349] Add the domain and data layers as targets (modules) in the project #536

Merged
merged 5 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Alamofire

@testable import {PROJECT_NAME}
@testable import Data

struct DummyRequestConfiguration: RequestConfiguration {

Expand All @@ -24,6 +24,6 @@ extension DummyRequestConfiguration: RequestConfigurationStubable {
}

var path: String {
(try? url.asURL().path).string
(try? url.asURL().path) ?? ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Nimble
import Quick

@testable import {PROJECT_NAME}
@testable import Data

final class NetworkAPISpec: AsyncSpec {

Expand Down
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions Modules/Domain/Tests/Sources/Specs/DummySpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// TODO: Remove this file

import Nimble
import Quick

@testable import Domain

final class DummySpec: QuickSpec {

override class func spec() {

describe("A Dummy") {

context("given a dummy message") {
let message = "Hello"

it("equals Hello") {
expect(message) == "Hello"
}
}
}
}
}
8 changes: 3 additions & 5 deletions Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ let project = Project.project(name: "{PROJECT_NAME}", bundleId: "${PRODUCT_BUNDL
extension Project {

static func project(name: String, bundleId: String) -> Project {
let targets = Target.makeTargets(name: name, bundleId: bundleId)

return Project(
name: name,
organizationName: "Nimble",
Expand All @@ -16,11 +18,7 @@ extension Project {
settings: .settings(
configurations: BuildConfiguration.allCases.map { $0.createConfiguration(projectName: name) }
),
targets: [
.mainTarget(name: name, bundleId: bundleId),
.testsTarget(name: name, bundleId: bundleId),
.kifUITestsTarget(name: name, bundleId: bundleId),
],
targets: targets,
schemes: [
.productionScheme(name: name),
.stagingScheme(name: name),
Expand Down
20 changes: 20 additions & 0 deletions Tuist/Interfaces/SwiftUI/Project/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ target '{PROJECT_NAME}' do
end
end

def data_dependencies
pod 'Alamofire'
pod 'JSONAPIMapper', :git => 'https://github.com/nimblehq/JSONMapper', :tag => '1.1.1'
end

target 'Data' do
data_dependencies

target 'DataTests' do
data_dependencies
testing_pods
end
end

target 'Domain' do
target 'DomainTests' do
testing_pods
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
Expand Down
23 changes: 19 additions & 4 deletions Tuist/Interfaces/UIKit/Project/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ target '{PROJECT_NAME}' do
pod 'Kingfisher'
pod 'SnapKit'

# Backend
pod 'Alamofire'
pod 'JSONAPIMapper', :git => 'https://github.com/nimblehq/JSONMapper', :tag => '1.1.1'

# Storage
pod 'KeychainAccess'

Expand Down Expand Up @@ -48,6 +44,25 @@ target '{PROJECT_NAME}' do
end
end

def data_dependencies
pod 'Alamofire'
pod 'JSONAPIMapper', :git => 'https://github.com/nimblehq/JSONMapper', :tag => '1.1.1'
end

target 'Data' do
data_dependencies
target 'DataTests' do
data_dependencies
testing_pods
end
end

target 'Domain' do
target 'DomainTests' do
testing_pods
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
Expand Down
15 changes: 15 additions & 0 deletions Tuist/ProjectDescriptionHelpers/Constant.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Constant.swift
// ProjectDescriptionHelpers
//
// Created by Phong on 22/10/2023.
//

public enum Constant {

static let plistsPath = "Configurations/Plists"
static let modulesRootPath = "Modules"
static let sourcesPath = "Sources"
static let resourcesPath = "Resources"
static let testsPath = "Tests"
}
64 changes: 64 additions & 0 deletions Tuist/ProjectDescriptionHelpers/Module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// Modules.swift
// ProjectDescriptionHelpers
//
// Created by Phong on 16/10/2023.
//

import ProjectDescription

public enum Module: CaseIterable {

case domain
case data

public var name: String {
switch self {
case .domain:
return "Domain"
case .data:
return "Data"
}
}

public var dependencies: [TargetDependency] {
switch self {
case .domain:
return []
case .data:
return [.target(name: Module.domain.name)]
}
}

public var frameworkPath: String {
"\(Constant.modulesRootPath)/\(name)"
}

public var sources: ProjectDescription.SourceFilesList {
["\(frameworkPath)/\(Constant.sourcesPath)/**"]
}

public var resources: ProjectDescription.ResourceFileElements {
[]
}

public var testsSources: ProjectDescription.SourceFilesList {
["\(frameworkPath)/\(Constant.testsPath)/**"]
}

public var testsResources: ProjectDescription.ResourceFileElements {
[
"\(frameworkPath)/\(Constant.testsPath)/**/.gitkeep",
"\(frameworkPath)/\(Constant.testsPath)/\(Constant.resourcesPath)/**"
]
}


public func getBundleId(mainBundleId: String) -> String {
"\(mainBundleId).\(name)"
}

public func getTestBundleId(mainBundleId: String) -> String {
"\(mainBundleId).\(name)\(Constant.testsPath)"
}
}
22 changes: 12 additions & 10 deletions Tuist/ProjectDescriptionHelpers/Scheme+Initializing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ extension Scheme {
public static func productionScheme(name: String) -> Scheme {
let debugConfigName = BuildConfiguration.debugProduction.name
let releaseConfigName = BuildConfiguration.releaseProduction.name
let testModules = testSchemes(name)

return Scheme(
name: name,
shared: true,
buildAction: .buildAction(targets: ["\(name)"]),
testAction: .targets(
["\(name)Tests", "\(name)KIFUITests"],
configuration: debugConfigName
),
testAction: .targets(testModules, configuration: debugConfigName),
runAction: .runAction(configuration: debugConfigName),
archiveAction: .archiveAction(configuration: releaseConfigName),
profileAction: .profileAction(configuration: debugConfigName),
Expand All @@ -23,14 +22,13 @@ extension Scheme {
public static func stagingScheme(name: String) -> Scheme {
let debugConfigName = BuildConfiguration.debugStaging.name
let releaseConfigName = BuildConfiguration.releaseStaging.name
let testModules = testSchemes(name)

return Scheme(
phongvhd93 marked this conversation as resolved.
Show resolved Hide resolved
name: "\(name) Staging",
shared: true,
buildAction: .buildAction(targets: ["\(name)"]),
testAction: .targets(
["\(name)Tests", "\(name)KIFUITests"],
configuration: debugConfigName
),
testAction: .targets(testModules, configuration: debugConfigName),
runAction: .runAction(configuration: debugConfigName),
archiveAction: .archiveAction(configuration: releaseConfigName),
profileAction: .profileAction(configuration: debugConfigName),
Expand All @@ -39,12 +37,16 @@ extension Scheme {
}

public static func kifUITestsScheme(name: String) -> Scheme {
let debugConfigName = BuildConfiguration.debugStaging.name
let releaseConfigName = BuildConfiguration.releaseStaging.name
return Scheme(
name: "\(name)KIFUITests",
shared: false,
hidden: true
)
}

private static func testSchemes(_ name: String) -> [TestableTarget] {
var modules = Module.allCases.map { TestableTarget("\($0.name)\(Constant.testsPath)") }
modules.append(contentsOf: ["\(name)Tests", "\(name)KIFUITests"])
return modules
}
}
76 changes: 67 additions & 9 deletions Tuist/ProjectDescriptionHelpers/Target+Initializing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,41 @@ import ProjectDescription

extension Target {

private static let plistsPath: String = "Configurations/Plists"
public static func makeTargets(name: String, bundleId: String) -> [Target] {
var targets: [Target] = []

public static func mainTarget(name: String, bundleId: String) -> Target {
let frameworks = Module.allCases
.flatMap { Target.frameworkTargets(module: $0, bundleId: bundleId) }

targets.append(contentsOf: frameworks)

let mainTargets: [Target] = [
.mainTarget(name: name, bundleId: bundleId),
.testsTarget(name: name, bundleId: bundleId),
.kifUITestsTarget(name: name, bundleId: bundleId)
]

targets.append(contentsOf: mainTargets)

return targets
}
}

// MARK: - Main Targets

extension Target {

fileprivate static func mainTarget(name: String, bundleId: String) -> Target {
return Target(
name: name,
platform: .iOS,
product: .app,
bundleId: bundleId,
deploymentTarget: .iOS(
targetVersion: "{TARGET_VERSION}",
targetVersion: "{TARGET_VERSION}",
devices: [.iphone]
),
infoPlist: "\(name)/\(plistsPath)/Info.plist",
infoPlist: "\(name)/\(Constant.plistsPath)/Info.plist",
sources: ["\(name)/Sources/**"],
resources: [
"\(name)/Resources/**",
Expand All @@ -26,18 +48,22 @@ extension Target {
.swiftLintScript(),
.swiftFormatLintScript(),
.firebaseScript()
],
dependencies: [
.target(name: Module.data.name),
.target(name: Module.domain.name)
]
)
}

public static func testsTarget(name: String, bundleId: String) -> Target {
fileprivate static func testsTarget(name: String, bundleId: String) -> Target {
let targetName = "\(name)Tests"
return Target(
name: targetName,
platform: .iOS,
product: .unitTests,
bundleId: bundleId,
infoPlist: "\(targetName)/\(plistsPath)/Info.plist",
infoPlist: "\(targetName)/\(Constant.plistsPath)/Info.plist",
sources: ["\(targetName)/**"],
resources: [
"\(targetName)/**/.gitkeep", // To include empty folders
Expand All @@ -48,19 +74,51 @@ extension Target {
)
}

public static func kifUITestsTarget(name: String, bundleId: String) -> Target {
fileprivate static func kifUITestsTarget(name: String, bundleId: String) -> Target {
let targetName = "\(name)KIFUITests"
return Target(
name: targetName,
platform: .iOS,
product: .unitTests,
bundleId: bundleId,
infoPlist: "\(targetName)/\(plistsPath)/Info.plist",
infoPlist: "\(targetName)/\(Constant.plistsPath)/Info.plist",
sources: ["\(targetName)/**"],
resources: [
"\(targetName)/**/.gitkeep", // To include empty folders
],
],
dependencies: [.target(name: name)]
)
}
}

// MARK: - Dependencies

extension Target {

fileprivate static func frameworkTargets(module: Module, bundleId: String) -> [Target] {
let framework = Target(
name: module.name,
platform: .iOS,
product: .framework,
bundleId: module.getBundleId(mainBundleId: bundleId),
deploymentTarget: .iOS(
targetVersion: "{TARGET_VERSION}",
devices: [.iphone]
),
sources: module.sources,
resources: module.resources,
dependencies: module.dependencies
)

let testTarget = Target(
name: "\(module.name)\(Constant.testsPath)",
platform: .iOS,
product: .unitTests,
bundleId: module.getTestBundleId(mainBundleId: bundleId),
sources: module.testsSources,
resources: module.testsResources,
dependencies: [.target(name: module.name)]
)
return [framework, testTarget]
}
}
Loading