xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XToolSupport / ProcessZIPCompressor.swift
ProcessZIPCompressor.swift36 lines · 1.0 KiBRaw
| 1 | import Foundation |
| 2 | import XKit |
| 3 | import Dependencies |
| 4 | import PackLib |
| 5 | import Subprocess |
| 6 | import XUtils |
| 7 | |
| 8 | extension ZIPCompressor: DependencyKey { |
| 9 | // TODO: Use `powershell Compress-Archive` and `powershell Expand-Archive` on Windows |
| 10 | |
| 11 | public static let liveValue = ZIPCompressor( |
| 12 | compress: { dir, progress in |
| 13 | progress(nil) |
| 14 | |
| 15 | let dest = dir.deletingLastPathComponent().appendingPathComponent("app.ipa") |
| 16 | |
| 17 | try await Subprocess.run( |
| 18 | .name("zip"), |
| 19 | arguments: ["-yqru0", dest.path, dir.lastPathComponent], |
| 20 | workingDirectory: FilePath(dir.deletingLastPathComponent()), |
| 21 | output: .discarded, |
| 22 | ).checkSuccess() |
| 23 | |
| 24 | return dest |
| 25 | }, |
| 26 | decompress: { ipa, directory, progress in |
| 27 | progress(nil) |
| 28 | |
| 29 | try await Subprocess.run( |
| 30 | .name("unzip"), |
| 31 | arguments: ["-q", ipa.path, "-d", directory.path], |
| 32 | output: .discarded, |
| 33 | ).checkSuccess() |
| 34 | } |
| 35 | ) |
| 36 | } |