mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
👌 Detect binary paths (#144)
This change introduces binary detection to the app. PHP Monitor does not rely on the user's PATH because the output of a user's terminal can cause issues, so we will scan the two common locations for the Composer binary file. The text in the alert has been modified to accommodate the change (you could still not have Composer installed).
This commit is contained in:
@@ -24,6 +24,10 @@ public class Paths {
|
||||
userName = String(Shell.pipe("whoami").split(separator: "\n")[0])
|
||||
}
|
||||
|
||||
public func detectBinaryPaths() {
|
||||
detectComposerBinary()
|
||||
}
|
||||
|
||||
// - MARK: Binaries
|
||||
|
||||
public static var valet: String {
|
||||
@@ -42,6 +46,11 @@ public class Paths {
|
||||
return "\(binPath)/php-config"
|
||||
}
|
||||
|
||||
// - MARK: Detected Binaries
|
||||
|
||||
/** The path to the Composer binary. Can be in multiple locations, so is detected instead. */
|
||||
public static var composer: String? = nil
|
||||
|
||||
// - MARK: Paths
|
||||
|
||||
public static var whoami: String {
|
||||
@@ -64,6 +73,21 @@ public class Paths {
|
||||
return "\(shared.baseDir.rawValue)/etc"
|
||||
}
|
||||
|
||||
// MARK: - Flexible Binaries
|
||||
// (these can be in multiple locations, so we scan common places because)
|
||||
// (PHP Monitor will not use the user's own PATH)
|
||||
|
||||
private func detectComposerBinary() {
|
||||
if Filesystem.fileExists("/usr/local/bin/composer") {
|
||||
Paths.composer = "/usr/local/bin/composer"
|
||||
} else if Filesystem.fileExists("/opt/homebrew/bin/composer") {
|
||||
Paths.composer = "/opt/homebrew/bin/composer"
|
||||
} else {
|
||||
Paths.composer = nil
|
||||
Log.warn("Composer was not found.")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Enum
|
||||
|
||||
public enum HomebrewDir: String {
|
||||
|
@@ -23,8 +23,9 @@ class ComposerWindow {
|
||||
self.shouldNotify = notify
|
||||
self.completion = completion
|
||||
|
||||
if !Filesystem.fileExists("/usr/local/bin/composer") {
|
||||
presentMissingSymlinkAlert()
|
||||
Paths.shared.detectBinaryPaths()
|
||||
if Paths.composer == nil {
|
||||
presentMissingAlert()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -41,11 +42,11 @@ class ComposerWindow {
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async { [self] in
|
||||
let task = Shell.user.createTask(
|
||||
for: "/usr/local/bin/composer global update", requiresPath: true
|
||||
for: "\(Paths.composer!) global update", requiresPath: true
|
||||
)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.window?.addToConsole("/usr/local/bin/composer global update\n")
|
||||
self.window?.addToConsole("\(Paths.composer!) global update\n")
|
||||
}
|
||||
|
||||
task.listen(
|
||||
@@ -114,11 +115,12 @@ class ComposerWindow {
|
||||
|
||||
// MARK: Alert
|
||||
|
||||
private func presentMissingSymlinkAlert() {
|
||||
private func presentMissingAlert() {
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.composer_missing.title".localized,
|
||||
subtitle: "alert.composer_missing.info".localized
|
||||
subtitle: "alert.composer_missing.subtitle".localized,
|
||||
description: "alert.composer_missing.desc".localized
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
.show()
|
||||
|
@@ -76,6 +76,8 @@ extension MainMenu {
|
||||
Log.info("PHP Monitor has extracted the version number of Valet: \(Valet.shared.version!)")
|
||||
}
|
||||
|
||||
Paths.shared.detectBinaryPaths()
|
||||
|
||||
Valet.shared.loadConfiguration()
|
||||
Valet.shared.validateVersion()
|
||||
Valet.shared.startPreloadingSites()
|
||||
|
@@ -182,7 +182,13 @@
|
||||
|
||||
// Composer Update
|
||||
"alert.composer_missing.title" = "Composer not found!";
|
||||
"alert.composer_missing.info" = "Make sure you have Composer available in `/usr/local/bin/composer`. If Composer is located somewhere else, please create a symlink, like so (make sure to use the correct path):\n\n`ln -s /path/to/composer /usr/local/bin`.";
|
||||
"alert.composer_missing.subtitle" = "PHP Monitor could not find Composer. Make sure that Composer is installed and try again.";
|
||||
"alert.composer_missing.desc" = "PHP Monitor assumes that Composer is located in either:
|
||||
|
||||
• `/usr/local/bin/composer`
|
||||
• `/opt/homebrew/bin/composer`
|
||||
|
||||
Make sure you have it installed in one of these locations, or make a symlink if you have Composer installed somewhere else.";
|
||||
|
||||
"alert.composer_progress.title" = "Updating global dependencies...";
|
||||
"alert.composer_progress.info" = "You can see the progress in the terminal output below.";
|
||||
|
Reference in New Issue
Block a user