Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Run `mint help` to see usage instructions.
- **which**: Print the path to an installed package executable.
- **uninstall**: Uninstalls a package by name.
- **bootstrap**: Installs all the packages in your [Mintfile](#mintfile), by default, without linking them globally
- **outdated**: Lists the outdated packages in your [Mintfile](#mintfile)

**Package reference**

Expand Down
19 changes: 19 additions & 0 deletions Sources/MintCLI/Commands/OutdatedCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import Foundation
import MintKit
import PathKit
import SwiftCLI

class OutdatedCommand: MintfileCommand {

init(mint: Mint) {
super.init(mint: mint,
name: "outdated",
description: "List all the outdated packages in your Mintfile")
}

override func execute() throws {
try super.execute()
try mint.outdated()
}
}
1 change: 1 addition & 0 deletions Sources/MintCLI/MintCLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class MintCLI {
ListCommand(mint: mint),
BootstrapCommand(mint: mint),
WhichCommand(mint: mint),
OutdatedCommand(mint: mint),
])
}

Expand Down
40 changes: 40 additions & 0 deletions Sources/MintKit/Mint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,46 @@ public class Mint {
}
}

public func outdated() throws {

let mintFile = try Mintfile(path: mintFilePath)

guard !mintFile.packages.isEmpty else {
standardOut <<< "🌱 Mintfile is empty"
return
}

let packageCount = "\(mintFile.packages.count) \(mintFile.packages.count == 1 ? "package" : "packages")"

if verbose {
output("Found \(packageCount) in \(mintFilePath.string)")
}

var hasUpdates = false
for package in mintFile.packages {

let tagOutput = try Task.capture(bash: "git ls-remote --tags --refs \(package.gitPath)")
let versions = tagOutput.stdout
.split(separator: "\n")
.map { String($0.split(separator: "\t").last!.split(separator: "/").last!) }
.compactMap { Version($0) }
.sorted()

if let latestVersion = versions.last,
let packageVersion = Version(package.version) {

if packageVersion < latestVersion {
hasUpdates = true
output("\(package.name) is outdated: \(packageVersion.description) -> \(latestVersion.description)".yellow)
}
}
}

if !hasUpdates {
output("\(packageCount) up to date".green)
}
}

public func uninstall(name: String) throws {

// find packages
Expand Down
Loading