-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #10: Project+App 및 Templates 구현
app 타겟, framework 타켓, Tests 타겟
- Loading branch information
Showing
5 changed files
with
118 additions
and
148 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Project+App.swift | ||
// ProjectDescriptionHelpers | ||
// | ||
// Created by 김영인 on 2023/07/25. | ||
// | ||
|
||
import ProjectDescription | ||
|
||
import ConfigPlugin | ||
import DependencyPlugin | ||
import EnvPlugin | ||
|
||
extension Project { | ||
public static func app(name: String, | ||
internalDependencies: [TargetDependency] = [], | ||
externalDependencies: [TargetDependency] = [] | ||
) -> Project { | ||
|
||
let mainTarget = Target( | ||
name: name, | ||
platform: Environment.platform, | ||
product: .app, | ||
bundleId: "\(Environment.organizationName).\(name)", | ||
deploymentTarget: Environment.deploymentTarget, | ||
infoPlist: .extendingDefault(with: Project.infoPlist), | ||
sources: ["Sources/**"], | ||
resources: [.glob(pattern: "Resources/**", excluding: [])], | ||
entitlements: .relativeToRoot("Keyme.entitlements"), | ||
scripts: Project.script, | ||
dependencies: internalDependencies + externalDependencies, | ||
settings: .settings(base: .baseSettings, configurations: XCConfig.project) | ||
) | ||
|
||
let testTarget = Target( | ||
name: "\(name)Tests", | ||
platform: Environment.platform, | ||
product: .unitTests, | ||
bundleId: "\(Environment.organizationName).\(name)Tests", | ||
infoPlist: .default, | ||
sources: ["Tests/Sources/**"], | ||
resources: [.glob(pattern: "Tests/Resources/**", excluding: [])], | ||
dependencies: [.target(name: name)], | ||
settings: .settings(base: .baseSettings, configurations: XCConfig.tests) | ||
) | ||
|
||
return Project(name: name, | ||
organizationName: Environment.organizationName, | ||
settings: .settings(configurations: XCConfig.project), | ||
targets: [mainTarget, testTarget], | ||
schemes: Project.appScheme) | ||
} | ||
} |
171 changes: 55 additions & 116 deletions
171
Tuist/ProjectDescriptionHelpers/Project+Templates.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,69 @@ | ||
import ProjectDescription | ||
import Environment | ||
|
||
/// 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/ | ||
import ConfigPlugin | ||
import DependencyPlugin | ||
import EnvPlugin | ||
|
||
extension Project { | ||
/// Helper function to create the Project for this ExampleApp | ||
public static func app(name: String, platform: Platform, additionalTargets: [String]) -> Project { | ||
var dependencies = additionalTargets.map { TargetDependency.target(name: $0) } | ||
dependencies += [ | ||
.external(name: "FirebaseMessaging") | ||
] | ||
public extension Project { | ||
static func makeModule(name: String, | ||
internalDependencies: [TargetDependency] = [], | ||
externalDependencies: [TargetDependency] = [], | ||
isDynamicFramework: Bool = false, | ||
hasTestTarget: Bool = true | ||
) -> Project { | ||
var targets: [Target] = [ ] | ||
|
||
var targets = makeAppTargets( | ||
let target = Target( | ||
name: name, | ||
platform: platform, | ||
dependencies: dependencies) | ||
|
||
targets += additionalTargets.flatMap({ makeFrameworkTargets(name: $0, platform: platform) }) | ||
return Project(name: name, | ||
organizationName: Environment.organizationName, | ||
targets: targets) | ||
} | ||
|
||
// MARK: - Private | ||
|
||
/// Helper function to create a framework target and an associated unit test target | ||
private static func makeFrameworkTargets(name: String, platform: Platform) -> [Target] { | ||
let sources = Target( | ||
name: name, | ||
platform: platform, | ||
product: .framework, | ||
platform: Environment.platform, | ||
product: isDynamicFramework ? .framework : .staticFramework, | ||
bundleId: "\(Environment.organizationName).\(name)", | ||
deploymentTarget: .iOS(targetVersion: Environment.targetVersion, devices: .iphone), | ||
deploymentTarget: Environment.deploymentTarget, | ||
infoPlist: .default, | ||
sources: ["Targets/\(name)/Sources/**"], | ||
sources: ["Sources/**"], | ||
resources: [], | ||
dependencies: [ | ||
.external(name: "Moya"), | ||
.external(name: "CombineMoya") | ||
]) | ||
dependencies: internalDependencies + externalDependencies, | ||
settings: .settings(base: .baseSettings, configurations: XCConfig.framework) | ||
|
||
let tests = Target( | ||
name: "\(name)Tests", | ||
platform: platform, | ||
product: .unitTests, | ||
bundleId: "\(Environment.organizationName).\(name)Tests", | ||
deploymentTarget: .iOS(targetVersion: Environment.targetVersion, devices: .iphone), | ||
infoPlist: .default, | ||
sources: ["Targets/\(name)/Tests/**"], | ||
resources: [], | ||
dependencies: [.target(name: name)]) | ||
) | ||
targets.append(target) | ||
|
||
if hasTestTarget { | ||
let testTarget = Target( | ||
name: "\(name)Tests", | ||
platform: Environment.platform, | ||
product: .unitTests, | ||
bundleId: "\(Environment.organizationName).\(name)Tests", | ||
infoPlist: .default, | ||
sources: ["Tests/Sources/**"], | ||
resources: [.glob(pattern: "Tests/Resources/**", excluding: [])], | ||
dependencies: [.target(name: name)], | ||
settings: .settings(base: .baseSettings, configurations: XCConfig.tests) | ||
|
||
return [sources, tests] | ||
) | ||
targets.append(testTarget) | ||
} | ||
|
||
return Project(name: name, | ||
organizationName: Environment.organizationName, | ||
settings: .settings(configurations: XCConfig.project), | ||
targets: targets, | ||
schemes: [Scheme.makeScheme(configs: "DEV", name: "\(name)"), | ||
Scheme.makeScheme(configs: "PROD", name: "\(name)")]) | ||
} | ||
} | ||
|
||
/// Helper function to create the application target and the unit test target. | ||
private static func makeAppTargets(name: String, platform: Platform, dependencies: [TargetDependency]) -> [Target] { | ||
let platform: Platform = platform | ||
let infoPlist: [String: InfoPlist.Value] = [ | ||
"CFBundleShortVersionString": "1.0", | ||
"CFBundleVersion": "1", | ||
"UIMainStoryboardFile": "", | ||
"UILaunchStoryboardName": "LaunchScreen", | ||
"CFBundleURLTypes": [ | ||
[ | ||
"CFBundleTypeRole": "Editor", | ||
"CFBundleURLSchemes": ["keyme"] | ||
] | ||
], | ||
"API_BASE_URL": "$(API_BASE_URL)", | ||
] | ||
|
||
let mainTarget = Target( | ||
name: name, | ||
platform: platform, | ||
product: .app, | ||
bundleId: "\(Environment.organizationName).\(name)", | ||
deploymentTarget: .iOS(targetVersion: "16.0", devices: .iphone), | ||
infoPlist: .extendingDefault(with: infoPlist), | ||
sources: ["Targets/\(name)/Sources/**",], | ||
resources: [ | ||
"Targets/\(name)/Resources/**" | ||
], | ||
entitlements: .relativeToRoot("Keyme.entitlements"), | ||
scripts: [ | ||
.pre( | ||
path: .relativeToRoot("Scripts/lint.sh"), | ||
name: "Lint codes", | ||
basedOnDependencyAnalysis: false), | ||
.post(path: .relativeToRoot("Scripts/encrypt.sh"), | ||
name: "Encrypt the secret files") | ||
], | ||
dependencies: dependencies, | ||
settings: .settings( | ||
base: [ | ||
"API_BASE_URL": .string("$(inherited)"), | ||
], | ||
configurations: [ | ||
.debug( | ||
name: "Debug", settings: [ | ||
"OTHER_LDFLAGS": ["$(inherited)", "-ObjC"] | ||
], | ||
xcconfig: .relativeToRoot("Config.xcconfig") | ||
), | ||
.release( | ||
name: "Release", settings: [ | ||
"OTHER_LDFLAGS": ["$(inherited)", "-ObjC"] | ||
], | ||
xcconfig: .relativeToRoot("Config.xcconfig") | ||
) | ||
] | ||
)) | ||
|
||
let testTarget = Target( | ||
name: "\(name)Tests", | ||
platform: platform, | ||
product: .unitTests, | ||
bundleId: "\(Environment.organizationName).\(name)Tests", | ||
infoPlist: .default, | ||
sources: ["Targets/\(name)/Tests/**"], | ||
dependencies: [ | ||
.target(name: "\(name)") | ||
]) | ||
return [mainTarget, testTarget] | ||
extension Scheme { | ||
static func makeScheme(configs: ConfigurationName, name: String) -> Scheme { | ||
return Scheme(name: name, | ||
buildAction: .buildAction(targets: ["\(name)"]), | ||
testAction: .targets(["\(name)Tests"], | ||
configuration: configs, | ||
options: .options(coverage: true, codeCoverageTargets: ["\(name)"])), | ||
runAction: .runAction(configuration: configs), | ||
archiveAction: .archiveAction(configuration: configs), | ||
profileAction: .profileAction(configuration: configs), | ||
analyzeAction: .analyzeAction(configuration: configs) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import ProjectDescription | ||
|
||
import EnvPlugin | ||
|
||
let workspace = Workspace( | ||
name: Environment.appName, | ||
projects: [ | ||
"Projects/**" | ||
] | ||
) |