From 4cf4cbbddd02573e129ad92551b5592911730246 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Tue, 22 Aug 2023 17:56:11 +0700 Subject: [PATCH] [#495] Add Swift package for Make --- .../workflows/test_swiftui_install_script.yml | 2 +- .../workflows/test_uikit_install_script.yml | 2 +- .../test_upload_build_to_firebase.yml | 4 +- .../test_upload_build_to_test_flight.yml | 4 +- .gitignore | 3 + Scripts/Swift/SetUpTestFirebase.swift | 16 ---- Scripts/Swift/SetUpTestTestFlight.swift | 16 ---- .../Swift/iOSTemplateMaker/Package.resolved | 14 ++++ Scripts/Swift/iOSTemplateMaker/Package.swift | 28 +++++++ Scripts/Swift/iOSTemplateMaker/README.md | 3 + .../Extensions/FileManager+Utils.swift | 0 .../Extensions/Optional+Utils.swift | 18 +++++ .../Extensions/String+Utils.swift | 3 + .../iOSTemplateMaker}/Helpers/SafeShell.swift | 0 .../iOSTemplateMaker}/SetUpCICDService.swift | 4 +- .../SetUpDeliveryConstants.swift | 0 .../iOSTemplateMaker}/SetUpInterface.swift | 2 + .../iOSTemplateMaker/SetUpTestFirebase.swift | 23 ++++++ .../SetUpTestTestFlight.swift | 23 ++++++ .../iOSTemplateMaker}/SetUpiOSProject.swift | 42 +++++----- .../iOSTemplateMaker/iOSTemplateMaker.swift | 78 +++++++++++++++++++ .../iOSTemplateMakerTests.swift | 11 +++ make.sh | 74 ------------------ 23 files changed, 236 insertions(+), 134 deletions(-) delete mode 100644 Scripts/Swift/SetUpTestFirebase.swift delete mode 100644 Scripts/Swift/SetUpTestTestFlight.swift create mode 100644 Scripts/Swift/iOSTemplateMaker/Package.resolved create mode 100644 Scripts/Swift/iOSTemplateMaker/Package.swift create mode 100644 Scripts/Swift/iOSTemplateMaker/README.md rename Scripts/Swift/{ => iOSTemplateMaker/Sources/iOSTemplateMaker}/Extensions/FileManager+Utils.swift (100%) create mode 100644 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/Optional+Utils.swift rename Scripts/Swift/{ => iOSTemplateMaker/Sources/iOSTemplateMaker}/Extensions/String+Utils.swift (83%) rename Scripts/Swift/{ => iOSTemplateMaker/Sources/iOSTemplateMaker}/Helpers/SafeShell.swift (100%) rename Scripts/Swift/{ => iOSTemplateMaker/Sources/iOSTemplateMaker}/SetUpCICDService.swift (95%) rename Scripts/Swift/{ => iOSTemplateMaker/Sources/iOSTemplateMaker}/SetUpDeliveryConstants.swift (100%) rename Scripts/Swift/{ => iOSTemplateMaker/Sources/iOSTemplateMaker}/SetUpInterface.swift (98%) create mode 100644 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestFirebase.swift create mode 100644 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestTestFlight.swift rename Scripts/Swift/{ => iOSTemplateMaker/Sources/iOSTemplateMaker}/SetUpiOSProject.swift (88%) create mode 100644 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/iOSTemplateMaker.swift create mode 100644 Scripts/Swift/iOSTemplateMaker/Tests/iOSTemplateMakerTests/iOSTemplateMakerTests.swift delete mode 100644 make.sh diff --git a/.github/workflows/test_swiftui_install_script.yml b/.github/workflows/test_swiftui_install_script.yml index 7002abae..bded91e1 100644 --- a/.github/workflows/test_swiftui_install_script.yml +++ b/.github/workflows/test_swiftui_install_script.yml @@ -19,7 +19,7 @@ jobs: 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 + run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make --bundle-id-production co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface SwiftUI - name: Build and Test run: bundle exec fastlane buildAndTest diff --git a/.github/workflows/test_uikit_install_script.yml b/.github/workflows/test_uikit_install_script.yml index d5cc86e9..3f4d0a60 100644 --- a/.github/workflows/test_uikit_install_script.yml +++ b/.github/workflows/test_uikit_install_script.yml @@ -19,7 +19,7 @@ jobs: run: bundle install - 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 + run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make --bundle-id-production co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.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 5f8d2655..8b0becfc 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -47,10 +47,10 @@ 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 --interface UIKit + run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make --bundle-id-production 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 | swift - + run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make-test-firebase env: MATCH_REPO: ${{ secrets.MATCH_REPO }} STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }} diff --git a/.github/workflows/test_upload_build_to_test_flight.yml b/.github/workflows/test_upload_build_to_test_flight.yml index 28baf490..9d68acba 100644 --- a/.github/workflows/test_upload_build_to_test_flight.yml +++ b/.github/workflows/test_upload_build_to_test_flight.yml @@ -44,10 +44,10 @@ 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 --interface UIKit + run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make --bundle-id-production 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: cat Scripts/Swift/SetUpTestTestFlight.swift Scripts/Swift/Extensions/FileManager+Utils.swift | swift - + run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make-test-test-flight env: MATCH_REPO: ${{ secrets.MATCH_REPO }} API_KEY_ID: ${{ secrets.API_KEY_ID }} diff --git a/.gitignore b/.gitignore index d64a8594..398c9216 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,6 @@ dependencies/ # Environment .env +Scripts/Swift/iOSTemplateMaker/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +Scripts/Swift/iOSTemplateMaker/.build +Scripts/Swift/iOSTemplateMaker/.swiftpm diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift deleted file mode 100644 index f7b36fbb..00000000 --- a/Scripts/Swift/SetUpTestFirebase.swift +++ /dev/null @@ -1,16 +0,0 @@ -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"] ?? "" -let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] ?? "" -let firebaseTesterGroup = "nimble" - -let fileManager = FileManager.default - -fileManager.replaceAllOccurrences(of: teamIdPlaceholder, to: envTeamId) -fileManager.replaceAllOccurrences(of: stagingFirebaseAppIdPlaceholder, to: envStagingFirebaseAppId) -fileManager.replaceAllOccurrences(of: firebaseTesterGroupsPlaceholder, to: firebaseTesterGroup) -fileManager.replaceAllOccurrences(of: matchRepoPlaceholder, to: envMatchRepo) diff --git a/Scripts/Swift/SetUpTestTestFlight.swift b/Scripts/Swift/SetUpTestTestFlight.swift deleted file mode 100644 index 950c4952..00000000 --- a/Scripts/Swift/SetUpTestTestFlight.swift +++ /dev/null @@ -1,16 +0,0 @@ -let teamIdPlaceholder = "<#teamId#>" -let apiKeyIdPlaceholder = "<#API_KEY_ID#>" -let issuerIdPlaceholder = "<#ISSUER_ID#>" -let matchRepoPlaceholder = "git@github.com:{organization}/{repo}.git" - -let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] ?? "" -let envApiKey = ProcessInfo.processInfo.environment["API_KEY_ID"] ?? "" -let envIssuerId = ProcessInfo.processInfo.environment["ISSUER_ID"] ?? "" -let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] ?? "" - -let fileManager = FileManager.default - -fileManager.replaceAllOccurrences(of: teamIdPlaceholder, to: envTeamId) -fileManager.replaceAllOccurrences(of: apiKeyIdPlaceholder, to: envApiKey) -fileManager.replaceAllOccurrences(of: issuerIdPlaceholder, to: envIssuerId) -fileManager.replaceAllOccurrences(of: matchRepoPlaceholder, to: envMatchRepo) diff --git a/Scripts/Swift/iOSTemplateMaker/Package.resolved b/Scripts/Swift/iOSTemplateMaker/Package.resolved new file mode 100644 index 00000000..d429d392 --- /dev/null +++ b/Scripts/Swift/iOSTemplateMaker/Package.resolved @@ -0,0 +1,14 @@ +{ + "pins" : [ + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser.git", + "state" : { + "revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531", + "version" : "1.2.3" + } + } + ], + "version" : 2 +} diff --git a/Scripts/Swift/iOSTemplateMaker/Package.swift b/Scripts/Swift/iOSTemplateMaker/Package.swift new file mode 100644 index 00000000..46e6dd43 --- /dev/null +++ b/Scripts/Swift/iOSTemplateMaker/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version: 5.7.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "iOSTemplateMaker", + products: [ + .executable( + name: "iOSTemplateMaker", + targets: ["iOSTemplateMaker"] + ), + ], + dependencies: [ + .package( + url: "https://github.com/apple/swift-argument-parser.git", + from: "1.0.0" + ), + ], + targets: [ + .executableTarget( + name: "iOSTemplateMaker", + dependencies: [ + .product(name: "ArgumentParser", package: "swift-argument-parser") + ] + ), + ] +) diff --git a/Scripts/Swift/iOSTemplateMaker/README.md b/Scripts/Swift/iOSTemplateMaker/README.md new file mode 100644 index 00000000..552722bb --- /dev/null +++ b/Scripts/Swift/iOSTemplateMaker/README.md @@ -0,0 +1,3 @@ +# iOSTemplateMaker + +A description of this package. diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/FileManager+Utils.swift similarity index 100% rename from Scripts/Swift/Extensions/FileManager+Utils.swift rename to Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/FileManager+Utils.swift diff --git a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/Optional+Utils.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/Optional+Utils.swift new file mode 100644 index 00000000..40610fbe --- /dev/null +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/Optional+Utils.swift @@ -0,0 +1,18 @@ +import Foundation + +extension Optional { + + func unwrappedOr(_ defaultValue: Wrapped) -> Wrapped { + switch self { + case .none: + return defaultValue + case let .some(value): + return value + } + } +} + +extension Optional where Wrapped == String { + + var string: String { unwrappedOr("") } +} diff --git a/Scripts/Swift/Extensions/String+Utils.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/String+Utils.swift similarity index 83% rename from Scripts/Swift/Extensions/String+Utils.swift rename to Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/String+Utils.swift index 76ccddaf..527a0b9f 100644 --- a/Scripts/Swift/Extensions/String+Utils.swift +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/String+Utils.swift @@ -1,5 +1,8 @@ +import Foundation + extension String { + /// Match string with regex expression static func ~= (lhs: String, rhs: String) -> Bool { guard let regex = try? NSRegularExpression(pattern: rhs) else { return false } let range = NSRange(location: 0, length: lhs.utf16.count) diff --git a/Scripts/Swift/Helpers/SafeShell.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Helpers/SafeShell.swift similarity index 100% rename from Scripts/Swift/Helpers/SafeShell.swift rename to Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Helpers/SafeShell.swift diff --git a/Scripts/Swift/SetUpCICDService.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift similarity index 95% rename from Scripts/Swift/SetUpCICDService.swift rename to Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift index b94d97d4..a126355c 100644 --- a/Scripts/Swift/SetUpCICDService.swift +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift @@ -1,3 +1,5 @@ +import Foundation + struct SetUpCICDService { enum CICDService { @@ -26,7 +28,7 @@ struct SetUpCICDService { var service: CICDService? = nil 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() ?? "") + service = CICDService(readLine().string) } switch service { diff --git a/Scripts/Swift/SetUpDeliveryConstants.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpDeliveryConstants.swift similarity index 100% rename from Scripts/Swift/SetUpDeliveryConstants.swift rename to Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpDeliveryConstants.swift diff --git a/Scripts/Swift/SetUpInterface.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpInterface.swift similarity index 98% rename from Scripts/Swift/SetUpInterface.swift rename to Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpInterface.swift index f34d42b8..295af3b1 100644 --- a/Scripts/Swift/SetUpInterface.swift +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpInterface.swift @@ -1,3 +1,5 @@ +import Foundation + struct SetUpInterface { enum Interface { diff --git a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestFirebase.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestFirebase.swift new file mode 100644 index 00000000..5f23b513 --- /dev/null +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestFirebase.swift @@ -0,0 +1,23 @@ +import Foundation + +struct SetUpTestFirebase { + + private let teamIdPlaceholder = "<#teamId#>" + private let stagingFirebaseAppIdPlaceholder = "<#stagingFirebaseAppId#>" + private let firebaseTesterGroupsPlaceholder = "<#group1#>, <#group2#>" + private let matchRepoPlaceholder = "git@github.com:{organization}/{repo}.git" + + private let firebaseTesterGroup = "nimble" + private let fileManager = FileManager.default + + let matchRepo: String + let stagingFirebaseAppId: String + let teamId: String + + func perform() { + fileManager.replaceAllOccurrences(of: teamIdPlaceholder, to: teamId) + fileManager.replaceAllOccurrences(of: stagingFirebaseAppIdPlaceholder, to: stagingFirebaseAppId) + fileManager.replaceAllOccurrences(of: firebaseTesterGroupsPlaceholder, to: firebaseTesterGroup) + fileManager.replaceAllOccurrences(of: matchRepoPlaceholder, to: matchRepo) + } +} diff --git a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestTestFlight.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestTestFlight.swift new file mode 100644 index 00000000..5dd58752 --- /dev/null +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestTestFlight.swift @@ -0,0 +1,23 @@ +import Foundation + +struct SetUpTestTestFlight { + + private let teamIdPlaceholder = "<#teamId#>" + private let apiKeyIdPlaceholder = "<#API_KEY_ID#>" + private let issuerIdPlaceholder = "<#ISSUER_ID#>" + private let matchRepoPlaceholder = "git@github.com:{organization}/{repo}.git" + + private let fileManager = FileManager.default + + let matchRepo: String + let apiKey: String + let issuerId: String + let teamId: String + + func perform() { + fileManager.replaceAllOccurrences(of: teamIdPlaceholder, to: teamId) + fileManager.replaceAllOccurrences(of: apiKeyIdPlaceholder, to: apiKey) + fileManager.replaceAllOccurrences(of: issuerIdPlaceholder, to: issuerId) + fileManager.replaceAllOccurrences(of: matchRepoPlaceholder, to: matchRepo) + } +} diff --git a/Scripts/Swift/SetUpiOSProject.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpiOSProject.swift similarity index 88% rename from Scripts/Swift/SetUpiOSProject.swift rename to Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpiOSProject.swift index 9ad2ac5f..89d759ac 100644 --- a/Scripts/Swift/SetUpiOSProject.swift +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpiOSProject.swift @@ -1,4 +1,4 @@ -#!/usr/bin/swift +import Foundation class SetUpIOSProject { @@ -14,7 +14,21 @@ class SetUpIOSProject { private var minimumVersion = "" private var interface: SetUpInterface.Interface? private var projectNameNoSpace: String { projectName.trimmingCharacters(in: .whitespacesAndNewlines) } - private var isCI = !(ProcessInfo.processInfo.environment["CI"] ?? "").isEmpty + private var isCI = !((ProcessInfo.processInfo.environment["CI"]).string).isEmpty + + init( + bundleIdProduction: String = "", + bundleIdStaging: String = "", + projectName: String = "", + minimumVersion: String = "", + interface: String = "" + ) { + self.bundleIdProduction = bundleIdProduction + self.bundleIdStaging = bundleIdStaging + self.projectName = projectName + self.minimumVersion = minimumVersion + self.interface = .init(interface) + } func perform() { readArguments() @@ -34,42 +48,30 @@ class SetUpIOSProject { } private func readArguments() { - // TODO: Should be replaced with ArgumentParser instead of command line - for (index, argument) in CommandLine.arguments.enumerated() { - switch index { - case 1: bundleIdProduction = argument - case 2: bundleIdStaging = argument - case 3: projectName = argument - case 4: minimumVersion = argument - case 5: interface = .init(argument) - default: break - } - } - if isCI { minimumVersion = "14.0" } while bundleIdProduction.isEmpty || !checkPackageName(bundleIdProduction) { print("BUNDLE ID PRODUCTION (i.e. com.example.project):") - bundleIdProduction = readLine() ?? "" + bundleIdProduction = readLine().string } while bundleIdStaging.isEmpty || !checkPackageName(bundleIdStaging) { print("BUNDLE ID STAGING (i.e. com.example.project.staging):") - bundleIdStaging = readLine() ?? "" + bundleIdStaging = readLine().string } while projectName.isEmpty { print("PROJECT NAME (i.e. NewProject):") - projectName = readLine() ?? "" + projectName = readLine().string } while minimumVersion.isEmpty || !checkVersion(minimumVersion) { print("iOS Minimum Version (i.e. 14.0):") - let version = readLine() ?? "" + let version = readLine().string minimumVersion = !version.isEmpty ? version : "14.0" } while interface == nil { print("Interface [(S)wiftUI or (U)IKit]:") - interface = SetUpInterface.Interface(readLine() ?? "") + interface = SetUpInterface.Interface(readLine().string) } } @@ -191,5 +193,3 @@ class SetUpIOSProject { return valid } } - -SetUpIOSProject().perform() diff --git a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/iOSTemplateMaker.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/iOSTemplateMaker.swift new file mode 100644 index 00000000..fc8c3fd4 --- /dev/null +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/iOSTemplateMaker.swift @@ -0,0 +1,78 @@ +import ArgumentParser +import Foundation + +@main +struct iOSTemplateMaker: ParsableCommand { + + static let configuration: CommandConfiguration = CommandConfiguration( + abstract: "Set up an iOS Project", + subcommands: [Make.self, MakeTestFirebase.self, MakeTestTestFlight.self], + defaultSubcommand: Make.self + ) +} + +extension iOSTemplateMaker { + + struct Make: ParsableCommand { + + @Option(help: "The production id (i.e. com.example.package)") + var bundleIdProduction: String? + @Option(help: "The staging id (i.e. com.example.package.staging)") + var bundleIdStaging: String? + @Option(help: "The project name (i.e. MyApp)") + var projectName: String? + @Option(help: "The minimum iOS version (14.0)") + var minimumVersion: String? + @Option(help: "The user interface frameword (SwiftUI or UIKit)") + var interface: String? + + mutating func run() { + SetUpIOSProject( + bundleIdProduction: bundleIdProduction.string, + bundleIdStaging: bundleIdStaging.string, + projectName: projectName.string, + minimumVersion: minimumVersion.string, + interface: interface.string + ).perform() + } + } +} + +extension iOSTemplateMaker { + + struct MakeTestFirebase: ParsableCommand { + + mutating func run() { + let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"].string + let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"].string + let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"].string + + SetUpTestFirebase( + matchRepo: envMatchRepo, + stagingFirebaseAppId: envStagingFirebaseAppId, + teamId: envTeamId + ).perform() + } + } +} + + +extension iOSTemplateMaker { + + struct MakeTestTestFlight: ParsableCommand { + + mutating func run() { + let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"].string + let envApiKey = ProcessInfo.processInfo.environment["API_KEY_ID"].string + let envIssuerId = ProcessInfo.processInfo.environment["ISSUER_ID"].string + let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"].string + + SetUpTestTestFlight( + matchRepo: envMatchRepo, + apiKey: envApiKey, + issuerId: envIssuerId, + teamId: envTeamId + ).perform() + } + } +} diff --git a/Scripts/Swift/iOSTemplateMaker/Tests/iOSTemplateMakerTests/iOSTemplateMakerTests.swift b/Scripts/Swift/iOSTemplateMaker/Tests/iOSTemplateMakerTests/iOSTemplateMakerTests.swift new file mode 100644 index 00000000..bae860b5 --- /dev/null +++ b/Scripts/Swift/iOSTemplateMaker/Tests/iOSTemplateMakerTests/iOSTemplateMakerTests.swift @@ -0,0 +1,11 @@ +import XCTest +@testable import iOSTemplateMaker + +final class iOSTemplateMakerTests: XCTestCase { + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + XCTAssertEqual(iOSTemplateMaker().text, "Hello, World!") + } +} diff --git a/make.sh b/make.sh deleted file mode 100644 index 61a83ee0..00000000 --- a/make.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh -set -e - -# Script inspired by https://gist.github.com/szeidner/613fe4652fc86f083cefa21879d5522b - -readonly PROGNAME=$(basename $0) -readonly WORKING_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P) - -die() { - echo "$PROGNAME: $*" >&2 - exit 1 -} - -usage() { - if [ "$*" != "" ] ; then - echo "Error: $*" - fi - - cat << EOF -Usage: $PROGNAME --bundle-id [BUNDLE_ID_PRODUCTION] --bundle-id-staging [BUNDLE_ID_STAGING] --project-name [PROJECT_NAME] --minimum-version [MINIMUM_VERSION] --interface [INTERFACE] -Set up an iOS app from tuist template. -Options: --h, --help display this usage message and exit --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) --m, --minimum-version [MINIMUM_VERSION] the minimum version of the project (i.e. 14.0) --i, --interface [INTERFACE] the user interface frameword (SwiftUI or UIKit) -EOF - exit 1 -} - -bundle_id_production="" -bundle_id_staging="" -project_name="" -minimum_version="" -interface="" - -while [ $# -gt 0 ] ; do - case "$1" in - -h|--help) - usage - ;; - -b|--bundle-id) - bundle_id_production="$2" - shift - ;; - -s|--bundle-id-staging) - bundle_id_staging="$2" - shift - ;; - -n|--project-name) - project_name="$2" - shift - ;; - -m|--minimum-version) - minimum_version="$2" - shift - ;; - -i|--interface) - interface="$2" - shift - ;; - -*) - usage "Unknown option '$1'" - ;; - *) - usage "Too many arguments" - ;; - esac - shift -done - -cat Scripts/Swift/SetUpiOSProject.swift Scripts/Swift/SetUpCICDService.swift Scripts/Swift/SetUpDeliveryConstants.swift Scripts/Swift/SetUpInterface.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Extensions/String+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift $bundle_id_production $bundle_id_staging $project_name "$minimum_version" $interface && rm -rf 't.swift'