Skip to content

Instantly share code, notes, and snippets.

@HarshilShah
Created July 10, 2023 17:15
Show Gist options
  • Save HarshilShah/dd3a87b0227a21eee9830e6af441bac5 to your computer and use it in GitHub Desktop.
Save HarshilShah/dd3a87b0227a21eee9830e6af441bac5 to your computer and use it in GitHub Desktop.
import SwiftUI
enum MarketingBump: String, CaseIterable, Hashable {
case none
case patch
case minor
case major
}
enum ASCGroup: String, CaseIterable, Hashable {
/// Insert your groups here
}
func formatForZshParameter(_ string: String) -> String {
let escapedString = string.replacingOccurrences(of: "'", with: "'\\''")
return "'\(escapedString)'"
}
struct ContentView: View {
@State private var buildNumberBumps = true
@State private var marketingBump = MarketingBump.none
@State private var changelog = ""
var isSubmitButtonEnabled: Bool {
changelog.isEmpty == false
}
var buildScript: String {
"""
fastlane beta should_increment_build:\(buildNumberBumps) marketing_version_bump:\(marketingBump.rawValue) changelog:\(formatForZshParameter(changelog)) groups:\(groups.map({ "\\\"" + $0.rawValue + "\\\"" }).joined(separator: ","))
"""
}
var script: String {
"""
tell application "Terminal"
activate
if not (exists window 1) then reopen
do script ("cd /Users/harshil/developer/Peak") in window 1
do script ("\(buildScript)") in window 1
end tell
"""
}
@State private var groups = Set(ASCGroup.allCases)
var body: some View {
Form {
Section {
Toggle(isOn: $buildNumberBumps.animation()) {
VStack(alignment: .leading) {
Text("Bump the build number?")
}
}
.toggleStyle(.switch)
Picker(
"Marketing version update",
selection: $marketingBump.animation()
) {
ForEach(MarketingBump.allCases, id: \.self) { bump in
Text(bump.rawValue.capitalized)
.tag(bump)
}
}
.pickerStyle(.menu)
VStack(alignment: .leading) {
Text("Changelog")
GroupBox {
ZStack {
if changelog.isEmpty {
TextEditor(text: .constant("Add some text here…"))
.foregroundStyle(.secondary)
}
TextEditor(text: $changelog)
}
.font(.body)
.labelsHidden()
.scrollDisabled(false)
.scrollContentBackground(.hidden)
.frame(height: 220)
.padding(.horizontal, 4)
.padding(.vertical, 8)
}
}
}
Section {
ForEach(ASCGroup.allCases, id: \.self) { group in
Toggle(
group.rawValue,
isOn: Binding(
get: { groups.contains(group) },
set: { isSelected in
if isSelected {
groups.insert(group)
} else {
groups.remove(group)
}
}
)
)
}
} header: {
HStack {
Text("Groups")
Spacer()
Button("Select All") {
groups = Set(ASCGroup.allCases)
}
.fontWeight(.regular)
.opacity(groups.count == ASCGroup.allCases.count ? 0 : 1)
}
}
HStack {
Spacer()
Button("Build") {
DispatchQueue.global(qos: .userInteractive).async {
let appleScript = NSAppleScript(source: script)!
var error: NSDictionary?
appleScript.executeAndReturnError(&error)
if let error {
print("Error", error)
} else {
print("No errors in execution")
}
}
}
.buttonStyle(.borderedProminent)
.disabled(!isSubmitButtonEnabled)
}
}
.formStyle(.grouped)
.frame(width: 420)
.fixedSize()
.scrollDisabled(true)
.navigationTitle("Peak Builder")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment