mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-20 10:16:39 +03:00
Add build --ipa (#24)
This commit is contained in:
committed by
GitHub
Unverified
parent
0ab48ac44f
commit
b3c12ef4d2
@@ -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)
|
||||
|
||||
@@ -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)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user