From 2dbcbca24b8de9be550eb4b19c8ed50b70a8cbf1 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Thu, 15 Jun 2023 12:36:58 +0700 Subject: [PATCH 01/33] [#483] Add SwiftUI variant --- .../Target+Initializing.swift | 34 ++++++++++++++++++- Tuist/Projects/SwiftUI/Project.swift | 31 +++++++++++++++++ .../Projects/UIKit/Project.swift | 0 make.sh | 3 ++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Tuist/Projects/SwiftUI/Project.swift rename Project.swift => Tuist/Projects/UIKit/Project.swift (100%) diff --git a/Tuist/ProjectDescriptionHelpers/Target+Initializing.swift b/Tuist/ProjectDescriptionHelpers/Target+Initializing.swift index 5e2158db..865d6efa 100644 --- a/Tuist/ProjectDescriptionHelpers/Target+Initializing.swift +++ b/Tuist/ProjectDescriptionHelpers/Target+Initializing.swift @@ -15,7 +15,39 @@ extension Target { devices: [.iphone] ), infoPlist: "\(name)/\(plistsPath)/Info.plist", - sources: ["\(name)/Sources/**"], + sources: [ + "\(name)/Sources/Application/**", + "\(name)/Sources/Constants/**" + ], + resources: [ + "\(name)/Resources/**", + "\(name)/Sources/**/.gitkeep" // To include empty folders + ], + scripts: [ + .sourceryScript(), + .rswiftScript(), + .swiftLintScript(), + .swiftFormatLintScript(), + .firebaseScript() + ] + ) + } + + public static func mainTarget2(name: String, bundleId: String) -> Target { + return Target( + name: name, + platform: .iOS, + product: .app, + bundleId: bundleId, + deploymentTarget: .iOS( + targetVersion: "{TARGET_VERSION}", + devices: [.iphone] + ), + infoPlist: "\(name)/\(plistsPath)/Info.plist", + sources: [ + "\(name)/Sources/Data/**", + "\(name)/Sources/Domain/**" + ], resources: [ "\(name)/Resources/**", "\(name)/Sources/**/.gitkeep" // To include empty folders diff --git a/Tuist/Projects/SwiftUI/Project.swift b/Tuist/Projects/SwiftUI/Project.swift new file mode 100644 index 00000000..ccb6c79a --- /dev/null +++ b/Tuist/Projects/SwiftUI/Project.swift @@ -0,0 +1,31 @@ +import ProjectDescription +import ProjectDescriptionHelpers + +let project = Project.project(name: "{PROJECT_NAME}", bundleId: "${PRODUCT_BUNDLE_IDENTIFIER}") + +extension Project { + + static func project(name: String, bundleId: String) -> Project { + return Project( + name: name, + organizationName: "Nimble", + options: .options( + disableBundleAccessors: true, + disableSynthesizedResourceAccessors: true + ), + settings: .settings( + configurations: BuildConfiguration.allCases.map { $0.createConfiguration(projectName: name) } + ), + targets: [ + .mainTarget2(name: name, bundleId: bundleId), + .testsTarget(name: name, bundleId: bundleId), + .kifUITestsTarget(name: name, bundleId: bundleId), + ], + schemes: [ + .productionScheme(name: name), + .stagingScheme(name: name), + .kifUITestsScheme(name: name) + ] + ) + } +} diff --git a/Project.swift b/Tuist/Projects/UIKit/Project.swift similarity index 100% rename from Project.swift rename to Tuist/Projects/UIKit/Project.swift diff --git a/make.sh b/make.sh index 62ada912..dd8db90f 100644 --- a/make.sh +++ b/make.sh @@ -162,6 +162,9 @@ then tuist install ${TUIST_VERSION} fi +cp tuist/Projects/SwiftUI/Project.swift . +rm -rf tuist/Projects + # Generate with tuist echo "Tuist found" tuist generate --no-open From b17e7677a9ddf02707d0e4112a95b12ffb171766 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Thu, 15 Jun 2023 12:48:11 +0700 Subject: [PATCH 02/33] [#483] Add interface setup prompt --- Tuist/Projects/SwiftUI/Podfile | 54 ++++++++++++++++++++++++++++ Tuist/Projects/UIKit/Podfile | 64 ++++++++++++++++++++++++++++++++++ interface_setup.sh | 16 +++++++++ make.sh | 5 +-- 4 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 Tuist/Projects/SwiftUI/Podfile create mode 100644 Tuist/Projects/UIKit/Podfile create mode 100644 interface_setup.sh diff --git a/Tuist/Projects/SwiftUI/Podfile b/Tuist/Projects/SwiftUI/Podfile new file mode 100644 index 00000000..2c39abd2 --- /dev/null +++ b/Tuist/Projects/SwiftUI/Podfile @@ -0,0 +1,54 @@ +platform :ios, '15.0' +use_frameworks! +inhibit_all_warnings! + +def testing_pods + pod 'Quick' + pod 'Nimble' + pod 'Sourcery' + pod 'SwiftFormat/CLI' +end + +target '{PROJECT_NAME}' do + # UI + pod 'Kingfisher' + + # Storage + pod 'KeychainAccess' + + # Tools + pod 'Firebase/Crashlytics' + pod 'NimbleExtension', :git => 'https://github.com/nimblehq/NimbleExtension', :branch => 'master' + pod 'R.swift' + pod 'Factory' + + # Development + pod 'SwiftLint' + pod 'Wormholy', :configurations => ['Debug Staging', 'Debug Production'] + pod 'xcbeautify' + + target '{PROJECT_NAME}Tests' do + inherit! :search_paths + testing_pods + end + + target '{PROJECT_NAME}KIFUITests' do + testing_pods + pod 'KIF', :configurations => ['Debug Staging', 'Debug Production'] + pod 'KIF/IdentifierTests', :configurations => ['Debug Staging', 'Debug Production'] + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' + config.build_settings['ENABLE_BITCODE'] = 'NO' + if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" + target.build_configurations.each do |config| + config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' + end + end + end + end +end diff --git a/Tuist/Projects/UIKit/Podfile b/Tuist/Projects/UIKit/Podfile new file mode 100644 index 00000000..78044a23 --- /dev/null +++ b/Tuist/Projects/UIKit/Podfile @@ -0,0 +1,64 @@ +platform :ios, '11.0' +use_frameworks! +inhibit_all_warnings! + +def testing_pods + pod 'Quick' + pod 'Nimble' + pod 'RxNimble', subspecs: ['RxBlocking', 'RxTest'] + pod 'RxSwift' + pod 'Sourcery' + pod 'SwiftFormat/CLI' +end + +target '{PROJECT_NAME}' do + # UI + pod 'Kingfisher' + pod 'SnapKit' + + # Rx + pod 'RxAlamofire' + pod 'RxCocoa' + pod 'RxDataSources' + pod 'RxSwift' + + # Storage + pod 'KeychainAccess' + + # Tools + pod 'Firebase/Crashlytics' + pod 'IQKeyboardManagerSwift' + pod 'NimbleExtension', :git => 'https://github.com/nimblehq/NimbleExtension', :branch => 'master' + pod 'R.swift' + pod 'Factory' + + # Development + pod 'SwiftLint' + pod 'Wormholy', :configurations => ['Debug Staging', 'Debug Production'] + pod 'xcbeautify' + + target '{PROJECT_NAME}Tests' do + inherit! :search_paths + testing_pods + end + + target '{PROJECT_NAME}KIFUITests' do + testing_pods + pod 'KIF', :configurations => ['Debug Staging', 'Debug Production'] + pod 'KIF/IdentifierTests', :configurations => ['Debug Staging', 'Debug Production'] + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' + config.build_settings['ENABLE_BITCODE'] = 'NO' + if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" + target.build_configurations.each do |config| + config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' + end + end + end + end +end diff --git a/interface_setup.sh b/interface_setup.sh new file mode 100644 index 00000000..e9543cb7 --- /dev/null +++ b/interface_setup.sh @@ -0,0 +1,16 @@ +#!/bin/sh +if [[ -z "${CI}" ]]; then + read -p "Which Interface do you want to use [(S)wiftUI/(U)IKit]: " interface + + if [ "$interface" = "s" -o "$ciService" = "SwiftUI" -o "$ciService" = "S" ]; then + echo "Setting up SwiftUI" + cp -r tuist/Projects/SwiftUI/. . + else + echo "Setting up UIKit" + cp -r tuist/Projects/UIKit/. . + fi + rm -rf tuist/Projects + echo "✅ Completed" +else + cp -r tuist/Projects/UIKit/. . +fi diff --git a/make.sh b/make.sh index dd8db90f..9e2ff65e 100644 --- a/make.sh +++ b/make.sh @@ -162,8 +162,8 @@ then tuist install ${TUIST_VERSION} fi -cp tuist/Projects/SwiftUI/Project.swift . -rm -rf tuist/Projects +# Choose the Interface +sh interface_setup.sh # Generate with tuist echo "Tuist found" @@ -198,6 +198,7 @@ echo "Remove script files and git/index" rm -rf make.sh rm -rf .github/workflows/test_install_script.yml rm -f .git/index +rm -rf interface_setup.sh git reset if [[ -z "${CI}" ]]; then From c8e7f59e02e9edba1396ac9fe10f6be79c6af401 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Thu, 15 Jun 2023 13:51:11 +0700 Subject: [PATCH 03/33] [#483] Add source files for both interfaces --- .../UIKit/Project.swift => Project.swift | 0 .../SwiftUI/Pod}/Podfile | 3 + .../SwiftUI/Sources/Application/App.swift | 10 +++ .../NetworkAPI/Core/NetworkAPIError.swift | 0 .../NetworkAPI/Core/NetworkAPIProtocol.swift | 34 ++++++++++ .../Core/RequestConfiguration.swift | 0 .../Data/NetworkAPI/Interceptors/.gitkeep | 0 .../Sources/Data/NetworkAPI/Models/.gitkeep | 0 .../Sources/Data/NetworkAPI/NetworkAPI.swift | 26 ++++++++ .../NetworkAPI/RequestConfigurations/.gitkeep | 0 .../Sources/Data/Repositories/.gitkeep | 0 .../Presentation/Modules/HomeView.swift | 13 ++++ .../Sources/Presentation/Views/.gitkeep | 0 Podfile => Tuist/Interfaces/UIKit/Pod/Podfile | 0 .../UIKit/Pod}/Project.swift | 2 +- .../Sources/Application/AppDelegate.swift | 0 .../NetworkAPI/Core/NetworkAPIError.swift | 11 ++++ .../NetworkAPI/Core/NetworkAPIProtocol.swift | 0 .../Core/RequestConfiguration.swift | 39 +++++++++++ .../Data/NetworkAPI/Interceptors/.gitkeep | 0 .../Sources/Data/NetworkAPI/Models/.gitkeep | 0 .../Sources/Data/NetworkAPI/NetworkAPI.swift | 0 .../NetworkAPI/RequestConfigurations/.gitkeep | 0 .../UIKit/Sources/Data/Repositories/.gitkeep | 0 .../Modules/HomeViewController.swift | 0 .../Navigator/Navigator+Scene.swift | 0 .../Navigator/Navigator+Transition.swift | 0 .../Presentation/Navigator/Navigator.swift | 0 .../UIKit/Sources/Presentation/Views/.gitkeep | 0 Tuist/Projects/UIKit/Podfile | 64 ------------------- interface_setup.sh | 14 ++-- make.sh | 6 +- 32 files changed, 148 insertions(+), 74 deletions(-) rename Tuist/Projects/UIKit/Project.swift => Project.swift (100%) rename Tuist/{Projects/SwiftUI => Interfaces/SwiftUI/Pod}/Podfile (97%) create mode 100644 Tuist/Interfaces/SwiftUI/Sources/Application/App.swift rename {{PROJECT_NAME} => Tuist/Interfaces/SwiftUI}/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift (100%) create mode 100644 Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift rename {{PROJECT_NAME} => Tuist/Interfaces/SwiftUI}/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift (100%) rename {{PROJECT_NAME} => Tuist/Interfaces/SwiftUI}/Sources/Data/NetworkAPI/Interceptors/.gitkeep (100%) rename {{PROJECT_NAME} => Tuist/Interfaces/SwiftUI}/Sources/Data/NetworkAPI/Models/.gitkeep (100%) create mode 100644 Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/NetworkAPI.swift rename {{PROJECT_NAME} => Tuist/Interfaces/SwiftUI}/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep (100%) rename {{PROJECT_NAME} => Tuist/Interfaces/SwiftUI}/Sources/Data/Repositories/.gitkeep (100%) create mode 100644 Tuist/Interfaces/SwiftUI/Sources/Presentation/Modules/HomeView.swift rename {{PROJECT_NAME} => Tuist/Interfaces/SwiftUI}/Sources/Presentation/Views/.gitkeep (100%) rename Podfile => Tuist/Interfaces/UIKit/Pod/Podfile (100%) rename Tuist/{Projects/SwiftUI => Interfaces/UIKit/Pod}/Project.swift (93%) rename {{PROJECT_NAME} => Tuist/Interfaces/UIKit}/Sources/Application/AppDelegate.swift (100%) create mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift rename {{PROJECT_NAME} => Tuist/Interfaces/UIKit}/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift (100%) create mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift create mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Interceptors/.gitkeep create mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Models/.gitkeep rename {{PROJECT_NAME} => Tuist/Interfaces/UIKit}/Sources/Data/NetworkAPI/NetworkAPI.swift (100%) create mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep create mode 100644 Tuist/Interfaces/UIKit/Sources/Data/Repositories/.gitkeep rename {{PROJECT_NAME} => Tuist/Interfaces/UIKit}/Sources/Presentation/Modules/HomeViewController.swift (100%) rename {{PROJECT_NAME} => Tuist/Interfaces/UIKit}/Sources/Presentation/Navigator/Navigator+Scene.swift (100%) rename {{PROJECT_NAME} => Tuist/Interfaces/UIKit}/Sources/Presentation/Navigator/Navigator+Transition.swift (100%) rename {{PROJECT_NAME} => Tuist/Interfaces/UIKit}/Sources/Presentation/Navigator/Navigator.swift (100%) create mode 100644 Tuist/Interfaces/UIKit/Sources/Presentation/Views/.gitkeep delete mode 100644 Tuist/Projects/UIKit/Podfile diff --git a/Tuist/Projects/UIKit/Project.swift b/Project.swift similarity index 100% rename from Tuist/Projects/UIKit/Project.swift rename to Project.swift diff --git a/Tuist/Projects/SwiftUI/Podfile b/Tuist/Interfaces/SwiftUI/Pod/Podfile similarity index 97% rename from Tuist/Projects/SwiftUI/Podfile rename to Tuist/Interfaces/SwiftUI/Pod/Podfile index 2c39abd2..696cc506 100644 --- a/Tuist/Projects/SwiftUI/Podfile +++ b/Tuist/Interfaces/SwiftUI/Pod/Podfile @@ -13,6 +13,9 @@ target '{PROJECT_NAME}' do # UI pod 'Kingfisher' + # Backend + pod 'Alamofire' + # Storage pod 'KeychainAccess' diff --git a/Tuist/Interfaces/SwiftUI/Sources/Application/App.swift b/Tuist/Interfaces/SwiftUI/Sources/Application/App.swift new file mode 100644 index 00000000..e387c41e --- /dev/null +++ b/Tuist/Interfaces/SwiftUI/Sources/Application/App.swift @@ -0,0 +1,10 @@ +import SwiftUI + +@main +struct {PROJECT_NAME}App: App { + var body: some Scene { + WindowGroup { + HomeView() + } + } +} diff --git a/{PROJECT_NAME}/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift similarity index 100% rename from {PROJECT_NAME}/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift rename to Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift new file mode 100644 index 00000000..fb6a161d --- /dev/null +++ b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift @@ -0,0 +1,34 @@ +// +// NetworkAPIProtocol.swift +// + +import Alamofire +import Combine + +protocol NetworkAPIProtocol { + + func performRequest( + _ configuration: RequestConfiguration, + for type: T.Type + ) -> AnyPublisher +} + +extension NetworkAPIProtocol { + + func request( + session: Session, + configuration: RequestConfiguration, + decoder: JSONDecoder + ) -> AnyPublisher { + return session.request( + configuration.url, + method: configuration.method, + parameters: configuration.parameters, + encoding: configuration.encoding, + headers: configuration.headers, + interceptor: configuration.interceptor + ) + .publishDecodable(type: T.self, decoder: decoder) + .value() + } +} diff --git a/{PROJECT_NAME}/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift similarity index 100% rename from {PROJECT_NAME}/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift rename to Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift diff --git a/{PROJECT_NAME}/Sources/Data/NetworkAPI/Interceptors/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Interceptors/.gitkeep similarity index 100% rename from {PROJECT_NAME}/Sources/Data/NetworkAPI/Interceptors/.gitkeep rename to Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Interceptors/.gitkeep diff --git a/{PROJECT_NAME}/Sources/Data/NetworkAPI/Models/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Models/.gitkeep similarity index 100% rename from {PROJECT_NAME}/Sources/Data/NetworkAPI/Models/.gitkeep rename to Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Models/.gitkeep diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/NetworkAPI.swift b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/NetworkAPI.swift new file mode 100644 index 00000000..413a003c --- /dev/null +++ b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/NetworkAPI.swift @@ -0,0 +1,26 @@ +// +// NetworkAPI.swift +// + +import Alamofire +import Combine + +final class NetworkAPI: NetworkAPIProtocol { + + private let decoder: JSONDecoder + + init(decoder: JSONDecoder = JSONDecoder()) { + self.decoder = decoder + } + + func performRequest( + _ configuration: RequestConfiguration, + for type: T.Type + ) -> AnyPublisher { + request( + session: Session(), + configuration: configuration, + decoder: decoder + ) + } +} diff --git a/{PROJECT_NAME}/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep similarity index 100% rename from {PROJECT_NAME}/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep rename to Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep diff --git a/{PROJECT_NAME}/Sources/Data/Repositories/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Data/Repositories/.gitkeep similarity index 100% rename from {PROJECT_NAME}/Sources/Data/Repositories/.gitkeep rename to Tuist/Interfaces/SwiftUI/Sources/Data/Repositories/.gitkeep diff --git a/Tuist/Interfaces/SwiftUI/Sources/Presentation/Modules/HomeView.swift b/Tuist/Interfaces/SwiftUI/Sources/Presentation/Modules/HomeView.swift new file mode 100644 index 00000000..341a9171 --- /dev/null +++ b/Tuist/Interfaces/SwiftUI/Sources/Presentation/Modules/HomeView.swift @@ -0,0 +1,13 @@ +import SwiftUI + +struct HomeView: View { + var body: some View { + VStack { + Image(systemName: "globe") + .imageScale(.large) + .foregroundColor(.accentColor) + Text("Hello, world!") + } + .padding() + } +} diff --git a/{PROJECT_NAME}/Sources/Presentation/Views/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Presentation/Views/.gitkeep similarity index 100% rename from {PROJECT_NAME}/Sources/Presentation/Views/.gitkeep rename to Tuist/Interfaces/SwiftUI/Sources/Presentation/Views/.gitkeep diff --git a/Podfile b/Tuist/Interfaces/UIKit/Pod/Podfile similarity index 100% rename from Podfile rename to Tuist/Interfaces/UIKit/Pod/Podfile diff --git a/Tuist/Projects/SwiftUI/Project.swift b/Tuist/Interfaces/UIKit/Pod/Project.swift similarity index 93% rename from Tuist/Projects/SwiftUI/Project.swift rename to Tuist/Interfaces/UIKit/Pod/Project.swift index ccb6c79a..18a36590 100644 --- a/Tuist/Projects/SwiftUI/Project.swift +++ b/Tuist/Interfaces/UIKit/Pod/Project.swift @@ -17,7 +17,7 @@ extension Project { configurations: BuildConfiguration.allCases.map { $0.createConfiguration(projectName: name) } ), targets: [ - .mainTarget2(name: name, bundleId: bundleId), + .mainUIKitTarget(name: name, bundleId: bundleId), .testsTarget(name: name, bundleId: bundleId), .kifUITestsTarget(name: name, bundleId: bundleId), ], diff --git a/{PROJECT_NAME}/Sources/Application/AppDelegate.swift b/Tuist/Interfaces/UIKit/Sources/Application/AppDelegate.swift similarity index 100% rename from {PROJECT_NAME}/Sources/Application/AppDelegate.swift rename to Tuist/Interfaces/UIKit/Sources/Application/AppDelegate.swift diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift new file mode 100644 index 00000000..78c72199 --- /dev/null +++ b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift @@ -0,0 +1,11 @@ +// +// NetworkAPIError.swift +// + +import Foundation + +enum NetworkAPIError: Error { + + case generic + case dataNotFound +} diff --git a/{PROJECT_NAME}/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift similarity index 100% rename from {PROJECT_NAME}/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift rename to Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift new file mode 100644 index 00000000..32ddb9d3 --- /dev/null +++ b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift @@ -0,0 +1,39 @@ +// +// RequestConfiguration.swift +// + +import Alamofire +import Foundation + +protocol RequestConfiguration { + + var baseURL: String { get } + + var endpoint: String { get } + + var method: HTTPMethod { get } + + var url: URLConvertible { get } + + var parameters: Parameters? { get } + + var encoding: ParameterEncoding { get } + + var headers: HTTPHeaders? { get } + + var interceptor: RequestInterceptor? { get } +} + +extension RequestConfiguration { + + var url: URLConvertible { + let url = URL(string: baseURL)?.appendingPathComponent(endpoint) + return url?.absoluteString ?? "\(baseURL)\(endpoint)" + } + + var parameters: Parameters? { nil } + + var headers: HTTPHeaders? { nil } + + var interceptor: RequestInterceptor? { nil } +} diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Interceptors/.gitkeep b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Interceptors/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Models/.gitkeep b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Models/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/{PROJECT_NAME}/Sources/Data/NetworkAPI/NetworkAPI.swift b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/NetworkAPI.swift similarity index 100% rename from {PROJECT_NAME}/Sources/Data/NetworkAPI/NetworkAPI.swift rename to Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/NetworkAPI.swift diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Tuist/Interfaces/UIKit/Sources/Data/Repositories/.gitkeep b/Tuist/Interfaces/UIKit/Sources/Data/Repositories/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/{PROJECT_NAME}/Sources/Presentation/Modules/HomeViewController.swift b/Tuist/Interfaces/UIKit/Sources/Presentation/Modules/HomeViewController.swift similarity index 100% rename from {PROJECT_NAME}/Sources/Presentation/Modules/HomeViewController.swift rename to Tuist/Interfaces/UIKit/Sources/Presentation/Modules/HomeViewController.swift diff --git a/{PROJECT_NAME}/Sources/Presentation/Navigator/Navigator+Scene.swift b/Tuist/Interfaces/UIKit/Sources/Presentation/Navigator/Navigator+Scene.swift similarity index 100% rename from {PROJECT_NAME}/Sources/Presentation/Navigator/Navigator+Scene.swift rename to Tuist/Interfaces/UIKit/Sources/Presentation/Navigator/Navigator+Scene.swift diff --git a/{PROJECT_NAME}/Sources/Presentation/Navigator/Navigator+Transition.swift b/Tuist/Interfaces/UIKit/Sources/Presentation/Navigator/Navigator+Transition.swift similarity index 100% rename from {PROJECT_NAME}/Sources/Presentation/Navigator/Navigator+Transition.swift rename to Tuist/Interfaces/UIKit/Sources/Presentation/Navigator/Navigator+Transition.swift diff --git a/{PROJECT_NAME}/Sources/Presentation/Navigator/Navigator.swift b/Tuist/Interfaces/UIKit/Sources/Presentation/Navigator/Navigator.swift similarity index 100% rename from {PROJECT_NAME}/Sources/Presentation/Navigator/Navigator.swift rename to Tuist/Interfaces/UIKit/Sources/Presentation/Navigator/Navigator.swift diff --git a/Tuist/Interfaces/UIKit/Sources/Presentation/Views/.gitkeep b/Tuist/Interfaces/UIKit/Sources/Presentation/Views/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Tuist/Projects/UIKit/Podfile b/Tuist/Projects/UIKit/Podfile deleted file mode 100644 index 78044a23..00000000 --- a/Tuist/Projects/UIKit/Podfile +++ /dev/null @@ -1,64 +0,0 @@ -platform :ios, '11.0' -use_frameworks! -inhibit_all_warnings! - -def testing_pods - pod 'Quick' - pod 'Nimble' - pod 'RxNimble', subspecs: ['RxBlocking', 'RxTest'] - pod 'RxSwift' - pod 'Sourcery' - pod 'SwiftFormat/CLI' -end - -target '{PROJECT_NAME}' do - # UI - pod 'Kingfisher' - pod 'SnapKit' - - # Rx - pod 'RxAlamofire' - pod 'RxCocoa' - pod 'RxDataSources' - pod 'RxSwift' - - # Storage - pod 'KeychainAccess' - - # Tools - pod 'Firebase/Crashlytics' - pod 'IQKeyboardManagerSwift' - pod 'NimbleExtension', :git => 'https://github.com/nimblehq/NimbleExtension', :branch => 'master' - pod 'R.swift' - pod 'Factory' - - # Development - pod 'SwiftLint' - pod 'Wormholy', :configurations => ['Debug Staging', 'Debug Production'] - pod 'xcbeautify' - - target '{PROJECT_NAME}Tests' do - inherit! :search_paths - testing_pods - end - - target '{PROJECT_NAME}KIFUITests' do - testing_pods - pod 'KIF', :configurations => ['Debug Staging', 'Debug Production'] - pod 'KIF/IdentifierTests', :configurations => ['Debug Staging', 'Debug Production'] - end -end - -post_install do |installer| - installer.pods_project.targets.each do |target| - target.build_configurations.each do |config| - config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' - config.build_settings['ENABLE_BITCODE'] = 'NO' - if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" - target.build_configurations.each do |config| - config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' - end - end - end - end -end diff --git a/interface_setup.sh b/interface_setup.sh index e9543cb7..22df0e4f 100644 --- a/interface_setup.sh +++ b/interface_setup.sh @@ -2,15 +2,17 @@ if [[ -z "${CI}" ]]; then read -p "Which Interface do you want to use [(S)wiftUI/(U)IKit]: " interface - if [ "$interface" = "s" -o "$ciService" = "SwiftUI" -o "$ciService" = "S" ]; then + if [ "$interface" = "s" -o "$interface" = "SwiftUI" -o "$interface" = "S" ]; then echo "Setting up SwiftUI" - cp -r tuist/Projects/SwiftUI/. . + cp -r tuist/Interfaces/SwiftUI/Pod/. . + cp -r tuist/Interfaces/SwiftUI/Sources/. {PROJECT_NAME}/Sources else echo "Setting up UIKit" - cp -r tuist/Projects/UIKit/. . + cp -r tuist/Interfaces/UIKit/Pod/. . + cp -r tuist/Interfaces/UIKit/Sources/. {PROJECT_NAME}/Sources fi - rm -rf tuist/Projects - echo "✅ Completed" else - cp -r tuist/Projects/UIKit/. . + cp -r tuist/Interfaces/UIKit/Pod/. . + cp -r tuist/Interfaces/UIKit/Sources/. {PROJECT_NAME}/Sources fi +rm -rf tuist/Interfaces diff --git a/make.sh b/make.sh index 9e2ff65e..e66eee8a 100644 --- a/make.sh +++ b/make.sh @@ -101,6 +101,9 @@ if ! [[ $bundle_id_production =~ $regex ]]; then die "Invalid Package Name: $bundle_id_production (needs to follow standard pattern {com.example.package})" fi +# Choose the Interface +sh interface_setup.sh + echo "=> 🐢 Starting init $project_name ..." # Trim spaces in APP_NAME @@ -162,9 +165,6 @@ then tuist install ${TUIST_VERSION} fi -# Choose the Interface -sh interface_setup.sh - # Generate with tuist echo "Tuist found" tuist generate --no-open From ee38fa1025a709fe4d55be89ef704bc3f9fa4b32 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Thu, 15 Jun 2023 15:48:58 +0700 Subject: [PATCH 04/33] [#483] Fix build --- Tuist/Interfaces/SwiftUI/Pod/Podfile | 2 +- Tuist/Interfaces/UIKit/Pod/Project.swift | 31 ----------------- .../Target+Initializing.swift | 34 +------------------ 3 files changed, 2 insertions(+), 65 deletions(-) delete mode 100644 Tuist/Interfaces/UIKit/Pod/Project.swift diff --git a/Tuist/Interfaces/SwiftUI/Pod/Podfile b/Tuist/Interfaces/SwiftUI/Pod/Podfile index 696cc506..70215749 100644 --- a/Tuist/Interfaces/SwiftUI/Pod/Podfile +++ b/Tuist/Interfaces/SwiftUI/Pod/Podfile @@ -1,4 +1,4 @@ -platform :ios, '15.0' +platform :ios, '14.0' use_frameworks! inhibit_all_warnings! diff --git a/Tuist/Interfaces/UIKit/Pod/Project.swift b/Tuist/Interfaces/UIKit/Pod/Project.swift deleted file mode 100644 index 18a36590..00000000 --- a/Tuist/Interfaces/UIKit/Pod/Project.swift +++ /dev/null @@ -1,31 +0,0 @@ -import ProjectDescription -import ProjectDescriptionHelpers - -let project = Project.project(name: "{PROJECT_NAME}", bundleId: "${PRODUCT_BUNDLE_IDENTIFIER}") - -extension Project { - - static func project(name: String, bundleId: String) -> Project { - return Project( - name: name, - organizationName: "Nimble", - options: .options( - disableBundleAccessors: true, - disableSynthesizedResourceAccessors: true - ), - settings: .settings( - configurations: BuildConfiguration.allCases.map { $0.createConfiguration(projectName: name) } - ), - targets: [ - .mainUIKitTarget(name: name, bundleId: bundleId), - .testsTarget(name: name, bundleId: bundleId), - .kifUITestsTarget(name: name, bundleId: bundleId), - ], - schemes: [ - .productionScheme(name: name), - .stagingScheme(name: name), - .kifUITestsScheme(name: name) - ] - ) - } -} diff --git a/Tuist/ProjectDescriptionHelpers/Target+Initializing.swift b/Tuist/ProjectDescriptionHelpers/Target+Initializing.swift index 865d6efa..5e2158db 100644 --- a/Tuist/ProjectDescriptionHelpers/Target+Initializing.swift +++ b/Tuist/ProjectDescriptionHelpers/Target+Initializing.swift @@ -15,39 +15,7 @@ extension Target { devices: [.iphone] ), infoPlist: "\(name)/\(plistsPath)/Info.plist", - sources: [ - "\(name)/Sources/Application/**", - "\(name)/Sources/Constants/**" - ], - resources: [ - "\(name)/Resources/**", - "\(name)/Sources/**/.gitkeep" // To include empty folders - ], - scripts: [ - .sourceryScript(), - .rswiftScript(), - .swiftLintScript(), - .swiftFormatLintScript(), - .firebaseScript() - ] - ) - } - - public static func mainTarget2(name: String, bundleId: String) -> Target { - return Target( - name: name, - platform: .iOS, - product: .app, - bundleId: bundleId, - deploymentTarget: .iOS( - targetVersion: "{TARGET_VERSION}", - devices: [.iphone] - ), - infoPlist: "\(name)/\(plistsPath)/Info.plist", - sources: [ - "\(name)/Sources/Data/**", - "\(name)/Sources/Domain/**" - ], + sources: ["\(name)/Sources/**"], resources: [ "\(name)/Resources/**", "\(name)/Sources/**/.gitkeep" // To include empty folders From f9094b429e0d1cc0aa1698fdbfdf487d63f49f36 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Thu, 15 Jun 2023 16:47:04 +0700 Subject: [PATCH 05/33] [#483] Add none breaking podfile --- Tuist/Interfaces/SwiftUI/Pod/Podfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tuist/Interfaces/SwiftUI/Pod/Podfile b/Tuist/Interfaces/SwiftUI/Pod/Podfile index 70215749..a13753b9 100644 --- a/Tuist/Interfaces/SwiftUI/Pod/Podfile +++ b/Tuist/Interfaces/SwiftUI/Pod/Podfile @@ -3,8 +3,8 @@ use_frameworks! inhibit_all_warnings! def testing_pods - pod 'Quick' - pod 'Nimble' + pod 'Quick', '~> 6.0' + pod 'Nimble', '~> 11.0' pod 'Sourcery' pod 'SwiftFormat/CLI' end From 898d562dd0406e98170672b1d68d9d2809b1e450 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 16 Jun 2023 15:01:32 +0700 Subject: [PATCH 06/33] [#483] Use cmd argument --- interface_setup.sh | 28 +++++++++++++++++----------- make.sh | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/interface_setup.sh b/interface_setup.sh index 22df0e4f..4686e607 100644 --- a/interface_setup.sh +++ b/interface_setup.sh @@ -1,17 +1,23 @@ #!/bin/sh -if [[ -z "${CI}" ]]; then - read -p "Which Interface do you want to use [(S)wiftUI/(U)IKit]: " interface - if [ "$interface" = "s" -o "$interface" = "SwiftUI" -o "$interface" = "S" ]; then - echo "Setting up SwiftUI" - cp -r tuist/Interfaces/SwiftUI/Pod/. . - cp -r tuist/Interfaces/SwiftUI/Sources/. {PROJECT_NAME}/Sources - else - echo "Setting up UIKit" - cp -r tuist/Interfaces/UIKit/Pod/. . - cp -r tuist/Interfaces/UIKit/Sources/. {PROJECT_NAME}/Sources - fi +interface="" + +while [ $# -gt 0 ] ; do + case "$1" in + -i|--interface) + interface="$2" + shift + ;; + esac + shift +done + +if [ "$interface" = "s" -o "$interface" = "SwiftUI" -o "$interface" = "S" ]; then + echo "Setting up SwiftUI" + cp -r tuist/Interfaces/SwiftUI/Pod/. . + cp -r tuist/Interfaces/SwiftUI/Sources/. {PROJECT_NAME}/Sources else + echo "Setting up UIKit" cp -r tuist/Interfaces/UIKit/Pod/. . cp -r tuist/Interfaces/UIKit/Sources/. {PROJECT_NAME}/Sources fi diff --git a/make.sh b/make.sh index e66eee8a..ce488b74 100644 --- a/make.sh +++ b/make.sh @@ -24,6 +24,7 @@ Options: -b, --bundle-id [BUNDLE_ID_PRODUCTION] the production id (i.e. com.example.package) -s, --bundle-id-staging [BUNDLE_ID_STAGING] the staging id (i.e. com.example.package.staging) -n, --project-name [PROJECT_NAME] the project name (i.e. MyApp) +-i, --interface [INTERFACE] the user interface frameword (SwiftUI or UIKit) EOF exit 1 } @@ -32,6 +33,7 @@ bundle_id_production="" bundle_id_staging="" project_name="" minimum_version="" +interface="" readonly CONSTANT_PROJECT_NAME="{PROJECT_NAME}" readonly CONSTANT_BUNDLE_PRODUCTION="{BUNDLE_ID_PRODUCTION}" @@ -55,6 +57,10 @@ while [ $# -gt 0 ] ; do project_name="$2" shift ;; + -i|--interface) + interface="$2" + shift + ;; -*) usage "Unknown option '$1'" ;; @@ -84,6 +90,13 @@ if [ -z "$minimum_version" ]; then minimum_version="14.0" fi +if [ -z "$interface" ]; then + read -p "Interface [(S)wiftUI or (U)IKit]:" interface + if [ -z "$interface" ]; then + interface="SwiftUI" + fi +fi + # Enforce minimum version version_regex='^[0-9_]+(\.[0-9]+)+$' if ! [[ $minimum_version =~ $version_regex ]]; then @@ -102,7 +115,7 @@ if ! [[ $bundle_id_production =~ $regex ]]; then fi # Choose the Interface -sh interface_setup.sh +sh interface_setup.sh -i $interface echo "=> 🐢 Starting init $project_name ..." From 11193f8f4cb3ae4d9e413fc2fa858bf02546c670 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 16 Jun 2023 15:21:06 +0700 Subject: [PATCH 07/33] [#483] Add wiki instruction --- .github/wiki/Deliverable-Configurations.md | 2 +- .github/wiki/Selecting-User-Interface.md | 11 +++++++++++ .github/wiki/_Sidebar.md | 1 + make.sh | 6 +++--- deliverable_setup.sh => set_up_deliverable.sh | 0 interface_setup.sh => set_up_interface.sh | 0 6 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 .github/wiki/Selecting-User-Interface.md rename deliverable_setup.sh => set_up_deliverable.sh (100%) rename interface_setup.sh => set_up_interface.sh (100%) diff --git a/.github/wiki/Deliverable-Configurations.md b/.github/wiki/Deliverable-Configurations.md index c6a0e6ed..28c892d1 100644 --- a/.github/wiki/Deliverable-Configurations.md +++ b/.github/wiki/Deliverable-Configurations.md @@ -12,5 +12,5 @@ The file [DeliverableConstants.rb](https://github.com/nimblehq/ios-templates/blo ## Configure later - Developer can modify the `DeliverableConstants` at any time. -- Use the command `sh deliverable_setup.sh` to open `DeliverableConstants` with Xcode. +- Use the command `sh set_up_deliverable.sh` to open `DeliverableConstants` with Xcode. - Open the file manually at `fastlane/Constants/DeliverableConstants.rb` with any IDE. diff --git a/.github/wiki/Selecting-User-Interface.md b/.github/wiki/Selecting-User-Interface.md new file mode 100644 index 00000000..80482ea7 --- /dev/null +++ b/.github/wiki/Selecting-User-Interface.md @@ -0,0 +1,11 @@ +## Selecting User Interface + +Current the template supports setup with two user interfaces: +- UIKit +- SwiftUI + +To select a user interface when creating a project pass the argument `--interface [SwiftUI or UIKit]` with the `make` script. + + ```bash + sh make.sh --bundle-id [BUNDLE_ID_PRODUCTION] --bundle-id-staging [BUNDLE_ID_STAGING] --project-name [PROJECT_NAME] --interface SwiftUI + ``` diff --git a/.github/wiki/_Sidebar.md b/.github/wiki/_Sidebar.md index 238befd9..10d80ff1 100644 --- a/.github/wiki/_Sidebar.md +++ b/.github/wiki/_Sidebar.md @@ -3,6 +3,7 @@ - [[Home]] - [[Getting Started]] - [[Deliverable Configurations]] +- [[Selecting User Interface]] ## Architecture diff --git a/make.sh b/make.sh index ce488b74..3489d84a 100644 --- a/make.sh +++ b/make.sh @@ -115,7 +115,7 @@ if ! [[ $bundle_id_production =~ $regex ]]; then fi # Choose the Interface -sh interface_setup.sh -i $interface +sh set_up_interface.sh -i $interface echo "=> 🐢 Starting init $project_name ..." @@ -211,14 +211,14 @@ echo "Remove script files and git/index" rm -rf make.sh rm -rf .github/workflows/test_install_script.yml rm -f .git/index -rm -rf interface_setup.sh +rm -rf set_up_interface.sh git reset if [[ -z "${CI}" ]]; then rm -rf fastlane/Tests rm -f set_up_test_firebase.sh rm -f set_up_test_testflight.sh - sh deliverable_setup.sh + sh set_up_deliverable.sh fi echo "✅ Completed" diff --git a/deliverable_setup.sh b/set_up_deliverable.sh similarity index 100% rename from deliverable_setup.sh rename to set_up_deliverable.sh diff --git a/interface_setup.sh b/set_up_interface.sh similarity index 100% rename from interface_setup.sh rename to set_up_interface.sh From fc34ccab2baaba7c5d25b5b6e02c1dddaf83329d Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 16 Jun 2023 15:22:15 +0700 Subject: [PATCH 08/33] [#483] Add interface to test --- .github/workflows/test_install_script.yml | 2 +- .github/workflows/test_upload_build_to_firebase.yml | 2 +- .github/workflows/test_upload_build_to_test_flight.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_install_script.yml b/.github/workflows/test_install_script.yml index e2d201d8..7dcf6236 100644 --- a/.github/workflows/test_install_script.yml +++ b/.github/workflows/test_install_script.yml @@ -21,7 +21,7 @@ jobs: run: bundle install - name: Start Install Script for Template App - run: sh make.sh --bundle-id co.nimblehq.template --bundle-id-staging co.nimblehq.template.staging --project-name TemplateApp + run: sh make.sh --bundle-id co.nimblehq.template --bundle-id-staging co.nimblehq.template.staging --project-name TemplateApp --interface UIKit - name: Build and Test run: bundle exec fastlane buildAndTest diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index e27af9e3..39194acd 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -47,7 +47,7 @@ jobs: ${{ runner.os }}-pods- - name: Start Install Script for Template App - run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp + run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App Firebase Upload run: sh set_up_test_firebase.sh diff --git a/.github/workflows/test_upload_build_to_test_flight.yml b/.github/workflows/test_upload_build_to_test_flight.yml index b0764479..1606fdab 100644 --- a/.github/workflows/test_upload_build_to_test_flight.yml +++ b/.github/workflows/test_upload_build_to_test_flight.yml @@ -44,7 +44,7 @@ jobs: ${{ runner.os }}-pods- - name: Start Install Script for Template App - run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp + run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App TestFlight Upload run: sh set_up_test_testflight.sh From 3e751475ac5e28e4759aae1f5de9b9fffdc90fed Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Wed, 21 Jun 2023 11:22:43 +0700 Subject: [PATCH 09/33] [#483] Replace script with Swift script --- Scripts/Swift/Extensions/FileManager+.swift | 23 ++++++++++++++++++++ Scripts/Swift/SetUpInterface.swift | 20 +++++++++++++++++ make.sh | 6 +++--- set_up_interface.sh | 24 --------------------- 4 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 Scripts/Swift/Extensions/FileManager+.swift create mode 100644 Scripts/Swift/SetUpInterface.swift delete mode 100644 set_up_interface.sh diff --git a/Scripts/Swift/Extensions/FileManager+.swift b/Scripts/Swift/Extensions/FileManager+.swift new file mode 100644 index 00000000..89fc9c52 --- /dev/null +++ b/Scripts/Swift/Extensions/FileManager+.swift @@ -0,0 +1,23 @@ +import Foundation + +extension FileManager { + + public func moveFiles(in directory: String, to destination: String) { + let currentDirectory = currentDirectoryPath + let files = try? contentsOfDirectory( + atPath: "\(currentDirectory)/\(directory)" + ) + if let files = files { + for file in files { + guard file != ".DS_Store" else { continue } + do { + try moveItem( + atPath: "\(currentDirectory)/\(directory)/\(file)", + toPath:"\(currentDirectory)/\(destination)/\(file)") + } catch { + print("Error \(error)") + } + } + } + } +} diff --git a/Scripts/Swift/SetUpInterface.swift b/Scripts/Swift/SetUpInterface.swift new file mode 100644 index 00000000..2959f3d0 --- /dev/null +++ b/Scripts/Swift/SetUpInterface.swift @@ -0,0 +1,20 @@ +#!/usr/bin/swift + +import Foundation + +var interface = "UIKit" +switch CommandLine.arguments[1] { + case "SwiftUI", "s", "S": + print("=> 🦅 Setting up SwiftUI") + interface = "SwiftUI" + default: + print("=> 🦉 Setting up UIKit") + interface = "UIKit" +} + +let fileManager = FileManager.default +let currentDirectory = fileManager.currentDirectoryPath + +fileManager.moveFiles(in: "tuist/Interfaces/\(interface)/Pod", to: "") +fileManager.moveFiles(in: "tuist/Interfaces/\(interface)/Sources", to: "{PROJECT_NAME}/Sources") +try fileManager.removeItem(atPath: "\(currentDirectory)/tuist/Interfaces") diff --git a/make.sh b/make.sh index 3489d84a..76ff360d 100644 --- a/make.sh +++ b/make.sh @@ -114,8 +114,8 @@ if ! [[ $bundle_id_production =~ $regex ]]; then die "Invalid Package Name: $bundle_id_production (needs to follow standard pattern {com.example.package})" fi -# Choose the Interface -sh set_up_interface.sh -i $interface +# Select the Interface +cat Scripts/Swift/SetUpInterface.swift Scripts/Swift/Extensions/FileManager+.swift | swift - $interface echo "=> 🐢 Starting init $project_name ..." @@ -211,7 +211,7 @@ echo "Remove script files and git/index" rm -rf make.sh rm -rf .github/workflows/test_install_script.yml rm -f .git/index -rm -rf set_up_interface.sh +rm -rf Scripts git reset if [[ -z "${CI}" ]]; then diff --git a/set_up_interface.sh b/set_up_interface.sh deleted file mode 100644 index 4686e607..00000000 --- a/set_up_interface.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -interface="" - -while [ $# -gt 0 ] ; do - case "$1" in - -i|--interface) - interface="$2" - shift - ;; - esac - shift -done - -if [ "$interface" = "s" -o "$interface" = "SwiftUI" -o "$interface" = "S" ]; then - echo "Setting up SwiftUI" - cp -r tuist/Interfaces/SwiftUI/Pod/. . - cp -r tuist/Interfaces/SwiftUI/Sources/. {PROJECT_NAME}/Sources -else - echo "Setting up UIKit" - cp -r tuist/Interfaces/UIKit/Pod/. . - cp -r tuist/Interfaces/UIKit/Sources/. {PROJECT_NAME}/Sources -fi -rm -rf tuist/Interfaces From 2c9f88738bba2493cea84b7c4cd7d5f29892e264 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Wed, 21 Jun 2023 12:01:25 +0700 Subject: [PATCH 10/33] [#483] Add rename SwiftUI App file --- Scripts/Swift/Extensions/FileManager+.swift | 26 +++++++++++++++++++-- Scripts/Swift/SetUpInterface.swift | 10 ++++---- make.sh | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Scripts/Swift/Extensions/FileManager+.swift b/Scripts/Swift/Extensions/FileManager+.swift index 89fc9c52..111ce941 100644 --- a/Scripts/Swift/Extensions/FileManager+.swift +++ b/Scripts/Swift/Extensions/FileManager+.swift @@ -2,7 +2,7 @@ import Foundation extension FileManager { - public func moveFiles(in directory: String, to destination: String) { + func moveFiles(in directory: String, to destination: String) { let currentDirectory = currentDirectoryPath let files = try? contentsOfDirectory( atPath: "\(currentDirectory)/\(directory)" @@ -13,11 +13,33 @@ extension FileManager { do { try moveItem( atPath: "\(currentDirectory)/\(directory)/\(file)", - toPath:"\(currentDirectory)/\(destination)/\(file)") + toPath:"\(currentDirectory)/\(destination)/\(file)" + ) } catch { print("Error \(error)") } } } } + + func rename(file: String, to destination: String) { + let currentDirectory = currentDirectoryPath + do { + try moveItem( + atPath: "\(currentDirectory)/\(file)", + toPath:"\(currentDirectory)/\(destination)" + ) + } catch { + print("Error \(error)") + } + } + + func removeItems(in directory: String) { + let currentDirectory = currentDirectoryPath + do { + try removeItem(atPath: "\(currentDirectory)/\(directory)") + } catch { + print("Error \(error)") + } + } } diff --git a/Scripts/Swift/SetUpInterface.swift b/Scripts/Swift/SetUpInterface.swift index 2959f3d0..f4a5bfe7 100644 --- a/Scripts/Swift/SetUpInterface.swift +++ b/Scripts/Swift/SetUpInterface.swift @@ -2,19 +2,21 @@ import Foundation +let fileManager = FileManager.default + var interface = "UIKit" + switch CommandLine.arguments[1] { case "SwiftUI", "s", "S": print("=> 🦅 Setting up SwiftUI") interface = "SwiftUI" + let swiftUIAppDirectory = "tuist/Interfaces/SwiftUI/Sources/Application" + fileManager.rename(file: "\(swiftUIAppDirectory)/App.swift", to: "\(swiftUIAppDirectory)/\(CommandLine.arguments[2])App.swift") default: print("=> 🦉 Setting up UIKit") interface = "UIKit" } -let fileManager = FileManager.default -let currentDirectory = fileManager.currentDirectoryPath - fileManager.moveFiles(in: "tuist/Interfaces/\(interface)/Pod", to: "") fileManager.moveFiles(in: "tuist/Interfaces/\(interface)/Sources", to: "{PROJECT_NAME}/Sources") -try fileManager.removeItem(atPath: "\(currentDirectory)/tuist/Interfaces") +fileManager.removeItems(in: "tuist/Interfaces") diff --git a/make.sh b/make.sh index 76ff360d..6536ad8d 100644 --- a/make.sh +++ b/make.sh @@ -115,7 +115,7 @@ if ! [[ $bundle_id_production =~ $regex ]]; then fi # Select the Interface -cat Scripts/Swift/SetUpInterface.swift Scripts/Swift/Extensions/FileManager+.swift | swift - $interface +cat Scripts/Swift/SetUpInterface.swift Scripts/Swift/Extensions/FileManager+.swift | swift - $interface $project_name echo "=> 🐢 Starting init $project_name ..." From a3018fd5f95586e9d49edde75cb10a2d97e62abd Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Wed, 21 Jun 2023 13:01:44 +0700 Subject: [PATCH 11/33] [#483] Create Sourcery for SwiftUI --- Scripts/Swift/SetUpInterface.swift | 2 +- Tuist/Interfaces/SwiftUI/Project/.sourcery.yml | 9 +++++++++ Tuist/Interfaces/SwiftUI/{Pod => Project}/Podfile | 0 .../Interfaces/UIKit/Project/.sourcery.yml | 0 Tuist/Interfaces/UIKit/{Pod => Project}/Podfile | 0 5 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Tuist/Interfaces/SwiftUI/Project/.sourcery.yml rename Tuist/Interfaces/SwiftUI/{Pod => Project}/Podfile (100%) rename .sourcery.yml => Tuist/Interfaces/UIKit/Project/.sourcery.yml (100%) rename Tuist/Interfaces/UIKit/{Pod => Project}/Podfile (100%) diff --git a/Scripts/Swift/SetUpInterface.swift b/Scripts/Swift/SetUpInterface.swift index f4a5bfe7..6925abf8 100644 --- a/Scripts/Swift/SetUpInterface.swift +++ b/Scripts/Swift/SetUpInterface.swift @@ -17,6 +17,6 @@ switch CommandLine.arguments[1] { interface = "UIKit" } -fileManager.moveFiles(in: "tuist/Interfaces/\(interface)/Pod", to: "") +fileManager.moveFiles(in: "tuist/Interfaces/\(interface)/Project", to: "") fileManager.moveFiles(in: "tuist/Interfaces/\(interface)/Sources", to: "{PROJECT_NAME}/Sources") fileManager.removeItems(in: "tuist/Interfaces") diff --git a/Tuist/Interfaces/SwiftUI/Project/.sourcery.yml b/Tuist/Interfaces/SwiftUI/Project/.sourcery.yml new file mode 100644 index 00000000..492262a4 --- /dev/null +++ b/Tuist/Interfaces/SwiftUI/Project/.sourcery.yml @@ -0,0 +1,9 @@ +sources: + - {PROJECT_NAME}/Sources +templates: + - tools/sourcery/templates +output: + {PROJECT_NAME}Tests/Sources/Mocks/Sourcery +args: + autoMockableTestableImports: + - {PROJECT_NAME} diff --git a/Tuist/Interfaces/SwiftUI/Pod/Podfile b/Tuist/Interfaces/SwiftUI/Project/Podfile similarity index 100% rename from Tuist/Interfaces/SwiftUI/Pod/Podfile rename to Tuist/Interfaces/SwiftUI/Project/Podfile diff --git a/.sourcery.yml b/Tuist/Interfaces/UIKit/Project/.sourcery.yml similarity index 100% rename from .sourcery.yml rename to Tuist/Interfaces/UIKit/Project/.sourcery.yml diff --git a/Tuist/Interfaces/UIKit/Pod/Podfile b/Tuist/Interfaces/UIKit/Project/Podfile similarity index 100% rename from Tuist/Interfaces/UIKit/Pod/Podfile rename to Tuist/Interfaces/UIKit/Project/Podfile From f0f5924eafb2ef1265fb42b28533da76243b981f Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Wed, 21 Jun 2023 15:22:09 +0700 Subject: [PATCH 12/33] [#483] Fix indents --- Scripts/Swift/Extensions/FileManager+.swift | 70 ++++++++++----------- Scripts/Swift/SetUpInterface.swift | 9 ++- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/Scripts/Swift/Extensions/FileManager+.swift b/Scripts/Swift/Extensions/FileManager+.swift index 111ce941..cda858de 100644 --- a/Scripts/Swift/Extensions/FileManager+.swift +++ b/Scripts/Swift/Extensions/FileManager+.swift @@ -2,44 +2,44 @@ import Foundation extension FileManager { - func moveFiles(in directory: String, to destination: String) { - let currentDirectory = currentDirectoryPath - let files = try? contentsOfDirectory( - atPath: "\(currentDirectory)/\(directory)" - ) - if let files = files { - for file in files { - guard file != ".DS_Store" else { continue } - do { - try moveItem( - atPath: "\(currentDirectory)/\(directory)/\(file)", - toPath:"\(currentDirectory)/\(destination)/\(file)" - ) - } catch { - print("Error \(error)") - } - } + func moveFiles(in directory: String, to destination: String) { + let currentDirectory = currentDirectoryPath + let files = try? contentsOfDirectory( + atPath: "\(currentDirectory)/\(directory)" + ) + if let files = files { + for file in files { + guard file != ".DS_Store" else { continue } + do { + try moveItem( + atPath: "\(currentDirectory)/\(directory)/\(file)", + toPath:"\(currentDirectory)/\(destination)/\(file)" + ) + } catch { + print("Error \(error)") + } + } + } } - } - func rename(file: String, to destination: String) { - let currentDirectory = currentDirectoryPath - do { - try moveItem( - atPath: "\(currentDirectory)/\(file)", - toPath:"\(currentDirectory)/\(destination)" - ) - } catch { - print("Error \(error)") + func rename(file: String, to destination: String) { + let currentDirectory = currentDirectoryPath + do { + try moveItem( + atPath: "\(currentDirectory)/\(file)", + toPath:"\(currentDirectory)/\(destination)" + ) + } catch { + print("Error \(error)") + } } - } - func removeItems(in directory: String) { - let currentDirectory = currentDirectoryPath - do { - try removeItem(atPath: "\(currentDirectory)/\(directory)") - } catch { - print("Error \(error)") + func removeItems(in directory: String) { + let currentDirectory = currentDirectoryPath + do { + try removeItem(atPath: "\(currentDirectory)/\(directory)") + } catch { + print("Error \(error)") + } } - } } diff --git a/Scripts/Swift/SetUpInterface.swift b/Scripts/Swift/SetUpInterface.swift index 6925abf8..44d82628 100644 --- a/Scripts/Swift/SetUpInterface.swift +++ b/Scripts/Swift/SetUpInterface.swift @@ -7,12 +7,15 @@ let fileManager = FileManager.default var interface = "UIKit" switch CommandLine.arguments[1] { - case "SwiftUI", "s", "S": +case "SwiftUI", "s", "S": print("=> 🦅 Setting up SwiftUI") interface = "SwiftUI" let swiftUIAppDirectory = "tuist/Interfaces/SwiftUI/Sources/Application" - fileManager.rename(file: "\(swiftUIAppDirectory)/App.swift", to: "\(swiftUIAppDirectory)/\(CommandLine.arguments[2])App.swift") - default: + fileManager.rename( + file: "\(swiftUIAppDirectory)/App.swift", + to: "\(swiftUIAppDirectory)/\(CommandLine.arguments[2])App.swift" + ) +default: print("=> 🦉 Setting up UIKit") interface = "UIKit" } From 7bad9a3a8a1cf37827ededaec713ea225cdc86e0 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 26 Jun 2023 14:31:04 +0700 Subject: [PATCH 13/33] [#483] Rename FileManager extension --- .../Extensions/{FileManager+.swift => FileManager+Utils.swift} | 0 make.sh | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename Scripts/Swift/Extensions/{FileManager+.swift => FileManager+Utils.swift} (100%) diff --git a/Scripts/Swift/Extensions/FileManager+.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift similarity index 100% rename from Scripts/Swift/Extensions/FileManager+.swift rename to Scripts/Swift/Extensions/FileManager+Utils.swift diff --git a/make.sh b/make.sh index 6536ad8d..d960d79d 100644 --- a/make.sh +++ b/make.sh @@ -115,7 +115,7 @@ if ! [[ $bundle_id_production =~ $regex ]]; then fi # Select the Interface -cat Scripts/Swift/SetUpInterface.swift Scripts/Swift/Extensions/FileManager+.swift | swift - $interface $project_name +cat Scripts/Swift/SetUpInterface.swift Scripts/Swift/Extensions/FileManager+Utils.swift | swift - $interface $project_name echo "=> 🐢 Starting init $project_name ..." From 3d4fca37beec3f9c3198059a4f545c78f9b475fe Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 7 Jul 2023 11:44:57 +0700 Subject: [PATCH 14/33] [#483] Add Arkana to SwiftUI --- Tuist/Interfaces/SwiftUI/Project/Podfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tuist/Interfaces/SwiftUI/Project/Podfile b/Tuist/Interfaces/SwiftUI/Project/Podfile index a13753b9..59017d36 100644 --- a/Tuist/Interfaces/SwiftUI/Project/Podfile +++ b/Tuist/Interfaces/SwiftUI/Project/Podfile @@ -29,6 +29,8 @@ target '{PROJECT_NAME}' do pod 'SwiftLint' pod 'Wormholy', :configurations => ['Debug Staging', 'Debug Production'] pod 'xcbeautify' + pod "ArkanaKeys", path: "./ArkanaKeys/ArkanaKeys" + pod "ArkanaKeysInterfaces", path: "./ArkanaKeys/ArkanaKeysInterfaces" target '{PROJECT_NAME}Tests' do inherit! :search_paths From 012325afabe2112545ed74ec7e9ff6d60d0cb355 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 3 Jul 2023 10:00:13 +0700 Subject: [PATCH 15/33] [#484] Add SwiftUI setup GH Actions --- .../workflows/test_swiftui_install_script.yml | 29 +++++++++++++++++++ ...ript.yml => test_uikit_install_script.yml} | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test_swiftui_install_script.yml rename .github/workflows/{test_install_script.yml => test_uikit_install_script.yml} (87%) diff --git a/.github/workflows/test_swiftui_install_script.yml b/.github/workflows/test_swiftui_install_script.yml new file mode 100644 index 00000000..1223b1b3 --- /dev/null +++ b/.github/workflows/test_swiftui_install_script.yml @@ -0,0 +1,29 @@ +name: Test SwiftUI Install Script + +on: + push: + branches: [ feature/**, bug/**, chore/** ] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + Test: + name: Test + runs-on: macOS-12 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Bundle install + run: bundle install + + - name: Start Install Script for SwiftUI Template App + run: sh make.sh --bundle-id co.nimblehq.template --bundle-id-staging co.nimblehq.template.staging --project-name TemplateApp --interface SwiftUI + + - name: Build and Test + run: bundle exec fastlane buildAndTest + env: + CI: true diff --git a/.github/workflows/test_install_script.yml b/.github/workflows/test_uikit_install_script.yml similarity index 87% rename from .github/workflows/test_install_script.yml rename to .github/workflows/test_uikit_install_script.yml index 7dcf6236..4059d3f2 100644 --- a/.github/workflows/test_install_script.yml +++ b/.github/workflows/test_uikit_install_script.yml @@ -1,4 +1,4 @@ -name: Test Install Script +name: Test UIKit Install Script on: push: @@ -20,7 +20,7 @@ jobs: - name: Bundle install run: bundle install - - name: Start Install Script for Template App + - name: Start Install Script for UIKit Template App run: sh make.sh --bundle-id co.nimblehq.template --bundle-id-staging co.nimblehq.template.staging --project-name TemplateApp --interface UIKit - name: Build and Test From 9c26d56cfcd6fde439a060dbd85acd7eaefa8483 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Thu, 6 Jul 2023 16:32:08 +0700 Subject: [PATCH 16/33] [#490] Add deliverable and CICD setup in Swift [#490] Add deliverable and CICD setup in Swift [#490] Add deliverable and CICD setup in Swift --- Scripts/Swift/Helpers/SafeShell.swift | 20 +++++++++ Scripts/Swift/SetUpCICDService.swift | 47 ++++++++++++++++++++++ Scripts/Swift/SetUpDeliveryConstants.swift | 18 +++++++++ make.sh | 2 + 4 files changed, 87 insertions(+) create mode 100644 Scripts/Swift/Helpers/SafeShell.swift create mode 100644 Scripts/Swift/SetUpCICDService.swift create mode 100644 Scripts/Swift/SetUpDeliveryConstants.swift diff --git a/Scripts/Swift/Helpers/SafeShell.swift b/Scripts/Swift/Helpers/SafeShell.swift new file mode 100644 index 00000000..77d559bc --- /dev/null +++ b/Scripts/Swift/Helpers/SafeShell.swift @@ -0,0 +1,20 @@ +import Foundation + +@discardableResult +func safeShell(_ command: String) throws -> String { + let task = Process() + let pipe = Pipe() + + task.standardOutput = pipe + task.standardError = pipe + task.arguments = ["-c", command] + task.executableURL = URL(fileURLWithPath: "/bin/zsh") + task.standardInput = nil + + try task.run() + + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let output = String(data: data, encoding: .utf8)! + + return output +} diff --git a/Scripts/Swift/SetUpCICDService.swift b/Scripts/Swift/SetUpCICDService.swift new file mode 100644 index 00000000..b4731ff5 --- /dev/null +++ b/Scripts/Swift/SetUpCICDService.swift @@ -0,0 +1,47 @@ +#!/usr/bin/swift + +import Foundation + +let fileManager = FileManager.default + +print("Which CI/CD service do you use (Can be edited later) [(g)ithub/(b)itrise/(c)odemagic/(l)ater]: ") + +var service = "later" + +enum CICDService { + case github, bitrise, codemagic, later + + init(_ name: String) { + switch name { + case "g", "github", "Github": + self = .github + case "b", "bitrise", "Bitrise": + self = .bitrise + case "c", "codemagic", "Codemagic": + self = .codemagic + default: self = .later + } + } +} + +service = readLine() ?? service + +let serviceType = CICDService(service) +switch serviceType { +case .github: + print("Setting template for Github Actions") + fileManager.removeItems(in: "bitrise.yml") + fileManager.removeItems(in: "codemagic.yaml") +case .bitrise: + print("Setting template for Bitrise") + fileManager.removeItems(in: "codemagic.yaml") + fileManager.removeItems(in: ".github/workflows") +case .codemagic: + print("Setting template for CodeMagic") + fileManager.removeItems(in: "bitrise.yml") + fileManager.removeItems(in: ".github/workflows") +case .later: + print("You can manually setup the template later.") +} + +print("✅ Completed") diff --git a/Scripts/Swift/SetUpDeliveryConstants.swift b/Scripts/Swift/SetUpDeliveryConstants.swift new file mode 100644 index 00000000..bfd54b6b --- /dev/null +++ b/Scripts/Swift/SetUpDeliveryConstants.swift @@ -0,0 +1,18 @@ +#!/usr/bin/swift + +import Foundation + +let fileManager = FileManager.default + +print("Do you want to set up Constants values? (Can be edited later) [Y/n]: ") + +var arg = "y" + +arg = readLine() ?? arg + +switch arg.lowercased() { + case "y", "yes": + try safeShell("open -a Xcode fastlane/Constants/Constant.swift") + default: + print("✅ Completed. You can edit this file at 'fastlane/Constants/Constant.swift'.") +} diff --git a/make.sh b/make.sh index d960d79d..883d5e4b 100644 --- a/make.sh +++ b/make.sh @@ -219,6 +219,8 @@ if [[ -z "${CI}" ]]; then rm -f set_up_test_firebase.sh rm -f set_up_test_testflight.sh sh set_up_deliverable.sh + cat Scripts/Swift/SetUpCICDService.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' + cat Scripts/Swift/SetUpDeliveryConstants.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' fi echo "✅ Completed" From cd6f1c95979f413a4b1e4ed6600da006b32c5b0a Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Thu, 6 Jul 2023 18:22:41 +0700 Subject: [PATCH 17/33] [#490] Remove set_up_deliverable.sh and references [#490] Remove set_up_deliverable.sh and references --- .github/wiki/Deliverable-Configurations.md | 1 - make.sh | 4 ++-- set_up_deliverable.sh | 26 ---------------------- 3 files changed, 2 insertions(+), 29 deletions(-) delete mode 100644 set_up_deliverable.sh diff --git a/.github/wiki/Deliverable-Configurations.md b/.github/wiki/Deliverable-Configurations.md index 28c892d1..1568bc23 100644 --- a/.github/wiki/Deliverable-Configurations.md +++ b/.github/wiki/Deliverable-Configurations.md @@ -12,5 +12,4 @@ The file [DeliverableConstants.rb](https://github.com/nimblehq/ios-templates/blo ## Configure later - Developer can modify the `DeliverableConstants` at any time. -- Use the command `sh set_up_deliverable.sh` to open `DeliverableConstants` with Xcode. - Open the file manually at `fastlane/Constants/DeliverableConstants.rb` with any IDE. diff --git a/make.sh b/make.sh index 883d5e4b..3f8b6ef3 100644 --- a/make.sh +++ b/make.sh @@ -211,18 +211,18 @@ echo "Remove script files and git/index" rm -rf make.sh rm -rf .github/workflows/test_install_script.yml rm -f .git/index -rm -rf Scripts git reset if [[ -z "${CI}" ]]; then rm -rf fastlane/Tests rm -f set_up_test_firebase.sh rm -f set_up_test_testflight.sh - sh set_up_deliverable.sh cat Scripts/Swift/SetUpCICDService.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' cat Scripts/Swift/SetUpDeliveryConstants.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' fi +rm -rf Scripts + echo "✅ Completed" # Done! diff --git a/set_up_deliverable.sh b/set_up_deliverable.sh deleted file mode 100644 index 445c4ca7..00000000 --- a/set_up_deliverable.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -read -p "Which CI/CD service do you use (Can be edited later) [(g)ithub/(b)itrise/(c)odemagic/(l)ater]: " ciService - -if [ "$ciService" = "g" -o "$ciService" = "github" ]; then - echo "Setting template for Github Actions" - rm bitrise.yml - rm codemagic.yaml -elif [ "$ciService" = "b" -o "$ciService" = "bitrise" ]; then - echo "Setting template for Bitrise" - rm -rf .github/workflows - rm codemagic.yaml -elif [ "$ciService" = "c" -o "$ciService" = "codemagic" ]; then - echo "Setting template for CodeMagic" - rm -rf .github/workflows - rm bitrise.yml -else - echo "You can manually setup the template later." -fi -echo "✅ Completed" - -read -n1 -p "Do you want to set up Constants values? (Can be edited later) [Y/n]:" confirm -if ! echo $confirm | grep '^[Yy]\?$'; then - echo "✅ Completed" -else - open -a Xcode fastlane/Constants/Constant.swift -fi From 0364221285a06491a9444a71174664f67d645501 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 10 Jul 2023 16:07:08 +0700 Subject: [PATCH 18/33] [#484] Remove not needed depth fetch --- .github/workflows/test_swiftui_install_script.yml | 2 -- .github/workflows/test_uikit_install_script.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/workflows/test_swiftui_install_script.yml b/.github/workflows/test_swiftui_install_script.yml index 1223b1b3..7002abae 100644 --- a/.github/workflows/test_swiftui_install_script.yml +++ b/.github/workflows/test_swiftui_install_script.yml @@ -14,8 +14,6 @@ jobs: runs-on: macOS-12 steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - name: Bundle install run: bundle install diff --git a/.github/workflows/test_uikit_install_script.yml b/.github/workflows/test_uikit_install_script.yml index 4059d3f2..d5cc86e9 100644 --- a/.github/workflows/test_uikit_install_script.yml +++ b/.github/workflows/test_uikit_install_script.yml @@ -14,8 +14,6 @@ jobs: runs-on: macOS-latest steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - name: Bundle install run: bundle install From f7a1c3aa6b7a8c8eef2d68ad2ae55ff2f88342fe Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 14 Jul 2023 11:16:34 +0700 Subject: [PATCH 19/33] [#490] Use optional return from Safeshell --- Scripts/Swift/Helpers/SafeShell.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/Swift/Helpers/SafeShell.swift b/Scripts/Swift/Helpers/SafeShell.swift index 77d559bc..dbca3d27 100644 --- a/Scripts/Swift/Helpers/SafeShell.swift +++ b/Scripts/Swift/Helpers/SafeShell.swift @@ -1,7 +1,7 @@ import Foundation @discardableResult -func safeShell(_ command: String) throws -> String { +func safeShell(_ command: String) throws -> String? { let task = Process() let pipe = Pipe() @@ -14,7 +14,7 @@ func safeShell(_ command: String) throws -> String { try task.run() let data = pipe.fileHandleForReading.readDataToEndOfFile() - let output = String(data: data, encoding: .utf8)! + let output = String(data: data, encoding: .utf8) return output } From f7c7dd26c221a4855f12eb56f8bdcb2ee0c2e46f Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 17 Jul 2023 18:01:31 +0700 Subject: [PATCH 20/33] [#490] Add fallback and error messages --- Scripts/Swift/SetUpCICDService.swift | 30 ++++++++++++---------- Scripts/Swift/SetUpDeliveryConstants.swift | 6 +++-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Scripts/Swift/SetUpCICDService.swift b/Scripts/Swift/SetUpCICDService.swift index b4731ff5..f8b06c77 100644 --- a/Scripts/Swift/SetUpCICDService.swift +++ b/Scripts/Swift/SetUpCICDService.swift @@ -4,30 +4,32 @@ import Foundation let fileManager = FileManager.default -print("Which CI/CD service do you use (Can be edited later) [(g)ithub/(b)itrise/(c)odemagic/(l)ater]: ") - -var service = "later" - enum CICDService { - case github, bitrise, codemagic, later + case github, bitrise, codemagic, later, none init(_ name: String) { - switch name { - case "g", "github", "Github": + switch name.lowercased() { + case "g", "github": self = .github - case "b", "bitrise", "Bitrise": + case "b", "bitrise": self = .bitrise - case "c", "codemagic", "Codemagic": + case "c", "codemagic": self = .codemagic - default: self = .later + case "l", "later": + self = .later + default: self = .none } } } -service = readLine() ?? service +var service = CICDService.none + +while service == .none { + print("Which CI/CD service do you use (Can be edited later) [(g)ithub/(b)itrise/(c)odemagic/(l)ater]: ") + service = CICDService(readLine() ?? "") +} -let serviceType = CICDService(service) -switch serviceType { +switch service { case .github: print("Setting template for Github Actions") fileManager.removeItems(in: "bitrise.yml") @@ -40,7 +42,7 @@ case .codemagic: print("Setting template for CodeMagic") fileManager.removeItems(in: "bitrise.yml") fileManager.removeItems(in: ".github/workflows") -case .later: +case .later, .none: print("You can manually setup the template later.") } diff --git a/Scripts/Swift/SetUpDeliveryConstants.swift b/Scripts/Swift/SetUpDeliveryConstants.swift index bfd54b6b..97a4813f 100644 --- a/Scripts/Swift/SetUpDeliveryConstants.swift +++ b/Scripts/Swift/SetUpDeliveryConstants.swift @@ -11,8 +11,10 @@ var arg = "y" arg = readLine() ?? arg switch arg.lowercased() { - case "y", "yes": - try safeShell("open -a Xcode fastlane/Constants/Constant.swift") + case "y", "yes", "": + let error = try safeShell("open -a Xcode fastlane/Constants/Constant.swift") + guard let error = error, !error.isEmpty else { break } + print("Could not open Xcode. Make sure Xcode is installed and try again.\nRaw error: \(error)") default: print("✅ Completed. You can edit this file at 'fastlane/Constants/Constant.swift'.") } From d98959b1f1b272df90c92b7142eb874794a9412b Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Tue, 18 Jul 2023 14:08:03 +0700 Subject: [PATCH 21/33] [#490] Refactor --- Scripts/Swift/SetUpCICDService.swift | 13 +++++++------ Scripts/Swift/SetUpDeliveryConstants.swift | 4 +--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Scripts/Swift/SetUpCICDService.swift b/Scripts/Swift/SetUpCICDService.swift index f8b06c77..35a22abb 100644 --- a/Scripts/Swift/SetUpCICDService.swift +++ b/Scripts/Swift/SetUpCICDService.swift @@ -5,9 +5,9 @@ import Foundation let fileManager = FileManager.default enum CICDService { - case github, bitrise, codemagic, later, none + case github, bitrise, codemagic, later - init(_ name: String) { + init?(_ name: String) { switch name.lowercased() { case "g", "github": self = .github @@ -17,14 +17,15 @@ enum CICDService { self = .codemagic case "l", "later": self = .later - default: self = .none + default: + return nil } } } -var service = CICDService.none +var service: CICDService? = nil -while service == .none { +while service == nil { print("Which CI/CD service do you use (Can be edited later) [(g)ithub/(b)itrise/(c)odemagic/(l)ater]: ") service = CICDService(readLine() ?? "") } @@ -42,7 +43,7 @@ case .codemagic: print("Setting template for CodeMagic") fileManager.removeItems(in: "bitrise.yml") fileManager.removeItems(in: ".github/workflows") -case .later, .none: +case .later: print("You can manually setup the template later.") } diff --git a/Scripts/Swift/SetUpDeliveryConstants.swift b/Scripts/Swift/SetUpDeliveryConstants.swift index 97a4813f..dfaf1f43 100644 --- a/Scripts/Swift/SetUpDeliveryConstants.swift +++ b/Scripts/Swift/SetUpDeliveryConstants.swift @@ -6,9 +6,7 @@ let fileManager = FileManager.default print("Do you want to set up Constants values? (Can be edited later) [Y/n]: ") -var arg = "y" - -arg = readLine() ?? arg +var arg = readLine() ?? "y" switch arg.lowercased() { case "y", "yes", "": From f4e3d82097ef5ee8cc086d88b79185ae55feffe6 Mon Sep 17 00:00:00 2001 From: Phong Vo Date: Tue, 18 Jul 2023 16:52:15 +0700 Subject: [PATCH 22/33] [#500] Add new folders to swiftui project --- .../Interfaces/SwiftUI/Sources/Presentation/Coordinators/.gitkeep | 0 Tuist/Interfaces/SwiftUI/Sources/Presentation/Models/.gitkeep | 0 Tuist/Interfaces/SwiftUI/Sources/Presentation/Styles/.gitkeep | 0 Tuist/Interfaces/SwiftUI/Sources/Presentation/ViewIds/.gitkeep | 0 .../SwiftUI/Sources/Presentation/ViewModifiers/.gitkeep | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Tuist/Interfaces/SwiftUI/Sources/Presentation/Coordinators/.gitkeep create mode 100644 Tuist/Interfaces/SwiftUI/Sources/Presentation/Models/.gitkeep create mode 100644 Tuist/Interfaces/SwiftUI/Sources/Presentation/Styles/.gitkeep create mode 100644 Tuist/Interfaces/SwiftUI/Sources/Presentation/ViewIds/.gitkeep create mode 100644 Tuist/Interfaces/SwiftUI/Sources/Presentation/ViewModifiers/.gitkeep diff --git a/Tuist/Interfaces/SwiftUI/Sources/Presentation/Coordinators/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Presentation/Coordinators/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Tuist/Interfaces/SwiftUI/Sources/Presentation/Models/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Presentation/Models/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Tuist/Interfaces/SwiftUI/Sources/Presentation/Styles/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Presentation/Styles/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Tuist/Interfaces/SwiftUI/Sources/Presentation/ViewIds/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Presentation/ViewIds/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Tuist/Interfaces/SwiftUI/Sources/Presentation/ViewModifiers/.gitkeep b/Tuist/Interfaces/SwiftUI/Sources/Presentation/ViewModifiers/.gitkeep new file mode 100644 index 00000000..e69de29b From 3c46f86ac83cda8628314c1dc48b744d7967754c Mon Sep 17 00:00:00 2001 From: Phong Vo Date: Fri, 21 Jul 2023 15:42:23 +0700 Subject: [PATCH 23/33] [500] Update pod file --- Tuist/Interfaces/SwiftUI/Project/Podfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tuist/Interfaces/SwiftUI/Project/Podfile b/Tuist/Interfaces/SwiftUI/Project/Podfile index 59017d36..d2eec0c3 100644 --- a/Tuist/Interfaces/SwiftUI/Project/Podfile +++ b/Tuist/Interfaces/SwiftUI/Project/Podfile @@ -12,9 +12,12 @@ end target '{PROJECT_NAME}' do # UI pod 'Kingfisher' + pod 'FlowStacks' # Backend - pod 'Alamofire' + # Network + pod 'Moya/Combine' + pod 'JSONAPIMapper', :git => 'https://github.com/nimblehq/JSONMapper', :branch => 'main' # Storage pod 'KeychainAccess' From 6346fc696cbeea7b6a6717717e60db4a66203597 Mon Sep 17 00:00:00 2001 From: Phong Vo Date: Mon, 31 Jul 2023 10:12:36 +0700 Subject: [PATCH 24/33] [#505] Remove flowstack --- Tuist/Interfaces/SwiftUI/Project/Podfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Tuist/Interfaces/SwiftUI/Project/Podfile b/Tuist/Interfaces/SwiftUI/Project/Podfile index d2eec0c3..6dbc2e01 100644 --- a/Tuist/Interfaces/SwiftUI/Project/Podfile +++ b/Tuist/Interfaces/SwiftUI/Project/Podfile @@ -12,12 +12,10 @@ end target '{PROJECT_NAME}' do # UI pod 'Kingfisher' - pod 'FlowStacks' # Backend - # Network - pod 'Moya/Combine' - pod 'JSONAPIMapper', :git => 'https://github.com/nimblehq/JSONMapper', :branch => 'main' + pod 'Alamofire' + pod 'JSONAPIMapper', :git => 'https://github.com/nimblehq/JSONMapper', :tag => '1.1.1' # Storage pod 'KeychainAccess' From d7c50a834af5ccd3fbcfd178c433eaddc559cd8d Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 10 Jul 2023 16:56:52 +0700 Subject: [PATCH 25/33] [#491] Migrate SetUpTestFirebase --- Scripts/Swift/SetUpTestFirebase.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Scripts/Swift/SetUpTestFirebase.swift diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift new file mode 100644 index 00000000..dc4bc803 --- /dev/null +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -0,0 +1,18 @@ +static let ConstantTeamId = "<#teamId#>" +static let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" +static let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" +static let ConstantMatchRepo = "git@github.com:{organization}\/{repo}.git" + +let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] +let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] +let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] +let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\/") +let firebaseTesterGroup = "nimble" + +let fileManager = FileManager.default +let workingDirectory = fileManager.currentDirectoryPath + +try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantTeamId)/\(envTeamId)/g\" {} +") +try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantStagingFirebaseAppId)/\(envStagingFirebaseAppId)/g\" {} +") +try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantFirebaseTesterGroups)/\(firebaseTesterGroup)/g\" {} +") +try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantMatchRepo)/\(matchRepoEscaped)/g\" {} +") From 4a661bce9ea50cbccdf9fafe94009a6de750a927 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 10 Jul 2023 17:03:19 +0700 Subject: [PATCH 26/33] [#491] Use Swift in CICD --- .../test_upload_build_to_firebase.yml | 2 +- Scripts/Swift/SetUpTestFirebase.swift | 26 +++++++++---------- make.sh | 1 - set_up_test_firebase.sh | 12 --------- 4 files changed, 14 insertions(+), 27 deletions(-) delete mode 100644 set_up_test_firebase.sh diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 39194acd..3961e6fb 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -50,7 +50,7 @@ jobs: run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App Firebase Upload - run: sh set_up_test_firebase.sh + run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift | swift - env: MATCH_REPO: ${{ secrets.MATCH_REPO }} STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }} diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift index dc4bc803..59664037 100644 --- a/Scripts/Swift/SetUpTestFirebase.swift +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -1,18 +1,18 @@ -static let ConstantTeamId = "<#teamId#>" -static let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" -static let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" -static let ConstantMatchRepo = "git@github.com:{organization}\/{repo}.git" +let ConstantTeamId = "<#teamId#>" +let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" +let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" +let ConstantMatchRepo = "git@github.com:{organization}\\/{repo}.git" -let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] -let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] -let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] -let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\/") +let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] ?? "" +let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] ?? "" +let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] ?? "" +let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\\/") let firebaseTesterGroup = "nimble" let fileManager = FileManager.default -let workingDirectory = fileManager.currentDirectoryPath +let workingDirectory = fileManager.currentDirectoryPath.replacingOccurrences(of: "/", with: "\\/") -try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantTeamId)/\(envTeamId)/g\" {} +") -try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantStagingFirebaseAppId)/\(envStagingFirebaseAppId)/g\" {} +") -try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantFirebaseTesterGroups)/\(firebaseTesterGroup)/g\" {} +") -try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantMatchRepo)/\(matchRepoEscaped)/g\" {} +") +try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantTeamId)/\(envTeamId)/g\" {} +") +try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantStagingFirebaseAppId)/\(envStagingFirebaseAppId)/g\" {} +") +try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantFirebaseTesterGroups)/\(firebaseTesterGroup)/g\" {} +") +try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantMatchRepo)/\(matchRepoEscaped)/g\" {} +") diff --git a/make.sh b/make.sh index 3f8b6ef3..542b8740 100644 --- a/make.sh +++ b/make.sh @@ -215,7 +215,6 @@ git reset if [[ -z "${CI}" ]]; then rm -rf fastlane/Tests - rm -f set_up_test_firebase.sh rm -f set_up_test_testflight.sh cat Scripts/Swift/SetUpCICDService.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' cat Scripts/Swift/SetUpDeliveryConstants.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' diff --git a/set_up_test_firebase.sh b/set_up_test_firebase.sh deleted file mode 100644 index e551f565..00000000 --- a/set_up_test_firebase.sh +++ /dev/null @@ -1,12 +0,0 @@ -readonly CONSTANT_TEAM_ID="<#teamId#>" -readonly CONSTANT_STAGING_FIREBASE_APP_ID="<#stagingFirebaseAppId#>" -readonly CONSTANT_FIREBASE_TESTER_GROUPS="<#group1#>, <#group2#>" -readonly CONSTANT_MATCH_REPO="git@github.com:{organization}\/{repo}.git" - -readonly WORKING_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P) -MATCH_REPO_ESCAPED=$(echo "${MATCH_REPO//\//\\\/}") - -LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_TEAM_ID/$TEAM_ID/g" {} + -LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_STAGING_FIREBASE_APP_ID/$STAGING_FIREBASE_APP_ID/g" {} + -LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_FIREBASE_TESTER_GROUPS/nimble/g" {} + -LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_MATCH_REPO/$MATCH_REPO_ESCAPED/g" {} + From d4ef290e8fc342c3e91f52decb5c7f27bdf728b3 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 10 Jul 2023 17:30:59 +0700 Subject: [PATCH 27/33] [#491] Migrate SetUpTestFirebase --- .github/workflows/test_upload_build_to_firebase.yml | 2 +- Scripts/Swift/Extensions/FileManager+Bash.swift | 8 ++++++++ Scripts/Swift/SetUpTestFirebase.swift | 9 ++++----- make.sh | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 Scripts/Swift/Extensions/FileManager+Bash.swift diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 3961e6fb..6a7b65b5 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -50,7 +50,7 @@ jobs: run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App Firebase Upload - run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift | swift - + run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Bash.swift Scripts/Swift/Helpers/SafeShell.swift | swift - env: MATCH_REPO: ${{ secrets.MATCH_REPO }} STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }} diff --git a/Scripts/Swift/Extensions/FileManager+Bash.swift b/Scripts/Swift/Extensions/FileManager+Bash.swift new file mode 100644 index 00000000..5dfb43e0 --- /dev/null +++ b/Scripts/Swift/Extensions/FileManager+Bash.swift @@ -0,0 +1,8 @@ +import Foundation + +extension FileManager { + + func replaceAllOccurrences(of original: String, to replacing: String) throws { + try safeShell("LC_ALL=C find \(currentDirectoryPath) -type f -exec sed -i \"\" \"s/\(original)/\(replacing)/g\" {} +") + } +} diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift index 59664037..a67d4102 100644 --- a/Scripts/Swift/SetUpTestFirebase.swift +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -10,9 +10,8 @@ let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\\/") let firebaseTesterGroup = "nimble" let fileManager = FileManager.default -let workingDirectory = fileManager.currentDirectoryPath.replacingOccurrences(of: "/", with: "\\/") -try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantTeamId)/\(envTeamId)/g\" {} +") -try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantStagingFirebaseAppId)/\(envStagingFirebaseAppId)/g\" {} +") -try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantFirebaseTesterGroups)/\(firebaseTesterGroup)/g\" {} +") -try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantMatchRepo)/\(matchRepoEscaped)/g\" {} +") +try fileManager.replaceAllOccurrences(of: ConstantTeamId, to: envTeamId) +try fileManager.replaceAllOccurrences(of: ConstantStagingFirebaseAppId, to: envStagingFirebaseAppId) +try fileManager.replaceAllOccurrences(of: ConstantFirebaseTesterGroups, to: firebaseTesterGroup) +try fileManager.replaceAllOccurrences(of: ConstantMatchRepo, to: matchRepoEscaped) diff --git a/make.sh b/make.sh index 542b8740..e9162149 100644 --- a/make.sh +++ b/make.sh @@ -218,9 +218,9 @@ if [[ -z "${CI}" ]]; then rm -f set_up_test_testflight.sh cat Scripts/Swift/SetUpCICDService.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' cat Scripts/Swift/SetUpDeliveryConstants.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' + rm -rf Scripts fi -rm -rf Scripts echo "✅ Completed" From ac197e0bc8d9b0341753f5ba45109f03a7422faf Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Tue, 11 Jul 2023 16:13:24 +0700 Subject: [PATCH 28/33] [#491] Add swift function of replace all in --- .../test_upload_build_to_firebase.yml | 2 +- .../Swift/Extensions/FileManager+Bash.swift | 8 ----- .../Swift/Extensions/FileManager+Utils.swift | 32 +++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) delete mode 100644 Scripts/Swift/Extensions/FileManager+Bash.swift diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 6a7b65b5..3961e6fb 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -50,7 +50,7 @@ jobs: run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App Firebase Upload - run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Bash.swift Scripts/Swift/Helpers/SafeShell.swift | swift - + run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift | swift - env: MATCH_REPO: ${{ secrets.MATCH_REPO }} STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }} diff --git a/Scripts/Swift/Extensions/FileManager+Bash.swift b/Scripts/Swift/Extensions/FileManager+Bash.swift deleted file mode 100644 index 5dfb43e0..00000000 --- a/Scripts/Swift/Extensions/FileManager+Bash.swift +++ /dev/null @@ -1,8 +0,0 @@ -import Foundation - -extension FileManager { - - func replaceAllOccurrences(of original: String, to replacing: String) throws { - try safeShell("LC_ALL=C find \(currentDirectoryPath) -type f -exec sed -i \"\" \"s/\(original)/\(replacing)/g\" {} +") - } -} diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift index cda858de..aba5c4ed 100644 --- a/Scripts/Swift/Extensions/FileManager+Utils.swift +++ b/Scripts/Swift/Extensions/FileManager+Utils.swift @@ -42,4 +42,36 @@ extension FileManager { print("Error \(error)") } } + + func replaceAllOccurrences(of original: String, to replacing: String) throws { + let files = try allFiles(in: currentDirectoryPath) + for file in files { + do { + let text = try String(contentsOf: file, encoding: .utf8) + print(file) + let modifiedText = text.replacingOccurrences(of: original, with: replacing) + try modifiedText.write(to: file, atomically: true, encoding: .utf8) + } + catch { + print(error) + } + } + } + + private func allFiles(in directory: String) throws -> [URL] { + let url = URL(fileURLWithPath: directory) + var files = [URL]() + if let enumerator = enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) { + for case let fileURL as URL in enumerator { + do { + let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey]) + guard fileAttributes.isRegularFile ?? false, + fileURL.pathExtension.count > 0 + else { continue } + files.append(fileURL) + } + } + } + return files + } } From f776ce0eb07af0a7061b0d4d0df973b1f0d40a34 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Tue, 11 Jul 2023 16:28:24 +0700 Subject: [PATCH 29/33] [#491] Add swift function of replace all in --- .github/workflows/test_upload_build_to_firebase.yml | 2 +- Scripts/Swift/Extensions/FileManager+Utils.swift | 5 +---- Scripts/Swift/SetUpTestFirebase.swift | 5 ++--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 3961e6fb..3ccdfb6c 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -50,7 +50,7 @@ jobs: run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App Firebase Upload - run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift | swift - + run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift | swift - env: MATCH_REPO: ${{ secrets.MATCH_REPO }} STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }} diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift index aba5c4ed..3b4befa9 100644 --- a/Scripts/Swift/Extensions/FileManager+Utils.swift +++ b/Scripts/Swift/Extensions/FileManager+Utils.swift @@ -48,7 +48,6 @@ extension FileManager { for file in files { do { let text = try String(contentsOf: file, encoding: .utf8) - print(file) let modifiedText = text.replacingOccurrences(of: original, with: replacing) try modifiedText.write(to: file, atomically: true, encoding: .utf8) } @@ -65,9 +64,7 @@ extension FileManager { for case let fileURL as URL in enumerator { do { let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey]) - guard fileAttributes.isRegularFile ?? false, - fileURL.pathExtension.count > 0 - else { continue } + guard fileAttributes.isRegularFile ?? false else { continue } files.append(fileURL) } } diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift index a67d4102..0f7e5faa 100644 --- a/Scripts/Swift/SetUpTestFirebase.swift +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -1,12 +1,11 @@ let ConstantTeamId = "<#teamId#>" let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" -let ConstantMatchRepo = "git@github.com:{organization}\\/{repo}.git" +let ConstantMatchRepo = "git@github.com:{organization}/{repo}.git" let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] ?? "" let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] ?? "" let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] ?? "" -let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\\/") let firebaseTesterGroup = "nimble" let fileManager = FileManager.default @@ -14,4 +13,4 @@ let fileManager = FileManager.default try fileManager.replaceAllOccurrences(of: ConstantTeamId, to: envTeamId) try fileManager.replaceAllOccurrences(of: ConstantStagingFirebaseAppId, to: envStagingFirebaseAppId) try fileManager.replaceAllOccurrences(of: ConstantFirebaseTesterGroups, to: firebaseTesterGroup) -try fileManager.replaceAllOccurrences(of: ConstantMatchRepo, to: matchRepoEscaped) +try fileManager.replaceAllOccurrences(of: ConstantMatchRepo, to: envMatchRepo) From 614371b9f48e2b3550604746895731d9e2c68126 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Tue, 11 Jul 2023 16:41:53 +0700 Subject: [PATCH 30/33] [#491] Add swift function of replace all in --- Scripts/Swift/Extensions/FileManager+Utils.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift index 3b4befa9..56238b2a 100644 --- a/Scripts/Swift/Extensions/FileManager+Utils.swift +++ b/Scripts/Swift/Extensions/FileManager+Utils.swift @@ -51,9 +51,7 @@ extension FileManager { let modifiedText = text.replacingOccurrences(of: original, with: replacing) try modifiedText.write(to: file, atomically: true, encoding: .utf8) } - catch { - print(error) - } + catch {} } } From 9957516eb2c1a60c4e57c38c414eda9418d0ed1d Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 4 Aug 2023 11:23:09 +0700 Subject: [PATCH 31/33] [#491] Fix try blocks --- .../Swift/Extensions/FileManager+Utils.swift | 22 +++++++++++-------- Scripts/Swift/SetUpTestFirebase.swift | 16 +++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift index 56238b2a..c55c4e4a 100644 --- a/Scripts/Swift/Extensions/FileManager+Utils.swift +++ b/Scripts/Swift/Extensions/FileManager+Utils.swift @@ -43,28 +43,32 @@ extension FileManager { } } - func replaceAllOccurrences(of original: String, to replacing: String) throws { - let files = try allFiles(in: currentDirectoryPath) + func replaceAllOccurrences(of original: String, to replacing: String) { + let files = try? allFiles(in: currentDirectoryPath) + guard let files else { return print("Cannot find any files in current directory") } for file in files { do { let text = try String(contentsOf: file, encoding: .utf8) let modifiedText = text.replacingOccurrences(of: original, with: replacing) try modifiedText.write(to: file, atomically: true, encoding: .utf8) + } catch { + print(error.localizedDescription) } - catch {} } } private func allFiles(in directory: String) throws -> [URL] { let url = URL(fileURLWithPath: directory) var files = [URL]() - if let enumerator = enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) { + if let enumerator = enumerator( + at: url, + includingPropertiesForKeys: [.isRegularFileKey], + options: [.skipsHiddenFiles, .skipsPackageDescendants] + ) { for case let fileURL as URL in enumerator { - do { - let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey]) - guard fileAttributes.isRegularFile ?? false else { continue } - files.append(fileURL) - } + let fileAttributes = try? fileURL.resourceValues(forKeys:[.isRegularFileKey]) + guard fileAttributes?.isRegularFile ?? false else { continue } + files.append(fileURL) } } return files diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift index 0f7e5faa..f7b36fbb 100644 --- a/Scripts/Swift/SetUpTestFirebase.swift +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -1,7 +1,7 @@ -let ConstantTeamId = "<#teamId#>" -let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" -let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" -let ConstantMatchRepo = "git@github.com:{organization}/{repo}.git" +let teamIdPlaceholder = "<#teamId#>" +let stagingFirebaseAppIdPlaceholder = "<#stagingFirebaseAppId#>" +let firebaseTesterGroupsPlaceholder = "<#group1#>, <#group2#>" +let matchRepoPlaceholder = "git@github.com:{organization}/{repo}.git" let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] ?? "" let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] ?? "" @@ -10,7 +10,7 @@ let firebaseTesterGroup = "nimble" let fileManager = FileManager.default -try fileManager.replaceAllOccurrences(of: ConstantTeamId, to: envTeamId) -try fileManager.replaceAllOccurrences(of: ConstantStagingFirebaseAppId, to: envStagingFirebaseAppId) -try fileManager.replaceAllOccurrences(of: ConstantFirebaseTesterGroups, to: firebaseTesterGroup) -try fileManager.replaceAllOccurrences(of: ConstantMatchRepo, to: envMatchRepo) +fileManager.replaceAllOccurrences(of: teamIdPlaceholder, to: envTeamId) +fileManager.replaceAllOccurrences(of: stagingFirebaseAppIdPlaceholder, to: envStagingFirebaseAppId) +fileManager.replaceAllOccurrences(of: firebaseTesterGroupsPlaceholder, to: firebaseTesterGroup) +fileManager.replaceAllOccurrences(of: matchRepoPlaceholder, to: envMatchRepo) From 27a283cce28f3f3e41561c7982c03297325f9ed1 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 4 Aug 2023 11:28:45 +0700 Subject: [PATCH 32/33] [#491] Fix local build --- Scripts/Swift/SetUpCICDService.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Swift/SetUpCICDService.swift b/Scripts/Swift/SetUpCICDService.swift index 35a22abb..bc8ab07b 100644 --- a/Scripts/Swift/SetUpCICDService.swift +++ b/Scripts/Swift/SetUpCICDService.swift @@ -43,7 +43,7 @@ case .codemagic: print("Setting template for CodeMagic") fileManager.removeItems(in: "bitrise.yml") fileManager.removeItems(in: ".github/workflows") -case .later: +case .later, .none: print("You can manually setup the template later.") } From 5020d934788bffd698a9b742164049a0d4ded6d9 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Wed, 9 Aug 2023 10:06:49 +0700 Subject: [PATCH 33/33] Fix Danger import old files --- Dangerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dangerfile b/Dangerfile index 84cb7b02..c19fdcd9 100644 --- a/Dangerfile +++ b/Dangerfile @@ -1,7 +1,5 @@ # frozen_string_literal: true -require './fastlane/Constants/Constants' - # Warn when there is a big PR warn("This pull request is quite big (#{git.lines_of_code} lines changed), please consider splitting it into multiple pull requests.") if git.lines_of_code > 500