Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Package Version Command #14

Merged
merged 21 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
72586c5
Created basic VersonSet console command
calebkleveter Jan 22, 2018
962d720
Implimented VersionSet.signiture array
calebkleveter Jan 22, 2018
c8108e1
Implimented VersionSet.help array
calebkleveter Jan 22, 2018
11d20b4
Created VeriableSet.versionOption private method
calebkleveter Jan 23, 2018
d5cfa0e
Added quotes to version range from VersionSet.versionOption
calebkleveter Jan 24, 2018
91198a7
Set Swift version to 4.1
calebkleveter Feb 13, 2018
9416c67
Fixed documentation for Manifest.getPackageUrl method
calebkleveter Feb 13, 2018
6099ebe
Started implementing VersionSet.run method
calebkleveter Feb 13, 2018
4e8ac66
Added VersionSet command to main executable
calebkleveter Feb 13, 2018
2d5eed2
Set Swift version to 4.1
calebkleveter Feb 13, 2018
0097914
Removed use of --enable-prefetching flag
calebkleveter Feb 13, 2018
736660d
Merge pull request #12 from Ether-CLI/swift-4.1
calebkleveter Feb 13, 2018
008872f
Set Swift version to 4.1
calebkleveter Feb 13, 2018
d2f00f1
Fixed RegEx for VersionSet to handle all package version types
calebkleveter Feb 16, 2018
b5b8c10
Specified exact version as the default package version type
calebkleveter Feb 16, 2018
42a5615
Added loading bars, Xcode regeneration, and package update to Version…
calebkleveter Feb 16, 2018
e9190fb
Updated VersionLatest comand regex to find packages with any version …
calebkleveter Feb 16, 2018
d30bf44
Updated VersionAll command script to use Manifest API
calebkleveter Feb 16, 2018
98d1aa0
Updated Remove command regex to handle packages with any version type
calebkleveter Feb 16, 2018
5bd0e59
Added v1.10.0 entry to CHANGELOG
calebkleveter Feb 16, 2018
05a23fa
Updated executable version
calebkleveter Feb 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.2
4.1
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [1.10.0] 2018-02-18

### Added
- `ether version set` command to update the version of a single package.

### Updated
- The RegEx for any command that matches the version of a package, so it handles any version type for a package.

## [1.9.2] 2017-11-27

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions Sources/Ether/FixInstall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public class FixInstall: Command {
fixBar.start()

_ = try console.backgroundExecute(program: "rm", arguments: ["-rf", ".build"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "resolve"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "resolve"])

if arguments.option("no-build") == nil {
_ = try console.backgroundExecute(program: "swift", arguments: ["build", "--enable-prefetching"])
_ = try console.backgroundExecute(program: "swift", arguments: ["build"])
}

fixBar.finish()
Expand Down
6 changes: 3 additions & 3 deletions Sources/Ether/Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public final class Install: Command {
try String(mutablePackageManifest).data(using: .utf8)?.write(to: URL(string: "file:\(fileManager.currentDirectoryPath)/Package.swift")!)

// Update the packages.
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "resolve"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "resolve"])

