From c0ba143aac5fe37527edc2901fe538eee027d85d Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Mon, 8 Jan 2024 15:40:51 +0100 Subject: [PATCH] :recycle: (tuist): Project Module - refactor to follow app(...) API --- Examples/Module/Project.swift | 7 +- Modules/AccountKit/Project.swift | 14 ++- Modules/BLEKit/Project.swift | 16 +--- Modules/ContentKit/Project.swift | 14 ++- Modules/DesignKit/Project.swift | 1 - Modules/GameEngineKit/Project.swift | 28 ++---- Modules/LocalizationKit/Project.swift | 5 +- Modules/LogKit/Project.swift | 12 +-- Modules/RobotKit/Project.swift | 28 ++---- .../Project+Templates+Module.swift | 88 +++++++++++++------ .../Project+Templates.swift | 72 --------------- 11 files changed, 97 insertions(+), 188 deletions(-) delete mode 100644 Tuist/ProjectDescriptionHelpers/Project+Templates.swift diff --git a/Examples/Module/Project.swift b/Examples/Module/Project.swift index c9c51fd93d..924823a4b1 100644 --- a/Examples/Module/Project.swift +++ b/Examples/Module/Project.swift @@ -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( @@ -22,5 +18,8 @@ let project = Project.module( "APP_NAME": "ModuleExampleAppTwo from InfoPlist", ] ), + ], + dependencies: [ + // no deps ] ) diff --git a/Modules/AccountKit/Project.swift b/Modules/AccountKit/Project.swift index 435acc5161..738c65a564 100644 --- a/Modules/AccountKit/Project.swift +++ b/Modules/AccountKit/Project.swift @@ -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")), ] ) diff --git a/Modules/BLEKit/Project.swift b/Modules/BLEKit/Project.swift index 6ddc9f9d72..377562a3ce 100644 --- a/Modules/BLEKit/Project.swift +++ b/Modules/BLEKit/Project.swift @@ -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"), ] ) diff --git a/Modules/ContentKit/Project.swift b/Modules/ContentKit/Project.swift index 3d064e845b..c95dd308dd 100644 --- a/Modules/ContentKit/Project.swift +++ b/Modules/ContentKit/Project.swift @@ -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"), ] ) diff --git a/Modules/DesignKit/Project.swift b/Modules/DesignKit/Project.swift index 134517d757..b07ed648c7 100644 --- a/Modules/DesignKit/Project.swift +++ b/Modules/DesignKit/Project.swift @@ -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"), ] diff --git a/Modules/GameEngineKit/Project.swift b/Modules/GameEngineKit/Project.swift index afa36752be..08c6e26a1f 100644 --- a/Modules/GameEngineKit/Project.swift +++ b/Modules/GameEngineKit/Project.swift @@ -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", - ] - ), ] ) diff --git a/Modules/LocalizationKit/Project.swift b/Modules/LocalizationKit/Project.swift index 72f9984b0f..8f43f91e5f 100644 --- a/Modules/LocalizationKit/Project.swift +++ b/Modules/LocalizationKit/Project.swift @@ -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", @@ -20,6 +18,9 @@ let project = Project.module( ] ), ], + dependencies: [ + // no deps + ], schemes: [ SchemeList.l10nFR(name: "LocalizationKitExample"), SchemeList.l10nEN(name: "LocalizationKitExample"), diff --git a/Modules/LogKit/Project.swift b/Modules/LogKit/Project.swift index 68e918c898..ec962fce59 100644 --- a/Modules/LogKit/Project.swift +++ b/Modules/LogKit/Project.swift @@ -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"), ] ) diff --git a/Modules/RobotKit/Project.swift b/Modules/RobotKit/Project.swift index 3ad3b1f767..388cbe3056 100644 --- a/Modules/RobotKit/Project.swift +++ b/Modules/RobotKit/Project.swift @@ -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", - ] - ), ] ) diff --git a/Tuist/ProjectDescriptionHelpers/Project+Templates+Module.swift b/Tuist/ProjectDescriptionHelpers/Project+Templates+Module.swift index adca6eb226..86b1ecedcd 100644 --- a/Tuist/ProjectDescriptionHelpers/Project+Templates+Module.swift +++ b/Tuist/ProjectDescriptionHelpers/Project+Templates+Module.swift @@ -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( @@ -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] +} diff --git a/Tuist/ProjectDescriptionHelpers/Project+Templates.swift b/Tuist/ProjectDescriptionHelpers/Project+Templates.swift deleted file mode 100644 index 0cdad8296c..0000000000 --- a/Tuist/ProjectDescriptionHelpers/Project+Templates.swift +++ /dev/null @@ -1,72 +0,0 @@ -// Leka - iOS Monorepo -// Copyright APF France handicap -// SPDX-License-Identifier: Apache-2.0 - -// swiftformat:disable acronyms - -import ProjectDescription - -/// Project helpers are functions that simplify the way you define your project. -/// Share code to create targets, settings, dependencies, -/// Create your own conventions, e.g: a func that makes sure all shared targets are "static frameworks" -/// See https://docs.tuist.io/guides/helpers/ - -extension Project { - // MARK: - Internal - - static func makeFrameworkTargets( - name: String, platform: Platform, product: Product = .staticLibrary, dependencies: [TargetDependency], settings: Settings? = nil - ) - -> [Target] - { - // MARK: - Set product type - - var product = product - - let generateModulesAsFrameworksForDebug = Environment.generateModulesAsFrameworksForDebug.getBoolean( - default: false) - - if generateModulesAsFrameworksForDebug { - product = .framework - } - - // MARK: - Set platform type - - var platform = platform - - let generateMacOSApps = Environment.generateMacOSApps.getBoolean(default: false) - - if generateMacOSApps { - platform = .macOS - } - - let module = Target( - name: "\(name)", - platform: platform, - product: product, - bundleId: "io.leka.apf.module.\(name)", - deploymentTarget: platform == .iOS - ? .iOS(targetVersion: "16.0", devices: .ipad) : .macOS(targetVersion: "13.0"), - infoPlist: .default, - sources: ["Sources/**"], - resources: ["Resources/**"], - scripts: TargetScript.linters(), - dependencies: dependencies, - settings: settings - ) - - let tests = Target( - name: "\(name)Tests", - platform: platform, - product: .unitTests, - bundleId: "io.leka.apf.framework.\(name)Tests", - infoPlist: .default, - sources: ["Tests/**"], - resources: [], - scripts: TargetScript.linters(), - dependencies: [.target(name: name)] - ) - - return [module, tests] - } -}