Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thii committed Jun 25, 2019
0 parents commit fddacac
Show file tree
Hide file tree
Showing 16 changed files with 682 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
.swiftpm
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2019 Thi Doãn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
142 changes: 142 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"object": {
"pins": [
{
"package": "Args",
"repositoryURL": "https://github.com/getGuaka/Args.git",
"state": {
"branch": null,
"revision": "f58452117e865bf1b7c6fc29a4368e207c1f5c24",
"version": "0.1.1"
}
},
{
"package": "Colorizer",
"repositoryURL": "https://github.com/getGuaka/Colorizer.git",
"state": {
"branch": null,
"revision": "2ccc99bf1715e73c4139e8d40b6e6b30be975586",
"version": "0.2.1"
}
},
{
"package": "Guaka",
"repositoryURL": "https://github.com/nsomar/Guaka.git",
"state": {
"branch": null,
"revision": "6fb29b2378166a30d72120980e1c099c664598de",
"version": "0.4.1"
}
},
{
"package": "Just",
"repositoryURL": "https://github.com/JustHTTP/Just.git",
"state": {
"branch": null,
"revision": "a6b530d0e7f237aee6262a4ba71086d9d884bb58",
"version": "0.7.1"
}
},
{
"package": "Mint",
"repositoryURL": "https://github.com/yonaskolb/Mint.git",
"state": {
"branch": null,
"revision": "6f6f5871e254462b4b380197756df18aa6f2b5c7",
"version": "0.12.0"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
"version": "7.3.4"
}
},
{
"package": "PathKit",
"repositoryURL": "https://github.com/kylef/PathKit.git",
"state": {
"branch": null,
"revision": "e2f5be30e4c8f531c9c1e8765aa7b71c0a45d7a0",
"version": "0.9.2"
}
},
{
"package": "Prompt",
"repositoryURL": "https://github.com/getGuaka/Prompt.git",
"state": {
"branch": null,
"revision": "265f929fda31c59d7dc5f1c674fd435e41dd9881",
"version": "0.1.1"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "f2b5a06440ea87eba1a167cab37bf6496646c52e",
"version": "1.3.4"
}
},
{
"package": "Rainbow",
"repositoryURL": "https://github.com/onevcat/Rainbow.git",
"state": {
"branch": null,
"revision": "9c52c1952e9b2305d4507cf473392ac2d7c9b155",
"version": "3.1.5"
}
},
{
"package": "Run",
"repositoryURL": "https://github.com/getGuaka/Run.git",
"state": {
"branch": null,
"revision": "5a2866c0ae4266e0406d85f16adf65a30a626d7f",
"version": "0.1.1"
}
},
{
"package": "Spectre",
"repositoryURL": "https://github.com/kylef/Spectre.git",
"state": {
"branch": null,
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
"version": "0.9.0"
}
},
{
"package": "StringScanner",
"repositoryURL": "https://github.com/getGuaka/StringScanner.git",
"state": {
"branch": null,
"revision": "de1685ad202cb586d626ed52d6de904dd34189f3",
"version": "0.4.1"
}
},
{
"package": "SwiftPM",
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
"state": {
"branch": null,
"revision": "63a01220e93271dc3bf204b9e13dd1aeb2beefee",
"version": "0.2.0"
}
},
{
"package": "SwiftCLI",
"repositoryURL": "https://github.com/jakeheis/SwiftCLI.git",
"state": {
"branch": null,
"revision": "5318c37d3cacc8780f50b87a8840a6774320ebdf",
"version": "5.2.2"
}
}
]
},
"version": 1
}
35 changes: 35 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// swift-tools-version:5.0

import PackageDescription

let package = Package(
name: "Swiftbrew",
platforms: [
.macOS(.v10_10)
],
products: [
.executable(name: "swift-brew", targets: ["Swiftbrew"])
],
dependencies: [
.package(url: "https://github.com/JustHTTP/Just.git", .upToNextMajor(from: "0.7.0")),
.package(url: "https://github.com/getGuaka/Colorizer.git", .upToNextMajor(from: "0.2.1")),
.package(url: "https://github.com/getGuaka/Run.git", .upToNextMajor(from: "0.1.1")),
.package(url: "https://github.com/nsomar/Guaka.git", .upToNextMajor(from: "0.4.1")),
.package(url: "https://github.com/yonaskolb/Mint.git", .upToNextMajor(from: "0.12.0")),

// SwiftCLI 5.3.0 doesn't build. This locks it to 5.2.x.
// This is a transitive dependency of Mint. We're not using this.
.package(url: "https://github.com/jakeheis/SwiftCLI.git", .upToNextMinor(from: "5.2.2")),
],
targets: [
.target(
name: "Swiftbrew",
dependencies: ["Guaka", "SwiftbrewCore"]),
.target(
name: "SwiftbrewCore",
dependencies: ["Colorizer", "Just", "MintKit", "Run"]),
.testTarget(
name: "SwiftbrewTests",
dependencies: ["Swiftbrew"]),
]
)
118 changes: 118 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Swiftbrew

A package manager that installs prebuilt Swift command line tool packages, or _Homebrew for Swift packages_.

## Installation
### Homebrew

```
brew install swiftbrew/tap/swiftbrew
```