// Get the new package name and add it to the previously accepted targets.
let dependencyName = try Manifest.current.getPackageName(for: newPackageData.url)
Expand All @@ -135,7 +135,7 @@ public final class Install: Command {
if let _ = arguments.options["xcode"] {
let xcodeBar = console.loadingBar(title: "Generating Xcode Project")
xcodeBar.start()
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "generate-xcodeproj"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "generate-xcodeproj"])
xcodeBar.finish()
try console.execute(program: "/bin/sh", arguments: ["-c", "open *.xcodeproj"], input: nil, output: nil, error: nil)
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Ether/Remove.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final class Remove: Command {
let name = try value("name", from: arguments)
let url = try Manifest.current.getPackageUrl(for: name)

let regex = try NSRegularExpression(pattern: "\\,?\\n *\\.package\\(url: *\"\(url)\", *\\.?\\w+(:|\\() *\"([\\d\\.]+)\"\\)?\\),?", options: .caseInsensitive)
let regex = try NSRegularExpression(pattern: "(\\,?\\n *\\.package\\(url: *\"\(url)\", *)(.*?)(?=,?\n)", options: .caseInsensitive)
let oldPins = try Manifest.current.getPins()

let packageString = try Manifest.current.get()
Expand All @@ -69,8 +69,8 @@ public final class Remove: Command {

do {
try String(mutableString).data(using: .utf8)?.write(to: URL(string: "file:\(manager.currentDirectoryPath)/Package.swift")!)
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "resolve"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "resolve"])
} catch let error {
removingProgressBar.fail()
throw error
Expand All @@ -84,7 +84,7 @@ public final class Remove: Command {
if let _ = arguments.options["xcode"] {
let xcodeBar = console.loadingBar(title: "Generating Xcode Project")
xcodeBar.start()
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "generate-xcodeproj"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "generate-xcodeproj"])
xcodeBar.finish()
try console.execute(program: "/bin/sh", arguments: ["-c", "open *.xcodeproj"], input: nil, output: nil, error: nil)
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Ether/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public final class Update: Command {
let updateBar = console.loadingBar(title: "Updating Packages")
updateBar.start()
_ = try console.backgroundExecute(program: "rm", arguments: ["-rf", ".build"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "resolve"])
_ = try console.backgroundExecute(program: "swift", arguments: ["build", "--enable-prefetching"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "resolve"])
_ = try console.backgroundExecute(program: "swift", arguments: ["build"])
updateBar.finish()

if let _ = arguments.options["xcode"] {
let xcodeBar = console.loadingBar(title: "Generating Xcode Project")
xcodeBar.start()
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "generate-xcodeproj"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "generate-xcodeproj"])
xcodeBar.finish()
try console.execute(program: "/bin/sh", arguments: ["-c", "open *.xcodeproj"], input: nil, output: nil, error: nil)
}
Expand Down
23 changes: 6 additions & 17 deletions Sources/Ether/VersionAll.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,12 @@ public final class VersionAll: Command {
let fetchingDataBar = console.loadingBar(title: "Getting Package Data")
fetchingDataBar.start()

let manager = FileManager.default

guard let packageData = manager.contents(atPath: "\(manager.currentDirectoryPath)/Package.resolved") else {
throw fail(bar: fetchingDataBar, with: "Make sure you are in the root of an SPM project.")
}

guard let packageJson = try packageData.json()?["object"] as? [String: AnyObject] else {
throw fail(bar: fetchingDataBar, with: "Unable to parse data from Package.resolved.")
}

if let pins = packageJson["pins"] as? [[String: AnyObject]] {
fetchingDataBar.finish()
pins.forEach { package in
console.output("\(package["package"] ?? "N/A" as AnyObject): ", style: .success, newLine: false)
if let state = package["state"] as? [String: AnyObject] {
console.output("v\(state["version"] ?? "N/A" as AnyObject)", style: .plain, newLine: true)
}
let pins = try Manifest.current.getPins()
fetchingDataBar.finish()
pins.forEach { package in
console.output("\(package["package"] ?? "N/A" as AnyObject): ", style: .success, newLine: false)
if let state = package["state"] as? [String: AnyObject] {
console.output("v\(state["version"] ?? "N/A" as AnyObject)", style: .plain, newLine: true)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Ether/VersionLatest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class VersionLatest: Command {
let fileManager = FileManager.default
let manifest = try Manifest.current.get()
let nsManifest = NSMutableString(string: manifest)
let versionPattern = try NSRegularExpression(pattern: "(.package\\(url:\\s*\".*?\\.com\\/(.*?)\\.git\",\\s*)(\\.?\\w+(\\(|:)\\s*\"[\\w\\.]+\"\\)?)(\\))", options: [])
let versionPattern = try NSRegularExpression(pattern: "(.package\\(url:\\s*\".*?\\.com\\/(.*?)\\.git\",\\s*)(.*?)(\\),?\\n)", options: [])
let matches = versionPattern.matches(in: manifest, options: [], range: NSMakeRange(0, manifest.utf8.count))
let packageNames = matches.map { match -> String in
let name = versionPattern.replacementString(for: match, in: manifest, offset: 0, template: "$2")
Expand All @@ -72,15 +72,15 @@ public final class VersionLatest: Command {
}

try String(nsManifest).data(using: .utf8)?.write(to: URL(string: "file:\(fileManager.currentDirectoryPath)/Package.swift")!)
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "resolve"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "resolve"])

updateBar.finish()

if let _ = arguments.options["xcode"] {
let xcodeBar = console.loadingBar(title: "Generating Xcode Project")
xcodeBar.start()
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "--enable-prefetching", "generate-xcodeproj"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "generate-xcodeproj"])
xcodeBar.finish()
try console.execute(program: "/bin/sh", arguments: ["-c", "open *.xcodeproj"], input: nil, output: nil, error: nil)
}
Expand Down
117 changes: 117 additions & 0 deletions Sources/Ether/VersionSet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// The MIT License (MIT)
//
// Copyright (c) 2017 Caleb Kleveter
//
// 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.

import Console
import Helpers
import Foundation

public final class VersonSet: Command {
public let id: String = "set"

public var signature: [Argument] = [
Value(name: "name", help: [
"The name of the package to change the version for"
]),
Value(name: "version", help: [
"The value for the new version. The format varies depending on the version type used"
]),
Option(name: "xcode", short: "x", help: [
"Regenerate the Xcode project after updating a package's version"
]),
Option(name: "from", short: "f", help: [
"Sets the dependency version argument to `from: VERSION`"
]),
Option(name: "up-to-next-major", short: "u", help: [
"Sets the dependency version argument to `.upToNextMinor(from: \"VERSION\")`"
]),
Option(name: "exact", short: "e", help: [
"(Default) Sets the dependency version argument to `.exact(\"VERSION\")`"
]),
Option(name: "range", short: "r", help: [
"Sets the dependency version argument to `VERSION`"
]),
Option(name: "branch", short: "b", help: [
"Sets the dependency version argument to `.branch(\"VERSION\")`"
]),
Option(name: "revision", help: [
"Sets the dependency version argument to `.revision(\"VERSION\")`"
])
]

public var help: [String] = [
"Changes the version of a single dependency"
]

public let console: ConsoleProtocol

public init(console: ConsoleProtocol) {
self.console = console
}

public func run(arguments: [String]) throws {
let updateBar = console.loadingBar(title: "Updating Package Version")
updateBar.start()

let package = try value("name", from: arguments)
let version = try value("version", from: arguments)
let versionLitteral = versionOption(from: arguments, with: version)

let url = try Manifest.current.getPackageUrl(for: package)
let manifest = try NSMutableString(string: Manifest.current.get())
let pattern = try NSRegularExpression(
pattern: "(\\,?\\n *\\.package\\(url: *\"\(url)\", *)(.*?)(\\),?\\n)",
options: []
)
pattern.replaceMatches(in: manifest, options: [], range: NSMakeRange(0, manifest.length), withTemplate: "$1\(versionLitteral)$3")
try Manifest.current.write(String(manifest))

_ = try console.backgroundExecute(program: "swift", arguments: ["package", "update"])
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "resolve"])

updateBar.finish()

if let _ = arguments.options["xcode"] {
let xcodeBar = console.loadingBar(title: "Generating Xcode Project")
xcodeBar.start()
_ = try console.backgroundExecute(program: "swift", arguments: ["package", "generate-xcodeproj"])
xcodeBar.finish()
try console.execute(program: "/bin/sh", arguments: ["-c", "open *.xcodeproj"], input: nil, output: nil, error: nil)
}

console.output("\(package) version was updated", style: .plain, newLine: true)
}

private func versionOption(from arguments: [String], with version: String) -> String {
if arguments.option("from") != nil {
return "from: \"\(version)\""
} else if arguments.option("up-to-next-major") != nil {
return ".upToNextMajor(from: \"\(version)\")"
} else if arguments.option("range") != nil {
return "\"\(version.dropLast(8))\"\(String(version.dropFirst(5)).dropLast(5))\"\(version.dropFirst(8))\""
} else if arguments.option("branch") != nil {
return ".branch(\"\(version)\")"
} else if arguments.option("revision") != nil {
return ".revision(\"\(version)\")"
}
return ".exact(\"\(version)\")"
}
}
5 changes: 3 additions & 2 deletions Sources/Executable/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Helpers
import libc

// The current version of Ether. This string should be updated with each release.
let version = "1.9.2"
let version = "1.10.0"
var arguments = CommandLine.arguments
let terminal = Terminal(arguments: arguments)
var iterator = arguments.makeIterator()
Expand Down Expand Up @@ -57,7 +57,8 @@ do {
FixInstall(console: terminal),
Group(id: "version", commands: [
VersionLatest(console: terminal),
VersionAll(console: terminal)
VersionAll(console: terminal),
VersonSet(console: terminal)
], help: ["For interacting with dependency versions"]),
CleanManifest(console: terminal)
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/Helpers/Manifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class Manifest {
return name
}

/// Gets the name of the package that has a specefied URL by reading the `Package.resolved` file data.
/// Gets the URL of the package that has a specefied name by reading the `Package.resolved` file data.
///
/// - Parameter name: The ame of the package that the URL is to get fetched from.
/// - Returns: The URL of the package that was found.
Expand Down