Skip to content

Commit

Permalink
Merge pull request #514 from nimblehq/feature/#495-package-setup-swif…
Browse files Browse the repository at this point in the history
…t-command

[#495] Package all Swift Commands
  • Loading branch information
blyscuit authored Oct 4, 2023
2 parents 3449d97 + e3fb966 commit afedd78
Show file tree
Hide file tree
Showing 34 changed files with 322 additions and 152 deletions.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions .github/project_workflows/publish_docs_to_wiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish docs to Wiki

on:
push:
paths:
- .github/wiki/**
branches:
- main
- master

jobs:
publish_docs_to_wiki:
name: Publish Wiki
uses: nimblehq/github-actions-workflows/.github/workflows/[email protected]
with:
USER_NAME: team-nimblehq
USER_EMAIL: [email protected]
secrets:
USER_TOKEN: ${{ secrets.NIMBLE_DEV_TOKEN }}
2 changes: 1 addition & 1 deletion .github/wiki/Deliverable-Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The file [DeliverableConstants.rb](https://github.com/nimblehq/ios-templates/blo

## Use the template

1. Running the `make.sh` script will ask if the developer wants to configure the `DeliverableConstants` file.
1. Running the `iOSTemplateMaker` script will ask if the developer wants to configure the `DeliverableConstants` file.
2. When confirming with the prompt, the template will launch Xcode to modify the `DeliverableConstants` file.

## Configure later
Expand Down
18 changes: 17 additions & 1 deletion .github/wiki/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,21 @@
2. Clone your repository
3. Setup the project by running the following command in your terminal:
```bash
sh make.sh --bundle-id [BUNDLE_ID_PRODUCTION] --bundle-id-staging [BUNDLE_ID_STAGING] --project-name [PROJECT_NAME]
swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make
```

## Options

Options are optional and will be prompted if not provided. Example is provided in (brackets).

- `--bundle-id-production`: The application's bundle id for production variant. (co.nimblehq.project)
- `--bundle-id-staging`: The application's bundle id for staging variant. (co.nimblehq.project.staging)
- `--project-name`: The name of the project. (Project)
- `--minimum-version`: The minimum version of the iOS application. (14.0)
- `--interface`: The user interface. (UIKit or SwiftUI)

### Example

```
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
```
2 changes: 1 addition & 1 deletion .github/wiki/Selecting-User-Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Current the template supports setup with two user interfaces:
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
swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make --interface SwiftUI
```
2 changes: 1 addition & 1 deletion .github/workflows/test_swiftui_install_script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_uikit_install_script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_upload_build_to_firebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_upload_build_to_test_flight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ dependencies/

# Environment
.env
Scripts/Swift/iOSTemplateMaker/.*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Our optimized iOS template used in our projects using Xcode Templates
2. Clone your repository
3. Setup the project by running the following command in your terminal:
```bash
sh make.sh --bundle-id [BUNDLE_ID_PRODUCTION] --bundle-id-staging [BUNDLE_ID_STAGING] --project-name [PROJECT_NAME]
swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make
```

## Full Documentation
Expand All @@ -53,4 +53,4 @@ We love open source and do our part in sharing our work with the community!
See [our other projects][community] or [hire our team][hire] to help build your product.

[community]: https://github.com/nimblehq
[hire]: https://nimblehq.co/
[hire]: https://nimblehq.co/
16 changes: 0 additions & 16 deletions Scripts/Swift/SetUpTestFirebase.swift

This file was deleted.

16 changes: 0 additions & 16 deletions Scripts/Swift/SetUpTestTestFlight.swift

This file was deleted.

14 changes: 14 additions & 0 deletions Scripts/Swift/iOSTemplateMaker/Package.resolved
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions Scripts/Swift/iOSTemplateMaker/Package.swift
Original file line number Diff line number Diff line change
@@ -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")
]
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ extension FileManager {
}
}

func createFile(name: String, at directory: String) {
func createDirectory(path: String) {
let currentDirectory = currentDirectoryPath
do {
try createDirectory(atPath: "\(currentDirectory)/\(directory)", withIntermediateDirectories: true, attributes: nil)
try createDirectory(atPath: "\(currentDirectory)/\(path)", withIntermediateDirectories: true, attributes: nil)
} catch {
print("Error \(error)")
}
}

func createFile(name: String, at directory: String) {
let currentDirectory = currentDirectoryPath
createDirectory(path: directory)
createFile(atPath: "\(currentDirectory)\(directory)\(name)", contents: nil)
}

Expand All @@ -66,7 +71,9 @@ extension FileManager {
}

func replaceAllOccurrences(of original: String, to replacing: String) {
let files = try? allFiles(in: currentDirectoryPath)
let swiftScriptBuildDirectory = "Scripts/Swift/iOSTemplateMaker/.build".lowercased()
let pngImage = ".png"
let files = try? allFiles(in: currentDirectoryPath, skips: [swiftScriptBuildDirectory, pngImage])
guard let files else { return print("Cannot find any files in current directory") }
for file in files {
do {
Expand All @@ -79,7 +86,7 @@ extension FileManager {
}
}

private func allFiles(in directory: String) throws -> [URL] {
private func allFiles(in directory: String, skips: [String] = []) throws -> [URL] {
let url = URL(fileURLWithPath: directory)
var files = [URL]()
if let enumerator = enumerator(
Expand All @@ -90,6 +97,7 @@ extension FileManager {
let hiddenFolderRegex = "\(directory.replacingOccurrences(of: "/", with: "\\/"))\\/\\..*\\/"
for case let fileURL as URL in enumerator {
guard !(fileURL.relativePath ~= hiddenFolderRegex) else { continue }
guard !(skips.contains(where: { fileURL.relativePath.lowercased().contains($0) })) else { continue }
let fileAttributes = try? fileURL.resourceValues(forKeys:[.isRegularFileKey])
guard fileAttributes?.isRegularFile ?? false else { continue }
files.append(fileURL)
Expand Down
Original file line number Diff line number Diff line change
@@ -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("") }
}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// EnvironmentValue.swift
//
//
// Created by Bliss on 30/8/23.
//

import Foundation

enum EnvironmentValue {

static func value(for key: String) -> String? {
ProcessInfo.processInfo.environment[key]
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// EnvironmentKey.swift
//
//
// Created by Bliss on 30/8/23.
//

enum EnvironmentKey: String {

case matchRepo = "MATCH_REPO"
case stagingFirebaseAppId = "STAGING_FIREBASE_APP_ID"
case teamId = "TEAM_ID"
case apiKey = "API_KEY_ID"
case issuerId = "ISSUER_ID"
case isCI = "CI"
}

extension EnvironmentValue {

static func value(for key: EnvironmentKey) -> String? {
Self.value(for: key.rawValue)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

struct SetUpCICDService {

enum CICDService {
Expand Down Expand Up @@ -26,14 +28,18 @@ 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 {
case .github:
print("Setting template for Github Actions")
fileManager.removeItems(in: "bitrise.yml")
fileManager.removeItems(in: "codemagic.yaml")
fileManager.removeItems(in: ".github/workflows")
fileManager.createDirectory(path: ".github/workflows")
fileManager.moveFiles(in: ".github/project_workflows", to: ".github/workflows")
fileManager.removeItems(in: ".github/project_workflows")
case .bitrise:
print("Setting template for Bitrise")
fileManager.removeItems(in: "codemagic.yaml")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import Foundation

struct SetUpInterface {

enum Interface {

case swiftUI, uiKit

init?(_ name: String) {
switch name.lowercased() {
case "s", "swiftui":
let name = name.lowercased()
if name == "s" || name == "swiftui" {
self = .swiftUI
case "u", "uikit":
} else if name == "u" || name == "uikit" {
self = .uiKit
default: return nil
} else {
return nil
}
}

Expand Down Expand Up @@ -40,7 +43,7 @@ struct SetUpInterface {
let folderName = interface.folderName

fileManager.moveFiles(in: "tuist/Interfaces/\(folderName)/Project", to: "")
fileManager.moveFiles(in: "tuist/Interfaces/\(folderName)/Sources", to: "TemplateApp/Sources")
fileManager.moveFiles(in: "tuist/Interfaces/\(folderName)/Sources", to: "\(projectName)/Sources")
fileManager.removeItems(in: "tuist/Interfaces")
}
}
Loading

0 comments on commit afedd78

Please sign in to comment.