From b3c12ef4d232d9746d4e443046dd167e80480600 Mon Sep 17 00:00:00 2001 From: Kabir Oberai Date: Mon, 12 May 2025 16:33:57 +0530 Subject: [PATCH] Add build --ipa (#24) --- .../Integration/IntegratedInstaller.swift | 4 +- Sources/XToolSupport/DevCommand.swift | 37 ++++++++++++++++++- .../XToolSupport/ProcessZIPCompressor.swift | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Sources/XKit/Integration/IntegratedInstaller.swift b/Sources/XKit/Integration/IntegratedInstaller.swift index 1a99826c..2555295a 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) diff --git a/Sources/XToolSupport/DevCommand.swift b/Sources/XToolSupport/DevCommand.swift index 221c396d..17c85c1e 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)") } } diff --git a/Sources/XToolSupport/ProcessZIPCompressor.swift b/Sources/XToolSupport/ProcessZIPCompressor.swift index ecbe7072..0a685030 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