Skip to content

Commit 08016c1

Browse files
committed
Add build --ipa
1 parent b33a4ff commit 08016c1

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

Sources/XKit/Integration/IntegratedInstaller.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public actor IntegratedInstaller {
5555
private var appInstaller: AppInstaller?
5656

5757
private let tempDir = FileManager.default.temporaryDirectoryShim
58-
.appendingPathComponent("com.kabiroberai.xtool.Staging")
58+
.appendingPathComponent("sh.xtool.Staging")
5959

6060
private var stage: String?
6161

@@ -299,7 +299,7 @@ public actor IntegratedInstaller {
299299
try await self.updateStage(to: "Packaging", initialProgress: nil)
300300

301301
let ipa = try await compressor.compress(
302-
directory: appDir.deletingLastPathComponent(),
302+
directory: payload,
303303
progress: { progress in
304304
self.queueUpdateTask {
305305
$0.updateProgressIgnoringCancellation(to: progress)

Sources/XToolSupport/DevCommand.swift

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22
import ArgumentParser
33
import PackLib
44
import XKit
5+
import Dependencies
56

67
struct PackOperation {
78
struct BuildOptions: ParsableArguments {
@@ -85,8 +86,42 @@ struct DevBuildCommand: AsyncParsableCommand {
8586

8687
@OptionGroup var packOptions: PackOperation.BuildOptions
8788

89+
@Flag(
90+
help: "Output a .ipa file instead of a .app"
91+
) var ipa = false
92+
8893
func run() async throws {
89-
try await PackOperation(buildOptions: packOptions).run()
94+
let url = try await PackOperation(
95+
buildOptions: packOptions
96+
).run()
97+
98+
let finalURL: URL
99+
if ipa {
100+
@Dependency(\.zipCompressor) var compressor
101+
finalURL = url.deletingPathExtension().appendingPathExtension("ipa")
102+
let tmpDir = try TemporaryDirectory(name: "sh.xtool.tmp")
103+
let payloadDir = tmpDir.url.appendingPathComponent("Payload", isDirectory: true)
104+
try FileManager.default.createDirectory(
105+
at: payloadDir,
106+
withIntermediateDirectories: true
107+
)
108+
try FileManager.default.moveItem(at: url, to: payloadDir.appendingPathComponent(url.lastPathComponent))
109+
let ipaURL = try await compressor.compress(directory: payloadDir) { progress in
110+
if let progress {
111+
let percent = Int(progress * 100)
112+
print("\rPackaging... \(percent)%", terminator: "")
113+
} else {
114+
print("\rPackaging...", terminator: "")
115+
}
116+
}
117+
print()
118+
try? FileManager.default.removeItem(at: finalURL)
119+
try FileManager.default.moveItem(at: ipaURL, to: finalURL)
120+
} else {
121+
finalURL = url
122+
}
123+
124+
print("Wrote to \(finalURL.path)")
90125
}
91126
}
92127

Sources/XToolSupport/ProcessZIPCompressor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension ZIPCompressor: DependencyKey {
1515
let zip = Process()
1616
zip.executableURL = try await ToolRegistry.locate("zip")
1717
zip.currentDirectoryURL = dir.deletingLastPathComponent()
18-
zip.arguments = ["-yqru0", dest.path, "Payload"]
18+
zip.arguments = ["-yqru0", dest.path, dir.lastPathComponent]
1919
try await zip.runUntilExit()
2020

2121
return dest

0 commit comments

Comments
 (0)