Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path parameter to IPASizeProvider #74

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Sources/SwiftInfoCore/Providers/IPASizeProvider.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import Foundation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

***eezy12
login

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

/// 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"
Expand All @@ -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)")
Expand Down
8 changes: 8 additions & 0 deletions Tests/SwiftInfoTests/ProviderTests/ProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down