Skip to content

Commit

Permalink
Merge pull request #51 from artemnovichkov/lint
Browse files Browse the repository at this point in the history
Lint
  • Loading branch information
artemnovichkov authored Jul 15, 2019
2 parents ca9e426 + 38d788f commit 00f6df1
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 76 deletions.
Binary file added .github/phase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $ carting update -s MyBestScript

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

Since Xcode 10 Run Script build phases support declaring input and output files in a `.xcfilelist` file. This file should contain a newline-separated list of the file paths for the inputs or outputs. Carting uses it by default. If you need to work with your projects in old Xcode versions, use `-f file` option.
Since Xcode 10 Run Script Phases support declaring input and output files in a `.xcfilelist` file. This file should contain a newline-separated list of the file paths for the inputs or outputs. Carting uses it by default. If you need to work with your projects in old Xcode versions, use `-f file` option.

**🚨Note**: be sure to have no uncommitted changes in project file to prevent project parsing errors 😱.

Expand All @@ -50,10 +50,23 @@ OVERVIEW: 🚘 Simple tool for updating Carthage script phase
USAGE: Carting <command> <options>

SUBCOMMANDS:
info Prints Carthage frameworks list with linking description.
update Adds a new script with input/output file paths or updates the script named `Carthage`.
info Prints Carthage frameworks list with linking description.
lint Lint the project for missing paths.
update Adds a new script with input/output file paths or updates the script named `Carthage`.
```

## Linting

Integrate Carting into an Xcode scheme to get errors displayed in the IDE. Just add a new "Run Script Phase" with:

```bash
/usr/local/bin/carting lint
```

<p align="center">
<img src=".github/phase.png" max-width="90%" alt="Run Script Phase" />
</p>

## Installing

### Homebrew (recommended):
Expand Down Expand Up @@ -86,20 +99,6 @@ let package = Package(
]
)
```
### Marathon

- Install [Marathon](https://github.com/johnsundell/marathon#installing).
- Add Carting to Marathon using `$ marathon add [email protected]:artemnovichkov/carting.git`. Alternatively, add `[email protected]:artemnovichkov/carting.git` to your `Marathonfile`.
- Write your script, then run it using `$ marathon run <path-to-your-script>`.

## Todo
- [x] Add option for adding new script
- [x] Add support of multiple targets
- [x] Add check of linked frameworks
- [x] Unify errors
- [x] Check correct work with workspaces
- [ ] Write tests

## Author

Artem Novichkov, [email protected]
Expand Down
49 changes: 49 additions & 0 deletions Sources/Carting/Commands/LintCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright © 2019 Artem Novichkov. All rights reserved.
//

import SPMUtility
import CartingCore
import Foundation

final class LintCommand: Command {

var command = "lint"
var overview = "Lint the project for missing paths."

private let name: OptionArgument<String>
private let projectPath: OptionArgument<String>
private let format: OptionArgument<Format>
private let targetName: OptionArgument<String>

private lazy var frameworkInformationService: FrameworkInformationService = .init()

required init(parser: ArgumentParser) {
let subparser = parser.add(subparser: command, overview: overview)
name = subparser.add(option: "--script",
shortName: "-s",
usage: "The name of Carthage script.")
projectPath = subparser.add(option: "--path",
shortName: "-p",
usage: "The project directory path.",
completion: .filename)
format = subparser.add(option: "--format",
shortName: "-f",
usage: "Format of input/output file paths: file - using simple paths, list - using xcfilelists",
completion: Format.completion)
targetName = subparser.add(option: "--target",
shortName: "-t",
usage: "The name of target.")
}

func run(with arguments: ArgumentParser.Result) throws {
let name = arguments.get(self.name) ?? "Carthage"
let projectPath = arguments.get(self.projectPath) ?? ProcessInfo.processInfo.environment["PROJECT_DIR"]
let format = arguments.get(self.format) ?? .list
let targetName = arguments.get(self.targetName) ?? ProcessInfo.processInfo.environment["TARGET_NAME"]
frameworkInformationService.projectPath = projectPath
try frameworkInformationService.lintScript(withName: name,
format: format,
targetName: targetName)
}
}
12 changes: 6 additions & 6 deletions Sources/Carting/Commands/UpdateCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

import SPMUtility
import CartingCore
import Foundation

final class UpdateCommand: Command {

var command = "update"
var overview = "Adds a new script with input/output file paths or updates the script named `Carthage`."

private let name: OptionArgument<String>
private let path: OptionArgument<String>
private let projectPath: OptionArgument<String>
private let format: OptionArgument<Format>
private let targetName: OptionArgument<String>

Expand All @@ -22,7 +23,7 @@ final class UpdateCommand: Command {
name = subparser.add(option: "--script",
shortName: "-s",
usage: "The name of Carthage script.")
path = subparser.add(option: "--path",
projectPath = subparser.add(option: "--path",
shortName: "-p",
usage: "The project directory path.",
completion: .filename)
Expand All @@ -37,12 +38,11 @@ final class UpdateCommand: Command {

func run(with arguments: ArgumentParser.Result) throws {
let name = arguments.get(self.name) ?? "Carthage"
let path = arguments.get(self.path)
let projectPath = arguments.get(self.projectPath) ?? ProcessInfo.processInfo.environment["PROJECT_DIR"]
let format = arguments.get(self.format) ?? .list
let targetName = arguments.get(self.targetName)
frameworkInformationService.path = path
let targetName = arguments.get(self.targetName) ?? ProcessInfo.processInfo.environment["TARGET_NAME"]
frameworkInformationService.projectPath = projectPath
try frameworkInformationService.updateScript(withName: name,
path: path,
format: format,
targetName: targetName)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Carting/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CartingCore
do {
let registry = CommandRegistry(usage: "<command> <options>",
overview: "🚘 Simple tool for updating Carthage script phase")
registry.register(UpdateCommand.self, InfoCommand.self)
registry.register(InfoCommand.self, LintCommand.self, UpdateCommand.self)
try registry.run()
}
catch {
Expand Down
8 changes: 8 additions & 0 deletions Sources/CartingCore/Models/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ final class Project {
self.scripts = scripts
self.frameworkScripts = frameworkScripts
}

func addScript(withName name: String, body: ScriptBody, to target: Target) {
let identifier = String.randomAlphaNumericString(length: 24)
let script = Script(identifier: identifier, name: name, body: body)
let buildPhase = BuildPhase(identifier: identifier, name: name)
scripts.append(script)
target.body.buildPhases.append(buildPhase)
}
}
Loading

0 comments on commit 00f6df1

Please sign in to comment.