Skip to content

Commit c7e47f7

Browse files
author
Artem Novichkov
committed
Merge branch 'static-frameworks'
2 parents be2306b + 4cf63ad commit c7e47f7

12 files changed

+235
-49
lines changed

.github/carting.gif

-5.45 MB
Binary file not shown.

.github/carting.png

79.4 KB
Loading

Makefile

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
{
22
"object": {
33
"pins": [
4-
4+
{
5+
"package": "Files",
6+
"repositoryURL": "https://github.com/johnsundell/files.git",
7+
"state": {
8+
"branch": null,
9+
"revision": "6171f9e9d8619678da22355560f3dbed6368058d",
10+
"version": "2.0.1"
11+
}
12+
},
13+
{
14+
"package": "ShellOut",
15+
"repositoryURL": "https://github.com/Johnsundell/shellout.git",
16+
"state": {
17+
"branch": null,
18+
"revision": "479a89d9bfa7585496bd4a3e4faffac5b01af37f",
19+
"version": "2.0.0"
20+
}
21+
}
522
]
623
},
724
"version": 1

Package.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ let package = Package(
77
products: [
88
.library(name: "Carting", targets: ["CartingCore"]),
99
],
10+
dependencies: [
11+
.package(url: "https://github.com/johnsundell/files.git", from: "2.0.0"),
12+
.package(url: "https://github.com/Johnsundell/shellout.git", from: "2.0.0")
13+
],
1014
targets: [
1115
.target(name: "Carting", dependencies: ["CartingCore"]),
12-
.target(name: "CartingCore")
16+
.target(name: "CartingCore", dependencies: ["Files", "ShellOut"])
1317
]
1418
)

README.md

+18-13
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,38 @@
1717
Do you use [Carthage](https://github.com/Carthage/Carthage)? Are you feel tired of adding special script and the paths to frameworks (point 4, 5 and 6 in [Getting Started guide](https://github.com/Carthage/Carthage#getting-started)) manually? Me too. Carting does it for you. It scans Carthage folder and linked frameworks, gets framework names and updates the script.
1818

1919
<p align="center">
20-
<img src=".github/carting.gif" max-width="90%" alt="Carting usage" />
20+
<img src=".github/carting.png" max-width="90%" alt="Carting usage" />
2121
</p>
2222

2323
## Using
2424

25-
Run `carting` in project folder. That's all.
25+
Run `carting update` in project folder. That's all.
2626

2727
By default Carting searches a script named `Carthage`, but you can set a name of your script via command line arguments:
2828

2929
```
30-
$ carting MyBestScript
30+
$ carting update -s MyBestScript
3131
```
3232

3333
If there is no script with the name, Carting will add a new one.
3434

3535
**🚨Note**: be sure to have no uncommitted changes in project file to prevent project parsing errors 😱.
3636
<img src="error.png" alt="Project parsing error" />
3737

38+
Run `carting help` to see available commands:
39+
40+
```bash
41+
Usage: carting [command] [options]
42+
update:
43+
Adds a new script with input/output file paths or updates the script named `Carthage`.
44+
-s, --script:
45+
Updates input/output file paths for the script with passed name.
46+
list:
47+
Prints Carthage frameworks list with linking description.
48+
help:
49+
Prints this message.
50+
```
51+
3852
## Installing
3953

4054
### Homebrew (recommended):
@@ -54,18 +68,9 @@ $ make
5468
### Swift Package Manager:
5569

5670
```swift
57-
// swift-tools-version:4.0
58-
59-
import PackageDescription
60-
6171
let package = Package(
62-
name: "Project",
6372
dependencies: [
64-
.package(url: "https://github.com/artemnovichkov/Carting.git", from: "1.0.0"),
65-
],
66-
targets: [
67-
.target(
68-
name: "Project", dependencies: ["Carting"])
73+
.Package(url: "https://github.com/artemnovichkov/carting", majorVersion: 1)
6974
]
7075
)
7176
```

Sources/CartingCore/Arguments.swift

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Copyright © 2017 Rosberry. All rights reserved.
3+
//
4+
5+
import Foundation
6+
7+
struct Arguments {
8+
9+
enum Command {
10+
case script(name: String), list, help
11+
}
12+
13+
private enum Keys {
14+
static let defaultScriptName = "Carthage"
15+
}
16+
17+
var command: Command = .help
18+
19+
init?(arguments: [String]) {
20+
for (index, argument) in arguments.enumerated() {
21+
switch argument.lowercased() {
22+
case "update":
23+
command = .script(name: Keys.defaultScriptName)
24+
case "-s", "--script":
25+
let nameIndex = index + 1
26+
let name = arguments.count > nameIndex ? arguments[nameIndex] : Keys.defaultScriptName
27+
command = .script(name: name)
28+
case "list":
29+
command = .list
30+
case "help":
31+
command = .help
32+
default: break
33+
}
34+
}
35+
}
36+
37+
static let description: String = {
38+
return """
39+
Usage: carting [command] [options]
40+
update:
41+
Adds a new script with input/output file paths or updates the script named `Carthage`.
42+
-s, --script:
43+
Updates input/output file paths for the script with passed name.
44+
list:
45+
Prints Carthage frameworks list with linking description.
46+
help:
47+
Prints this message.
48+
"""
49+
}()
50+
}

Sources/CartingCore/Carting.swift

+45-29
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,66 @@
55
import Foundation
66

77
public final class Carting {
8-
8+
99
enum Keys {
10-
static let defaultScriptName = "Carthage"
1110
static let carthageScript = "\"/usr/local/bin/carthage copy-frameworks\""
1211
}
13-
12+
1413
private let arguments: [String]
15-
14+
1615
private let projectService = ProjectService()
17-
16+
private let frameworkInformationService = FrameworkInformationService()
17+
1818
public init(arguments: [String] = CommandLine.arguments) {
1919
self.arguments = arguments
2020
}
21-
21+
2222
public func run() throws {
23+
guard let arguments = Arguments(arguments: self.arguments) else {
24+
print("❌ Wrong arguments")
25+
print(Arguments.description)
26+
return
27+
}
28+
29+
switch arguments.command {
30+
case .help:
31+
print(Arguments.description)
32+
case let .script(name: name):
33+
try updateScript(withName: name)
34+
case .list:
35+
frameworkInformationService.printFrameworksInformation()
36+
}
37+
}
38+
39+
private func updateScript(withName scriptName: String) throws {
2340
let project = try projectService.project()
24-
25-
let carthageScriptName = arguments.count > 1 ? arguments[1] : Keys.defaultScriptName
26-
41+
2742
var projectHasBeenUpdated = false
28-
43+
2944
try project.targets.forEach { target in
3045
let frameworkBuildPhase = target.body.buildPhases.first { $0.name == "Frameworks" }
3146
let frameworkScript = project.frameworkScripts.first { $0.identifier == frameworkBuildPhase?.identifier }
3247
guard let script = frameworkScript else {
3348
return
3449
}
35-
let carthageFrameworkNames = try projectService.frameworkNames()
36-
let linkedCarthageFrameworkNames = script.body.files
37-
.filter { carthageFrameworkNames.contains($0.name) }
50+
let linkedCarthageDynamicFrameworkNames = try frameworkInformationService.frameworksInformation()
51+
.filter { information in
52+
information.linking == .dynamic && script.body.files.contains { $0.name == information.name }
53+
}
3854
.map { $0.name }
39-
40-
let carthageBuildPhase = target.body.buildPhases.first { $0.name == carthageScriptName }
55+
56+
let carthageBuildPhase = target.body.buildPhases.first { $0.name == scriptName }
4157
let carthageScript = project.scripts.first { $0.identifier == carthageBuildPhase?.identifier }
42-
43-
let inputPathsString = projectService.pathsString(forFrameworkNames: linkedCarthageFrameworkNames,
58+
59+
let inputPathsString = projectService.pathsString(forFrameworkNames: linkedCarthageDynamicFrameworkNames,
4460
type: .input)
45-
let outputPathsString = projectService.pathsString(forFrameworkNames: linkedCarthageFrameworkNames,
61+
let outputPathsString = projectService.pathsString(forFrameworkNames: linkedCarthageDynamicFrameworkNames,
4662
type: .output)
47-
63+
4864
if let carthage = carthageScript {
4965
var scriptHasBeenUpdated = false
5066
if carthage.body.inputPaths != inputPathsString {
51-
carthage.body.inputPaths = inputPathsString
67+
carthage.body.inputPaths = inputPathsString
5268
scriptHasBeenUpdated = true
5369
}
5470
if carthage.body.outputPaths != outputPathsString {
@@ -61,25 +77,25 @@ public final class Carting {
6177
}
6278
if scriptHasBeenUpdated {
6379
projectHasBeenUpdated = true
64-
print("✅ Script \"\(carthageScriptName)\" in target \"\(target.name)\" was successfully updated.")
80+
print("✅ Script \"\(scriptName)\" in target \"\(target.name)\" was successfully updated.")
6581
}
6682
}
67-
else if linkedCarthageFrameworkNames.count > 0 {
83+
else if linkedCarthageDynamicFrameworkNames.count > 0 {
6884
let body = ScriptBody(inputPaths: inputPathsString,
69-
name: carthageScriptName,
85+
name: scriptName,
7086
outputPaths: outputPathsString,
7187
shellScript: Keys.carthageScript)
72-
88+
7389
let identifier = String.randomAlphaNumericString(length: 24)
74-
let script = Script(identifier: identifier, name: carthageScriptName, body: body)
75-
let buildPhase = BuildPhase(identifier: identifier, name: carthageScriptName)
90+
let script = Script(identifier: identifier, name: scriptName, body: body)
91+
let buildPhase = BuildPhase(identifier: identifier, name: scriptName)
7692
project.scripts.append(script)
7793
target.body.buildPhases.append(buildPhase)
78-
print("✅ Script \(carthageScriptName) was successfully added to \(target.name) target.")
94+
print("✅ Script \(scriptName) was successfully added to \(target.name) target.")
7995
projectHasBeenUpdated = true
8096
}
8197
}
82-
98+
8399
try projectService.update(project)
84100
if !projectHasBeenUpdated {
85101
print("🤷‍♂️ Nothing to update.")
@@ -92,7 +108,7 @@ enum MainError: Swift.Error {
92108
}
93109

94110
extension MainError: LocalizedError {
95-
111+
96112
var errorDescription: String? {
97113
switch self {
98114
case .noScript(name: let name): return "Can't find script with name \(name)"

Sources/CartingCore/Extensioins/StringExtensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extension String {
88

99
static func randomAlphaNumericString(length: Int) -> String {
1010
let allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
11-
let allowedCharsCount = UInt32(allowedChars.characters.count)
11+
let allowedCharsCount = UInt32(allowedChars.count)
1212
var randomString = ""
1313

1414
for _ in 0..<length {

Sources/CartingCore/Models/ScriptBody.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class ScriptBody: BaseScriptBody {
4545
runOnlyForDeploymentPostprocessing: String = "0",
4646
shellPath: String = "/bin/sh",
4747
shellScript: String = "\"\"",
48-
showEnvVarsInLog: String? = nil) {
48+
showEnvVarsInLog: String? = "0") {
4949
self.inputPaths = inputPaths
5050
self.name = name
5151
self.outputPaths = outputPaths

0 commit comments

Comments
 (0)