Skip to content

Commit

Permalink
📦 Declare mas as a Swift Package
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-araman committed Apr 27, 2021
1 parent d287c5c commit 7a7f36a
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
.VolumeIcon.icns
._*
.apdisk
.build/
.envrc
.fseventsd
.rubygems/
.swiftpm/
Carthage/
DerivedData
Pods/
Expand Down
61 changes: 61 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"object": {
"pins": [
{
"package": "Commandant",
"repositoryURL": "https://github.com/Carthage/Commandant.git",
"state": {
"branch": null,
"revision": "a1671cf728db837cf5ec1980a80d276bbba748f6",
"version": "0.18.0"
}
},
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "f809deb30dc5c9d9b78c872e553261a61177721a",
"version": "2.0.0"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "02b7a39a99c4da27abe03cab2053a9034379639f",
"version": "2.0.0"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "7a54aaf19a8ef16f67787c260fda81ead7ba4d67",
"version": "9.0.1"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "8cce6acd38f965f5baa3167b939f86500314022b",
"version": "3.1.2"
}
},
{
"package": "Version",
"repositoryURL": "https://github.com/mxcl/Version.git",
"state": {
"branch": null,
"revision": "a94b48f36763c05629fc102837398505032dead9",
"version": "2.0.0"
}
}
]
},
"version": 1
}
73 changes: 73 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "mas",
platforms: [
.macOS(.v10_11),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.executable(
name: "mas",
targets: ["mas"]
),
.library(
name: "MasKit",
targets: ["MasKit"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.18.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "9.0.1"),
.package(url: "https://github.com/Quick/Quick.git", from: "3.1.2"),
.package(url: "https://github.com/mxcl/Version.git", from: "2.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "mas",
dependencies: ["MasKit"],
swiftSettings: [
.unsafeFlags([
"-F", "/System/Library/PrivateFrameworks",
"-I", "Sources/PrivateFrameworks/CommerceKit",
"-I", "Sources/PrivateFrameworks/StoreFoundation",
]),
]
),
.target(
name: "MasKit",
dependencies: ["Commandant", "Version"],
swiftSettings: [
.unsafeFlags([
"-F", "/System/Library/PrivateFrameworks",
"-I", "Sources/PrivateFrameworks/CommerceKit",
"-I", "Sources/PrivateFrameworks/StoreFoundation",
]),
],
linkerSettings: [
.linkedFramework("CommerceKit"),
.linkedFramework("StoreFoundation"),
.unsafeFlags(["-F", "/System/Library/PrivateFrameworks"]),
]
),
.testTarget(
name: "MasKitTests",
dependencies: ["MasKit", "Nimble", "Quick"],
resources: [.copy("JSON")],
swiftSettings: [
.unsafeFlags([
"-F", "/System/Library/PrivateFrameworks",
"-I", "Sources/PrivateFrameworks/CommerceKit",
"-I", "Sources/PrivateFrameworks/StoreFoundation",
]),
]
),
],
swiftLanguageVersions: [.v5]
)
1 change: 1 addition & 0 deletions Sources/MasKit/Commands/Open.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Commandant
import Foundation

private let markerValue = "appstore"
private let masScheme = "macappstore"
Expand Down
1 change: 1 addition & 0 deletions Sources/MasKit/Commands/Outdated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Commandant
import Foundation

/// Command which displays a list of installed apps which have available updates
/// ready to be installed from the Mac App Store.
Expand Down
1 change: 1 addition & 0 deletions Sources/MasKit/Commands/Upgrade.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Commandant
import Foundation

/// Command which upgrades apps with new versions available in the Mac App Store.
public struct UpgradeCommand: CommandProtocol {
Expand Down
1 change: 1 addition & 0 deletions Sources/MasKit/Commands/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Commandant
import Foundation

/// Command which displays the version of the mas tool.
public struct VersionCommand: CommandProtocol {
Expand Down
1 change: 1 addition & 0 deletions Tests/MasKitTests/Commands/OpenCommandSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2019 mas-cli. All rights reserved.
//

import Foundation
import Nimble
import Quick

Expand Down
1 change: 1 addition & 0 deletions Tests/MasKitTests/Commands/UninstallCommandSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2018 mas-cli. All rights reserved.
//

import Foundation
import Nimble
import Quick

Expand Down
16 changes: 11 additions & 5 deletions Tests/MasKitTests/Extensions/Bundle+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ extension Bundle {
/// - Parameter fileName: Name of file to locate.
/// - Returns: URL to file.
static func url(for fileName: String) -> URL? {
Bundle(for: NetworkSessionMock.self).url(for: fileName)
var bundle = Bundle(for: NetworkSessionMock.self)
#if SWIFT_PACKAGE
// The Swift Package Manager places resources in a separate bundle from the executable.
bundle =
Bundle(url: bundle.bundleURL.deletingLastPathComponent().appendingPathComponent("mas_MasKitTests.bundle"))!
#endif
return bundle.url(for: fileName)
}

/// Builds a URL for a file in the JSON directory of the current bundle.
Expand All @@ -33,13 +39,13 @@ extension Bundle {
/// - Returns: URL to file.
func url(for fileName: String) -> URL? {
guard
let path = self.path(
let url = self.url(
forResource: fileName.fileNameWithoutExtension,
ofType: fileName.fileExtension,
inDirectory: "JSON"
withExtension: fileName.fileExtension,
subdirectory: "JSON"
)
else { fatalError("Unable to load file \(fileName)") }

return URL(fileURLWithPath: path)
return url
}
}
1 change: 1 addition & 0 deletions Tests/MasKitTests/Models/SearchResultListSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2020 mas-cli. All rights reserved.
//

import Foundation
import Nimble
import Quick

Expand Down
1 change: 1 addition & 0 deletions Tests/MasKitTests/Models/SearchResultSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2020 mas-cli. All rights reserved.
//

import Foundation
import Nimble
import Quick

Expand Down
1 change: 1 addition & 0 deletions Tests/MasKitTests/Network/NetworkSessionMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation

@testable import MasKit

/// Mock NetworkSession for testing.
Expand Down
2 changes: 2 additions & 0 deletions mas-cli.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
B5DBF81221DEEC7C00F3B151 /* OpenCommandSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenCommandSpec.swift; sourceTree = "<group>"; };
B5DBF81421E02BA900F3B151 /* StoreSearchMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreSearchMock.swift; sourceTree = "<group>"; };
B5DBF81621E02E3400F3B151 /* OpenSystemCommandMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenSystemCommandMock.swift; sourceTree = "<group>"; };
C56F16DF2637825300EAC548 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
ED031A781B5127C00097692E /* mas */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = mas; sourceTree = BUILT_PRODUCTS_DIR; };
ED031A7B1B5127C00097692E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
ED0F237E1B87522400AE40CD /* Install.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Install.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -543,6 +544,7 @@
C56F16DB2637711100EAC548 /* Sources */,
C56F16DC2637711900EAC548 /* Tests */,
ED031A791B5127C00097692E /* Products */,
C56F16DF2637825300EAC548 /* Package.swift */,
);
sourceTree = "<group>";
};
Expand Down
2 changes: 1 addition & 1 deletion script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ git diff --check

echo
echo "--> 🕊️ Swift"
for SOURCE in Sources Tests; do
for SOURCE in Package.swift Sources Tests; do
swiftformat --lint ${SOURCE}
swift-format lint --configuration .swift-format --recursive ${SOURCE}
swiftlint lint --strict ${SOURCE}
Expand Down

0 comments on commit 7a7f36a

Please sign in to comment.