diff --git a/Sources/SwiftInfoCore/Providers/IPASizeProvider.swift b/Sources/SwiftInfoCore/Providers/IPASizeProvider.swift index 3a68d69..56b7224 100644 --- a/Sources/SwiftInfoCore/Providers/IPASizeProvider.swift +++ b/Sources/SwiftInfoCore/Providers/IPASizeProvider.swift @@ -1,9 +1,16 @@ import Foundation /// Size of the .ipa archive (not the App Store size!). -/// Requirements: .ipa available in the `#{PROJECT_DIR}/build` folder. +/// Requirements: .ipa available in the `#{PROJECT_DIR}/build` folder (or in another `PROJECT_DIR` subfolder provided as the `path` argument). public struct IPASizeProvider: InfoProvider { - public struct Args {} + public struct Args { + /// The path to the folder containing the .ipa file. + public let path: String + + public init(path: String) { + self.path = path + } + } public typealias Arguments = Args public static let identifier: String = "ipa_size" @@ -15,10 +22,10 @@ public struct IPASizeProvider: InfoProvider { self.size = size } - public static func extract(fromApi api: SwiftInfo, args _: Args?) throws -> IPASizeProvider { + public static func extract(fromApi api: SwiftInfo, args: Args?) throws -> IPASizeProvider { let fileUtils = api.fileUtils let infofileFolder = try fileUtils.infofileFolder() - let buildFolder = infofileFolder + "build/" + let buildFolder = infofileFolder + (args?.path ?? "build/") let contents = try fileUtils.fileManager.contentsOfDirectory(atPath: buildFolder) guard let ipa = contents.first(where: { $0.hasSuffix(".ipa") }) else { throw error(".ipa not found! Attempted to find .ipa at: \(buildFolder)") diff --git a/Tests/SwiftInfoTests/ProviderTests/ProviderTests.swift b/Tests/SwiftInfoTests/ProviderTests/ProviderTests.swift index 8a227f5..8189f64 100644 --- a/Tests/SwiftInfoTests/ProviderTests/ProviderTests.swift +++ b/Tests/SwiftInfoTests/ProviderTests/ProviderTests.swift @@ -46,6 +46,14 @@ final class ProviderTests: XCTestCase { XCTAssertEqual(extracted.size, 5000) } + func testIPASizeWithCustomPath() { + let path = "./custom/path/App.ipa" + api.mockFileManager.add(file: path, contents: "") + api.mockFileManager.add(attributes: [.size: UInt64(5000)], file: path) + let extracted = try! IPASizeProvider.extract(fromApi: api, args: .init(path: "custom/path/")) + XCTAssertEqual(extracted.size, 5000) + } + func testWarningCount() { FileUtils.buildLogFilePath = "./build.log" let log =