Skip to content

Commit

Permalink
♻️ (tuist): Project Module - refactor to follow app(...) API
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Jan 8, 2024
1 parent 6dcfd42 commit c0ba143
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 188 deletions.
7 changes: 3 additions & 4 deletions Examples/Module/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import ProjectDescriptionHelpers
// Creates our project using a helper function defined in ProjectDescriptionHelpers
let project = Project.module(
name: "Module",
platform: .iOS,
dependencies: [
// no deps
],
examples: [
ModuleExample(name: "ModuleExampleAppOne"),
ModuleExample(
Expand All @@ -22,5 +18,8 @@ let project = Project.module(
"APP_NAME": "ModuleExampleAppTwo from InfoPlist",
]
),
],
dependencies: [
// no deps
]
)
14 changes: 5 additions & 9 deletions Modules/AccountKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ import ProjectDescriptionHelpers
// Creates our project using a helper function defined in ProjectDescriptionHelpers
let project = Project.module(
name: "AccountKit",
platform: .iOS,
dependencies: [
.project(target: "DesignKit", path: Path("../../Modules/DesignKit")),
.project(target: "LogKit", path: Path("../../Modules/LogKit")),
],
examples: [
ModuleExample(
name: "AccountKitExample",
infoPlist: [
"NSAccentColorName": "AccentColor",
]
name: "AccountKitExample"
),
],
dependencies: [
.project(target: "DesignKit", path: Path("../../Modules/DesignKit")),
.project(target: "LogKit", path: Path("../../Modules/LogKit")),
]
)
16 changes: 4 additions & 12 deletions Modules/BLEKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@ import ProjectDescriptionHelpers
// Creates our project using a helper function defined in ProjectDescriptionHelpers
let project = Project.module(
name: "BLEKit",
platform: .iOS,
dependencies: [
.external(name: "CombineCoreBluetooth"),
],
examples: [
ModuleExample(
name: "BLEKitExample",
infoPlist: [
"NSBluetoothAlwaysUsageDescription":
"The Leka Updater app needs to use Bluetooth to connect to the Leka robot.",
"UIBackgroundModes": [
"bluetooth-central",
],
]
name: "BLEKitExample"
),
],
dependencies: [
.external(name: "CombineCoreBluetooth"),
]
)
14 changes: 5 additions & 9 deletions Modules/ContentKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ import ProjectDescriptionHelpers
// Creates our project using a helper function defined in ProjectDescriptionHelpers
let project = Project.module(
name: "ContentKit",
platform: .iOS,
dependencies: [
.project(target: "LogKit", path: Path("../../Modules/LogKit")),
.external(name: "Yams"),
],
examples: [
ModuleExample(
name: "ContentKitExample",
infoPlist: [
"NSAccentColorName": "AccentColor",
]
name: "ContentKitExample"
),
],
dependencies: [
.project(target: "LogKit", path: Path("../../Modules/LogKit")),
.external(name: "Yams"),
]
)
1 change: 0 additions & 1 deletion Modules/DesignKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import ProjectDescriptionHelpers
// Creates our project using a helper function defined in ProjectDescriptionHelpers
let project = Project.module(
name: "DesignKit",
platform: .iOS,
dependencies: [
.external(name: "Lottie"),
]
Expand Down
28 changes: 5 additions & 23 deletions Modules/GameEngineKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,16 @@ import ProjectDescriptionHelpers
// Creates our project using a helper function defined in ProjectDescriptionHelpers
let project = Project.module(
name: "GameEngineKit",
platform: .iOS,
examples: [
ModuleExample(
name: "GameEngineKitExample"
),
],
dependencies: [
.project(target: "DesignKit", path: Path("../../Modules/DesignKit")),
.project(target: "RobotKit", path: Path("../../Modules/RobotKit")),
.project(target: "ContentKit", path: Path("../../Modules/ContentKit")),
.external(name: "SwiftUIJoystick"),
.external(name: "AudioKit"),
],
examples: [
ModuleExample(
name: "GameEngineKitExample",
infoPlist: [
"NSBluetoothAlwaysUsageDescription":
"The Leka Updater app needs to use Bluetooth to connect to the Leka robot.",
"UIBackgroundModes": [
"bluetooth-central",
],
"UIRequiresFullScreen": "true",
"UISupportedInterfaceOrientations": [
"UIInterfaceOrientationLandscapeRight",
"UIInterfaceOrientationLandscapeLeft",
],
"UISupportedInterfaceOrientations~ipad": [
"UIInterfaceOrientationLandscapeRight",
"UIInterfaceOrientationLandscapeLeft",
],
"NSAccentColorName": "AccentColor",
]
),
]
)
5 changes: 3 additions & 2 deletions Modules/LocalizationKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import ProjectDescriptionHelpers
// Creates our project using a helper function defined in ProjectDescriptionHelpers
let project = Project.module(
name: "LocalizationKit",
platform: .iOS,
dependencies: [],
examples: [
ModuleExample(
name: "LocalizationKitExample",
Expand All @@ -20,6 +18,9 @@ let project = Project.module(
]
),
],
dependencies: [
// no deps
],
schemes: [
SchemeList.l10nFR(name: "LocalizationKitExample"),
SchemeList.l10nEN(name: "LocalizationKitExample"),
Expand Down
12 changes: 4 additions & 8 deletions Modules/LogKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ import ProjectDescriptionHelpers
// Creates our project using a helper function defined in ProjectDescriptionHelpers
let project = Project.module(
name: "LogKit",
platform: .iOS,
dependencies: [
.external(name: "Logging"),
],
examples: [
ModuleExample(
name: "LogKitExample",
infoPlist: [
"NSAccentColorName": "AccentColor",
]
name: "LogKitExample"
),
],
dependencies: [
.external(name: "Logging"),
]
)
28 changes: 5 additions & 23 deletions Modules/RobotKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,15 @@ import ProjectDescriptionHelpers
// Creates our project using a helper function defined in ProjectDescriptionHelpers
let project = Project.module(
name: "RobotKit",
platform: .iOS,
examples: [
ModuleExample(
name: "RobotKitExample"
),
],
dependencies: [
.project(target: "BLEKit", path: Path("../../Modules/BLEKit")),
.project(target: "DesignKit", path: Path("../../Modules/DesignKit")),
.project(target: "LogKit", path: Path("../../Modules/LogKit")),
.external(name: "Version"),
],
examples: [
ModuleExample(
name: "RobotKitExample",
infoPlist: [
"NSBluetoothAlwaysUsageDescription":
"The Leka Updater app needs to use Bluetooth to connect to the Leka robot.",
"UIBackgroundModes": [
"bluetooth-central",
],
"UIRequiresFullScreen": "true",
"UISupportedInterfaceOrientations": [
"UIInterfaceOrientationLandscapeRight",
"UIInterfaceOrientationLandscapeLeft",
],
"UISupportedInterfaceOrientations~ipad": [
"UIInterfaceOrientationLandscapeRight",
"UIInterfaceOrientationLandscapeLeft",
],
"NSAccentColorName": "AccentColor",
]
),
]
)
88 changes: 63 additions & 25 deletions Tuist/ProjectDescriptionHelpers/Project+Templates+Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,38 @@ public struct ModuleExample {
public extension Project {
static func module(
name: String,
platform: Platform,
product: Product = .staticLibrary,
dependencies: [TargetDependency],
settings: Settings? = nil,
examples: [ModuleExample] = [],
deploymentTargets: DeploymentTargets = .iOS("16.0"),
destinations: Destinations = [.iPad, .macWithiPadDesign],
infoPlist: [String: Plist.Value] = [:],
settings: SettingsDictionary = [:],
options: Options = .options(),
examples: [ModuleExample] = [],
dependencies: [TargetDependency] = [],
schemes: [Scheme] = []
) -> Project {
let frameworkTargets = makeFrameworkTargets(
name: name,
platform: platform,
product: product,
dependencies: dependencies,
settings: settings
deploymentTargets: deploymentTargets,
destinations: destinations,
infoPlist: infoPlist,
settings: settings,
dependencies: dependencies
)

let exampleTargets = examples.compactMap { example in
let appInfoPlist = InfoPlist.base(version: "1.0.0").merging(example.infoPlist) { _, new in new }

let target = Target(
Target(
name: example.name,
platform: .iOS,
destinations: destinations,
product: .app,
bundleId: "io.leka.apf.app.example.\(example.name)",
deploymentTarget: .iOS(targetVersion: "16.0", devices: .ipad),
infoPlist: .extendingDefault(with: appInfoPlist),
deploymentTargets: deploymentTargets,
infoPlist: .extendingDefault(with: InfoPlist.extendingBase(version: "1.0.0", with: infoPlist)),
sources: ["Examples/\(example.name)/Sources/**"],
resources: ["Examples/\(example.name)/Resources/**"],
scripts: TargetScript.linters(),
dependencies: [.target(name: name)],
settings: .settings(base: [
"LOCALIZED_STRING_MACRO_NAMES": [
"NSLocalizedString",
"CFCopyLocalizedString",
"LocalizedString",
"LocalizedStringInterpolation",
],
])
settings: .settings(base: .extendingBase(with: settings))
)

return target
}

return Project(
Expand All @@ -77,3 +68,50 @@ public extension Project {
)
}
}

private func makeFrameworkTargets(
name: String,
deploymentTargets: DeploymentTargets = .iOS("16.0"),
destinations: Destinations = [.iPad, .macWithiPadDesign],
infoPlist: [String: Plist.Value] = [:],
settings: SettingsDictionary = [:],
dependencies: [TargetDependency] = []
)
-> [Target]
{
var product: Product = .staticLibrary

if Environment.generateModulesAsFrameworksForDebug.getBoolean(default: false) {
product = .framework
}

let module = Target(
name: name,
destinations: destinations,
product: product,
bundleId: "io.leka.apf.module.\(name)",
deploymentTargets: deploymentTargets,
infoPlist: .extendingDefault(with: InfoPlist.extendingBase(version: "1.0.0", with: infoPlist)),
sources: ["Sources/**"],
resources: ["Resources/**"],
scripts: TargetScript.linters(),
dependencies: dependencies,
settings: .settings(base: .extendingBase(with: settings))
)

let tests = Target(
name: "\(name)Tests",
destinations: destinations,
product: .unitTests,
bundleId: "io.leka.apf.framework.\(name)Tests",
infoPlist: .extendingDefault(with: InfoPlist.extendingBase(version: "1.0.0", with: infoPlist)),
sources: ["Tests/**"],
resources: [],
scripts: TargetScript.linters(),
dependencies: [
.target(name: name),
]
)

return [module, tests]
}
Loading

0 comments on commit c0ba143

Please sign in to comment.