### Mint

```
mint install swiftbrew/Swiftbrew
```

## Usage

```
swift brew install <package-reference>
```

Package reference can be a shorthand for a GitHub repository
(`Carthage/Carthage`) or a full git URL
(`https://github.com/Carthage/Carthage.git`), optionally followed by a tagged
version (`@x.y.z`). Swiftbrew currently only supports public repositories.

### Examples

Install the latest version of `Carthage`:

```
swift brew install Carthage/Carthage
```
or

```
swift brew install https://github.com/Carthage/Carthage
```

Install `Carthage` version 0.33.0:

```
swift brew install Carthage/Carthage@0.33.0
```

## Why create another package manager?

[Homebrew](https://brew.sh) is a popular method of distributing command line
tools on macOS. Some popular Swift command line tools are already distributed
via Homebrew. But there are some limitations:

- Distributing via Homebrew requires you to create a formula and then maintain
that formula.
- If your package is not popular enough to be accepted into Homebrew's core
formulae, you would have to create and maintain your own tap.
- As a package maintainer, a usual release process would be: build the
executable, archive it into a tarball/zipball, upload it to GitHub releases,
bump formula version.
- It can be tricky to install a specific version of a tool with Homebrew.

[Mint](https://github.com/yonaskolb/Mint) is a package manager that builds and
installs Swift command line tool packages. Mint is more flexible than Homebrew
as it allows installing a specific version of a package. The downside of Mint
is that it requires you to build all packages from source. This can be very
time-consuming as you start replacing most of your Ruby tools in your iOS
project with Swift packages, since bumping a tool version would require
rebuilding it from all your developers' machines.

### Introducing Swiftbrew

**Swiftbrew** saves Swift packages maintainers and users' time by caching
prebuilt Swift command line tool packages, while flexible enough to let users
install multiple versions of a package. Swiftbrew builds and caches Swift
packages on CDN servers so that they are fast to download from anywhere.
Swiftbrew bottles (prebuilt packages) are hosted on
[Bintray](http://bintray.com), the same service that hosts Homebrew bottles. If
any package is not available as a bottle, it will be built by Swiftbrew build
workers and cached after the first installation request, so that it will
available for everyone later on. Here is what an installation output looks
like:

```
$ swift brew install Carthage/Carthage
==> Finding latest version of Carthage
Resolved latest version of Carthage to 0.33.0
==> Installing Carthage 0.33.0
==> Downloading https://dl.bintray.com/swiftbrew/bottles/github.com_Carthage_Carthage-0.33.0.mojave.tar.xz
Bottle not yet available. Sent a build request to build workers.
==> Waiting for bottle to be available...
==> Pouring github.com_Carthage_Carthage-0.33.0.mojave.tar.xz
🍺 /usr/local/lib/swiftbrew/cellar/github.com_Carthage_Carthage/build/0.33.0
```

## FAQ

*What kind of packages can Swiftbrew install?*

> Swiftbrew can install any public Swift command line tool package. If you
> package can be built with `swift build` command, then it can be installed via
> Swiftbrew.
*Can I add my own package?*

> Yes, if your package's Git URL is public. Just install your package with
> Swiftbrew, a built request will be sent to Swiftbrew's build workers, then
> the bottle will be available after a few minutes.
*What platforms does Swiftbrew support?*

> We only have build workers that run macOS Mojave in the meantime. Other macOS
> versions and Linux may be added in the future upon community requests.
## License

MIT
39 changes: 39 additions & 0 deletions Sources/Swiftbrew/install.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Foundation
import Guaka
import Just
import SwiftbrewCore

var installCommand = Command(
usage: "install",
configuration: configuration,
run: run
)

private func configuration(command: Command) {
command.shortMessage = "Install a package"
command.longMessage = """
Install a Swift command line tool package:
swift brew install <package-reference>
<package-reference> can be a shorthand for a GitHub repository (Carthage/Carthage)
or a full git URL (https://github.com/Carthage/Carthage.git), optionally followed
by a tagged version (@x.y.z).
Note: Swiftbrew currently only supports public repositories.
"""
command.example = """
swift brew install thii/xcbeautify
swift brew install thii/xcbeautify@0.4.3
swift brew install https://github.com/thii/xcbeautify
"""
}

private func run(flags: Flags, args: [String]) {
guard let package = args.first else {
// Print help
return
}

try? SwiftbrewCore.install(package: package)
}
2 changes: 2 additions & 0 deletions Sources/Swiftbrew/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootCommand.add(subCommand: installCommand)
rootCommand.execute()
30 changes: 30 additions & 0 deletions Sources/Swiftbrew/root.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Guaka
import SwiftbrewCore

var rootCommand = Command(
usage: "swift-brew",
configuration: configuration,
run: nil
)

private func configuration(command: Command) {
command.add(flags: [
.init(shortName: "v",
longName: "version",
value: false,
description: "Print the version",
inheritable: true)
])

command.inheritablePreRun = { flags, args in
if let versionFlag = flags.getBool(name: "version"), versionFlag == true {
print(SwiftbrewCore.version)
return false
}

return true
}
}

private func run(flags: Flags, args: [String]) {
}
Loading

0 comments on commit fddacac

Please sign in to comment.