Skip to content

Commit 0fdb475

Browse files
committed
reformatted
1 parent 4e5a73e commit 0fdb475

9 files changed

Lines changed: 262 additions & 262 deletions

File tree

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
import Foundation
22

33
struct ArchiveExtractor {
4-
let executor: ShellExecutor
5-
let logger: Logger
6-
7-
/// Extract a zip archive to the specified directory
8-
func extractZip(_ archivePath: URL, to destinationDir: URL) async throws {
9-
logger.log("Extracting zip: \(archivePath.path) to \(destinationDir.path)", level: 1)
10-
11-
let result = try await executor.run([
12-
"/usr/bin/unzip",
13-
"-q",
14-
archivePath.path,
15-
"-d", destinationDir.path
16-
])
17-
18-
guard result.exitCode == 0 else {
19-
throw QuickPkgError.archiveExtractionFailed("unzip failed (\(result.exitCode)): \(result.stderr)")
20-
}
4+
let executor: ShellExecutor
5+
let logger: Logger
6+
7+
/// Extract a zip archive to the specified directory
8+
func extractZip(_ archivePath: URL, to destinationDir: URL) async throws {
9+
logger.log("Extracting zip: \(archivePath.path) to \(destinationDir.path)", level: 1)
10+
11+
let result = try await executor.run([
12+
"/usr/bin/unzip",
13+
"-q",
14+
archivePath.path,
15+
"-d", destinationDir.path
16+
])
17+
18+
guard result.exitCode == 0 else {
19+
throw QuickPkgError.archiveExtractionFailed("unzip failed (\(result.exitCode)): \(result.stderr)")
2120
}
22-
23-
/// Extract a xip archive to the specified directory
24-
func extractXip(_ archivePath: URL, to destinationDir: URL) async throws {
25-
logger.log("Extracting xip: \(archivePath.path) to \(destinationDir.path)", level: 1)
26-
27-
// xip --expand extracts to the current directory, so we need to run it from the destination
28-
let result = try await executor.run(
29-
["/usr/bin/xip", "--expand", archivePath.path],
30-
workingDirectory: destinationDir
31-
)
32-
33-
guard result.exitCode == 0 else {
34-
throw QuickPkgError.archiveExtractionFailed("xip failed (\(result.exitCode)): \(result.stderr)")
35-
}
21+
}
22+
23+
/// Extract a xip archive to the specified directory
24+
func extractXip(_ archivePath: URL, to destinationDir: URL) async throws {
25+
logger.log("Extracting xip: \(archivePath.path) to \(destinationDir.path)", level: 1)
26+
27+
// xip --expand extracts to the current directory, so we need to run it from the destination
28+
let result = try await executor.run(
29+
["/usr/bin/xip", "--expand", archivePath.path],
30+
workingDirectory: destinationDir
31+
)
32+
33+
guard result.exitCode == 0 else {
34+
throw QuickPkgError.archiveExtractionFailed("xip failed (\(result.exitCode)): \(result.stderr)")
3635
}
36+
}
3737
}

Sources/quickpkg/InputType.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import ArgumentParser
22
import Foundation
33

44
enum InputType: String, CaseIterable {
5-
case app
6-
case dmg
7-
case zip
8-
case xip
9-
10-
static func from(path: String) -> InputType? {
11-
let ext = URL(filePath: path).pathExtension.lowercased()
12-
return InputType(rawValue: ext)
13-
}
5+
case app
6+
case dmg
7+
case zip
8+
case xip
9+
10+
static func from(path: String) -> InputType? {
11+
let ext = URL(filePath: path).pathExtension.lowercased()
12+
return InputType(rawValue: ext)
13+
}
1414
}
1515

1616
enum Ownership: String, ExpressibleByArgument, CaseIterable {
17-
case recommended
18-
case preserve
19-
case preserveOther = "preserve-other"
17+
case recommended
18+
case preserve
19+
case preserveOther = "preserve-other"
2020
}

Sources/quickpkg/Logger.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Foundation
22

33
struct Logger: Sendable {
4-
let verbosity: Int
5-
6-
func log(_ message: String, level: Int = 0) {
7-
if verbosity >= level {
8-
print(message)
9-
}
4+
let verbosity: Int
5+
6+
func log(_ message: String, level: Int = 0) {
7+
if verbosity >= level {
8+
print(message)
109
}
10+
}
1111
}
Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,101 @@
11
import Foundation
22

33
struct PackageBuilder {
4-
let executor: ShellExecutor
5-
let logger: Logger
6-
7-
/// Analyze the payload and create a component plist
8-
func analyze(
9-
payloadDir: URL,
10-
identifier: String,
11-
version: String,
12-
installLocation: String,
13-
outputPlist: URL
14-
) async throws {
15-
let arguments = [
16-
"/usr/bin/pkgbuild",
17-
"--analyze",
18-
"--root", payloadDir.path,
19-
"--identifier", identifier,
20-
"--version", version,
21-
"--install-location", installLocation,
22-
outputPlist.path
23-
]
24-
25-
let result = try await executor.runOrThrow(arguments)
26-
logger.log(result.stdout, level: 1)
4+
let executor: ShellExecutor
5+
let logger: Logger
6+
7+
/// Analyze the payload and create a component plist
8+
func analyze(
9+
payloadDir: URL,
10+
identifier: String,
11+
version: String,
12+
installLocation: String,
13+
outputPlist: URL
14+
) async throws {
15+
let arguments = [
16+
"/usr/bin/pkgbuild",
17+
"--analyze",
18+
"--root", payloadDir.path,
19+
"--identifier", identifier,
20+
"--version", version,
21+
"--install-location", installLocation,
22+
outputPlist.path
23+
]
24+
25+
let result = try await executor.runOrThrow(arguments)
26+
logger.log(result.stdout, level: 1)
27+
}
28+
29+
/// Build the package
30+
func build(
31+
payloadDir: URL,
32+
outputPath: String,
33+
identifier: String,
34+
version: String,
35+
installLocation: String,
36+
scripts: URL?,
37+
ownership: Ownership?,
38+
relocatable: Bool,
39+
sign: String?,
40+
keychain: String?,
41+
cert: String?,
42+
tempDir: URL
43+
) async throws {
44+
// First, create the component plist
45+
let componentPlist = tempDir.appendingPathComponent("\(identifier).plist")
46+
try await analyze(
47+
payloadDir: payloadDir,
48+
identifier: identifier,
49+
version: version,
50+
installLocation: installLocation,
51+
outputPlist: componentPlist
52+
)
53+
54+
// Modify relocatable setting if needed
55+
if !relocatable {
56+
try PlistHandler.setRelocatable(false, in: componentPlist)
2757
}
28-
29-
/// Build the package
30-
func build(
31-
payloadDir: URL,
32-
outputPath: String,
33-
identifier: String,
34-
version: String,
35-
installLocation: String,
36-
scripts: URL?,
37-
ownership: Ownership?,
38-
relocatable: Bool,
39-
sign: String?,
40-
keychain: String?,
41-
cert: String?,
42-
tempDir: URL
43-
) async throws {
44-
// First, create the component plist
45-
let componentPlist = tempDir.appendingPathComponent("\(identifier).plist")
46-
try await analyze(
47-
payloadDir: payloadDir,
48-
identifier: identifier,
49-
version: version,
50-
installLocation: installLocation,
51-
outputPlist: componentPlist
52-
)
53-
54-
// Modify relocatable setting if needed
55-
if !relocatable {
56-
try PlistHandler.setRelocatable(false, in: componentPlist)
57-
}
58-
59-
// Build the pkgbuild command
60-
var arguments = [
61-
"/usr/bin/pkgbuild",
62-
"--root", payloadDir.path,
63-
"--component-plist", componentPlist.path,
64-
"--identifier", identifier,
65-
"--version", version,
66-
"--install-location", installLocation
67-
]
68-
69-
if let scriptsDir = scripts {
70-
arguments += ["--scripts", scriptsDir.path]
71-
logger.log("Scripts path: \(scriptsDir.path)", level: 1)
72-
}
73-
74-
if let ownership = ownership {
75-
arguments += ["--ownership", ownership.rawValue]
76-
}
77-
78-
if let sign = sign {
79-
arguments += ["--sign", sign]
80-
}
81-
82-
if let keychain = keychain {
83-
arguments += ["--keychain", keychain]
84-
}
85-
86-
if let cert = cert {
87-
arguments += ["--cert", cert]
88-
}
89-
90-
arguments.append(outputPath)
91-
92-
logger.log("Building package: \(outputPath)", level: 1)
93-
let result = try await executor.run(arguments)
94-
95-
logger.log(result.stdout, level: 1)
96-
97-
if result.exitCode != 0 {
98-
throw QuickPkgError.pkgbuildFailed("(\(result.exitCode)) \(result.stderr)")
99-
}
58+
59+
// Build the pkgbuild command
60+
var arguments = [
61+
"/usr/bin/pkgbuild",
62+
"--root", payloadDir.path,
63+
"--component-plist", componentPlist.path,
64+
"--identifier", identifier,
65+
"--version", version,
66+
"--install-location", installLocation
67+
]
68+
69+
if let scriptsDir = scripts {
70+
arguments += ["--scripts", scriptsDir.path]
71+
logger.log("Scripts path: \(scriptsDir.path)", level: 1)
72+
}
73+
74+
if let ownership = ownership {
75+
arguments += ["--ownership", ownership.rawValue]
76+
}
77+
78+
if let sign = sign {
79+
arguments += ["--sign", sign]
80+
}
81+
82+
if let keychain = keychain {
83+
arguments += ["--keychain", keychain]
84+
}
85+
86+
if let cert = cert {
87+
arguments += ["--cert", cert]
88+
}
89+
90+
arguments.append(outputPath)
91+
92+
logger.log("Building package: \(outputPath)", level: 1)
93+
let result = try await executor.run(arguments)
94+
95+
logger.log(result.stdout, level: 1)
96+
97+
if result.exitCode != 0 {
98+
throw QuickPkgError.pkgbuildFailed("(\(result.exitCode)) \(result.stderr)")
10099
}
100+
}
101101
}

0 commit comments

Comments
 (0)