Add build --ipa (#24)
- Commit
b3c12ef4d232d9746d4e443046dd167e80480600- Author
- Kabir Oberai <[email protected]>
- When
- 2025-05-12 11:03 UTC (1 year ago)
- Parents
0ab48ac
Diff
Sources/XKit/Integration/IntegratedInstaller.swift
diff --git a/Sources/XKit/Integration/IntegratedInstaller.swift b/Sources/XKit/Integration/IntegratedInstaller.swiftindex 1a99826..2555295 100644--- a/Sources/XKit/Integration/IntegratedInstaller.swift+++ b/Sources/XKit/Integration/IntegratedInstaller.swift@@ -55,7 +55,7 @@ public actor IntegratedInstaller { private var appInstaller: AppInstaller? private let tempDir = FileManager.default.temporaryDirectoryShim- .appendingPathComponent("com.kabiroberai.xtool.Staging")+ .appendingPathComponent("sh.xtool.Staging") private var stage: String? @@ -299,7 +299,7 @@ public actor IntegratedInstaller { try await self.updateStage(to: "Packaging", initialProgress: nil) let ipa = try await compressor.compress(- directory: appDir.deletingLastPathComponent(),+ directory: payload, progress: { progress in self.queueUpdateTask { $0.updateProgressIgnoringCancellation(to: progress)
Sources/XToolSupport/DevCommand.swift
diff --git a/Sources/XToolSupport/DevCommand.swift b/Sources/XToolSupport/DevCommand.swiftindex 221c396..17c85c1 100644--- a/Sources/XToolSupport/DevCommand.swift+++ b/Sources/XToolSupport/DevCommand.swift@@ -2,6 +2,7 @@ import Foundation import ArgumentParser import PackLib import XKit+import Dependencies struct PackOperation { struct BuildOptions: ParsableArguments {@@ -85,8 +86,42 @@ struct DevBuildCommand: AsyncParsableCommand { @OptionGroup var packOptions: PackOperation.BuildOptions + @Flag(+ help: "Output a .ipa file instead of a .app"+ ) var ipa = false+ func run() async throws {- try await PackOperation(buildOptions: packOptions).run()+ let url = try await PackOperation(+ buildOptions: packOptions+ ).run()++ let finalURL: URL+ if ipa {+ @Dependency(\.zipCompressor) var compressor+ finalURL = url.deletingPathExtension().appendingPathExtension("ipa")+ let tmpDir = try TemporaryDirectory(name: "sh.xtool.tmp")+ let payloadDir = tmpDir.url.appendingPathComponent("Payload", isDirectory: true)+ try FileManager.default.createDirectory(+ at: payloadDir,+ withIntermediateDirectories: true+ )+ try FileManager.default.moveItem(at: url, to: payloadDir.appendingPathComponent(url.lastPathComponent))+ let ipaURL = try await compressor.compress(directory: payloadDir) { progress in+ if let progress {+ let percent = Int(progress * 100)+ print("\rPackaging... \(percent)%", terminator: "")+ } else {+ print("\rPackaging...", terminator: "")+ }+ }+ print()+ try? FileManager.default.removeItem(at: finalURL)+ try FileManager.default.moveItem(at: ipaURL, to: finalURL)+ } else {+ finalURL = url+ }++ print("Wrote to \(finalURL.path)") } }
Sources/XToolSupport/ProcessZIPCompressor.swift
diff --git a/Sources/XToolSupport/ProcessZIPCompressor.swift b/Sources/XToolSupport/ProcessZIPCompressor.swiftindex ecbe707..0a68503 100644--- a/Sources/XToolSupport/ProcessZIPCompressor.swift+++ b/Sources/XToolSupport/ProcessZIPCompressor.swift@@ -15,7 +15,7 @@ extension ZIPCompressor: DependencyKey { let zip = Process() zip.executableURL = try await ToolRegistry.locate("zip") zip.currentDirectoryURL = dir.deletingLastPathComponent()- zip.arguments = ["-yqru0", dest.path, "Payload"]+ zip.arguments = ["-yqru0", dest.path, dir.lastPathComponent] try await zip.runUntilExit() return dest