Skip to content

Commit

Permalink
[#349] Create modules for Domain and Data layer
Browse files Browse the repository at this point in the history
  • Loading branch information
phongvhd93 committed Oct 24, 2023
1 parent 1985934 commit 3526b48
Show file tree
Hide file tree
Showing 25 changed files with 191 additions and 228 deletions.
File renamed without changes.
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: QuickSpec {

Expand Down
File renamed without changes.
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 func spec() {

describe("A Dummy") {

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

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

static func project(name: String, bundleId: String) -> Project {
var targets: [Target] = [
.mainTarget(name: name, bundleId: bundleId),
.testsTarget(name: name, bundleId: bundleId),
.kifUITestsTarget(name: name, bundleId: bundleId),
]

Module.allCases.forEach {
targets.append(Target.makeFramework(module: $0, bundleId: bundleId))
}
let targets = Target.makeTargets(name: name, bundleId: bundleId)

return Project(
name: name,
Expand All @@ -26,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
21 changes: 21 additions & 0 deletions Tuist/Interfaces/SwiftUI/Project/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ 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
# Pods for Domain
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
25 changes: 21 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,27 @@ 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
# Pods for Domain
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"
}
36 changes: 35 additions & 1 deletion Tuist/ProjectDescriptionHelpers/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import ProjectDescription


public enum Module: CaseIterable {

case domain
Expand All @@ -30,4 +29,39 @@ public enum Module: CaseIterable {
return [.target(name: Module.domain.name)]
}
}

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

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

public var resources: ProjectDescription.ResourceFileElements {
switch self {
case .data, .domain:
return []
}
}

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)"
}
}
20 changes: 10 additions & 10 deletions Tuist/ProjectDescriptionHelpers/Scheme+Initializing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ extension Scheme {
public static func productionScheme(name: String) -> Scheme {
let debugConfigName = BuildConfiguration.debugProduction.name
let releaseConfigName = BuildConfiguration.releaseProduction.name

var testModules = Module.allCases.map { TestableTarget("\($0.name)\(Constant.testsPath)") }
testModules.append(contentsOf: ["\(name)Tests", "\(name)KIFUITests"])

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 +24,15 @@ extension Scheme {
public static func stagingScheme(name: String) -> Scheme {
let debugConfigName = BuildConfiguration.debugStaging.name
let releaseConfigName = BuildConfiguration.releaseStaging.name

var testModules = Module.allCases.map { TestableTarget("\($0.name)\(Constant.testsPath)") }
testModules.append(contentsOf: ["\(name)Tests", "\(name)KIFUITests"])

return Scheme(
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,8 +41,6 @@ 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,
Expand Down
Loading

0 comments on commit 3526b48

Please sign in to comment.