-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #504 from nimblehq/chore/494-make-sh-swift-command
[#494] Migrate make.sh to Swift command
- Loading branch information
Showing
7 changed files
with
336 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
extension String { | ||
|
||
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) | ||
return regex.firstMatch(in: lhs, options: [], range: range) != nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
#!/usr/bin/swift | ||
|
||
import Foundation | ||
|
||
let fileManager = FileManager.default | ||
|
||
enum CICDService { | ||
case github, bitrise, codemagic, later | ||
|
||
init?(_ name: String) { | ||
switch name.lowercased() { | ||
case "g", "github": | ||
self = .github | ||
case "b", "bitrise": | ||
self = .bitrise | ||
case "c", "codemagic": | ||
self = .codemagic | ||
case "l", "later": | ||
self = .later | ||
default: | ||
return nil | ||
struct SetUpCICDService { | ||
|
||
enum CICDService { | ||
|
||
case github, bitrise, codemagic, later | ||
|
||
init?(_ name: String) { | ||
switch name.lowercased() { | ||
case "g", "github": | ||
self = .github | ||
case "b", "bitrise": | ||
self = .bitrise | ||
case "c", "codemagic": | ||
self = .codemagic | ||
case "l", "later": | ||
self = .later | ||
default: | ||
return nil | ||
} | ||
} | ||
} | ||
} | ||
|
||
var service: CICDService? = nil | ||
private let fileManager = FileManager.default | ||
|
||
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() ?? "") | ||
} | ||
func perform() { | ||
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() ?? "") | ||
} | ||
|
||
switch service { | ||
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, .none: | ||
print("You can manually setup the template later.") | ||
} | ||
switch service { | ||
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, .none: | ||
print("You can manually setup the template later.") | ||
} | ||
|
||
print("✅ Completed") | ||
print("✅ Completed") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
#!/usr/bin/swift | ||
struct SetUpDeliveryConstants { | ||
|
||
import Foundation | ||
func perform() { | ||
print("Do you want to set up Constants values? (Can be edited later) [Y/n]: ") | ||
|
||
let fileManager = FileManager.default | ||
let arg = readLine() ?? "y" | ||
|
||
print("Do you want to set up Constants values? (Can be edited later) [Y/n]: ") | ||
|
||
var arg = readLine() ?? "y" | ||
|
||
switch arg.lowercased() { | ||
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'.") | ||
switch arg.lowercased() { | ||
case "y", "yes": | ||
do { | ||
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)") | ||
} catch { | ||
print("Error: \(error)") | ||
} | ||
default: | ||
print("✅ Completed. You can edit this file at 'fastlane/Constants/Constant.swift'.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,46 @@ | ||
#!/usr/bin/swift | ||
|
||
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" | ||
} | ||
struct SetUpInterface { | ||
|
||
enum Interface { | ||
|
||
case swiftUI, uiKit | ||
|
||
init?(_ name: String) { | ||
switch name.lowercased() { | ||
case "s", "swiftui": | ||
self = .swiftUI | ||
case "u", "uikit": | ||
self = .uiKit | ||
default: return nil | ||
} | ||
} | ||
|
||
var folderName: String { | ||
switch self { | ||
case .swiftUI: return "SwiftUI" | ||
case .uiKit: return "UIKit" | ||
} | ||
} | ||
} | ||
|
||
fileManager.moveFiles(in: "tuist/Interfaces/\(interface)/Project", to: "") | ||
fileManager.moveFiles(in: "tuist/Interfaces/\(interface)/Sources", to: "{PROJECT_NAME}/Sources") | ||
fileManager.removeItems(in: "tuist/Interfaces") | ||
private let fileManager = FileManager.default | ||
|
||
func perform(_ interface: Interface, _ projectName: String) { | ||
switch interface { | ||
case .swiftUI: | ||
print("=> 🦅 Setting up SwiftUI") | ||
let swiftUIAppDirectory = "tuist/Interfaces/SwiftUI/Sources/Application" | ||
fileManager.rename( | ||
file: "\(swiftUIAppDirectory)/App.swift", | ||
to: "\(swiftUIAppDirectory)/\(projectName)App.swift" | ||
) | ||
case .uiKit: | ||
print("=> 🦉 Setting up UIKit") | ||
} | ||
|
||
let folderName = interface.folderName | ||
|
||
fileManager.moveFiles(in: "tuist/Interfaces/\(folderName)/Project", to: "") | ||
fileManager.moveFiles(in: "tuist/Interfaces/\(folderName)/Sources", to: "TemplateApp/Sources") | ||
fileManager.removeItems(in: "tuist/Interfaces") | ||
} | ||
} |
Oops, something went wrong.