@@ -2,6 +2,7 @@ import Foundation
22import ArgumentParser
33import PackLib
44import XKit
5+ import Dependencies
56
67struct 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 ( " \r Packaging... \( percent) % " , terminator: " " )
113+ } else {
114+ print ( " \r Packaging... " , 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
0 commit comments