mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-27 14:30:08 +01:00
♻️ WIP: Updates related to Valet version change
- Centralized logic related to fetching Valet version. - Updating global dependencies now updates the version number of Valet in the driver section. - The latest version of Valet is now determined by checking Packagist. (This only occurs when the app starts up.)
This commit is contained in:
@@ -278,19 +278,7 @@ class Startup {
|
||||
// =================================================================================
|
||||
EnvironmentCheck(
|
||||
command: {
|
||||
let output = await Shell.pipe("valet --version").out
|
||||
// Failure condition #1: does not contain Laravel Valet
|
||||
if !output.contains("Laravel Valet") {
|
||||
return true
|
||||
}
|
||||
// Failure condition #2: version cannot be parsed
|
||||
let versionString = output
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.components(separatedBy: "Laravel Valet")[1]
|
||||
.trimmingCharacters(in: .whitespaces)
|
||||
// Extract the version number
|
||||
Valet.shared.version = try! VersionNumber.parse(VersionExtractor.from(versionString)!)
|
||||
// Get the actual version
|
||||
await Valet.shared.updateVersionNumber()
|
||||
return Valet.shared.version == nil
|
||||
},
|
||||
name: "`valet --version` was loaded",
|
||||
|
||||
@@ -84,7 +84,14 @@ import NVAlert
|
||||
)
|
||||
}
|
||||
window = nil
|
||||
|
||||
// Update the internal Valet number because it may have updated
|
||||
await Valet.shared.updateVersionNumber()
|
||||
|
||||
// Update the UI
|
||||
removeBusyStatus()
|
||||
|
||||
// Fire completion callback
|
||||
completion(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ class Valet {
|
||||
/// The version of Valet that was detected.
|
||||
var version: VersionNumber?
|
||||
|
||||
/// The latest version of Valet, checked via Packagist, if possible.
|
||||
var latestVersion: VersionNumber?
|
||||
|
||||
/// The Valet configuration file.
|
||||
var config: Valet.Configuration!
|
||||
|
||||
@@ -80,6 +83,29 @@ class Valet {
|
||||
return self.shared.sites + self.shared.proxies
|
||||
}
|
||||
|
||||
/**
|
||||
Updates the internal version number of Laravel Valet.
|
||||
If this version number cannot be determined, it fails,
|
||||
and the app cannot start.
|
||||
*/
|
||||
public func updateVersionNumber() async {
|
||||
let output = await Shell.pipe("valet --version").out
|
||||
|
||||
// Failure condition #1: does not contain Laravel Valet
|
||||
if !output.contains("Laravel Valet") {
|
||||
return
|
||||
}
|
||||
|
||||
// Failure condition #2: version cannot be parsed
|
||||
let versionString = output
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.components(separatedBy: "Laravel Valet")[1]
|
||||
.trimmingCharacters(in: .whitespaces)
|
||||
|
||||
// Extract the version number
|
||||
Valet.shared.version = try? VersionNumber.parse(VersionExtractor.from(versionString)!)
|
||||
}
|
||||
|
||||
/**
|
||||
We don't want to load the initial config.json file as soon as the class is initialised.
|
||||
|
||||
@@ -184,6 +210,28 @@ class Valet {
|
||||
.out.contains("Composer detected issues in your platform")
|
||||
}
|
||||
|
||||
/**
|
||||
Determine if there is a newer version of Laravel Valet available.
|
||||
Checks by verifying the latest version via Packagist (Composer).
|
||||
*/
|
||||
public func checkForUpdates() async {
|
||||
if let currentVersion = self.version,
|
||||
let latestVersion = try? await Packagist.getLatestStableVersion(packageName: "laravel/valet") {
|
||||
self.latestVersion = latestVersion
|
||||
|
||||
if latestVersion.isNewerThan(currentVersion, false) {
|
||||
Log.info("The latest version of Valet is \(latestVersion.text); current is \(currentVersion.text).")
|
||||
|
||||
// Update the menu so this update is visible.
|
||||
await MainMenu.shared.rebuild()
|
||||
} else {
|
||||
Log.info("You are running the latest version of Valet (\(latestVersion.text).")
|
||||
}
|
||||
} else {
|
||||
Log.warn("Could not check for latest version of Valet.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Determine if PHP-FPM is configured correctly.
|
||||
|
||||
|
||||
@@ -146,6 +146,9 @@ extension MainMenu {
|
||||
|
||||
// Check if the linked version has changed between launches of phpmon
|
||||
await PhpGuard().compareToLastGlobalVersion()
|
||||
|
||||
// Check if Valet has updates
|
||||
await Valet.shared.checkForUpdates()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import Testing
|
||||
|
||||
@Suite("Integration")
|
||||
struct PackagistTest {
|
||||
@Test func packagistRetrieval() async {
|
||||
@Test func canRetrieveLaravelValetVersion() async {
|
||||
let packageToCheck = "laravel/valet"
|
||||
let latestVersion = try? await Packagist.getLatestStableVersion(packageName: packageToCheck)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user