From 46005a3c689e2d01493eccbece16722050c40729 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sat, 22 Jan 2022 21:35:32 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Load=20notable=20dependencies=20?= =?UTF-8?q?(incl.=20laravel,=20#80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Domain/Core/Base.lproj/Main.storyboard | 43 ++++--------------- .../Integrations/Composer/ComposerJson.swift | 13 ++++++ phpmon/Domain/Integrations/Valet/Valet.swift | 14 ++++-- phpmon/Domain/SiteList/SiteListCell.swift | 13 +++--- phpmon/Domain/SiteList/SiteListVC.swift | 1 - 5 files changed, 36 insertions(+), 48 deletions(-) diff --git a/phpmon/Domain/Core/Base.lproj/Main.storyboard b/phpmon/Domain/Core/Base.lproj/Main.storyboard index 446cd12..d30390e 100644 --- a/phpmon/Domain/Core/Base.lproj/Main.storyboard +++ b/phpmon/Domain/Core/Base.lproj/Main.storyboard @@ -473,7 +473,7 @@ - + @@ -481,7 +481,7 @@ - + @@ -492,7 +492,7 @@ - + @@ -500,46 +500,25 @@ - - - - - - - - - - + - - @@ -547,26 +526,21 @@ - - - - + - - @@ -616,13 +590,12 @@ - + - diff --git a/phpmon/Domain/Integrations/Composer/ComposerJson.swift b/phpmon/Domain/Integrations/Composer/ComposerJson.swift index 860b484..0752733 100644 --- a/phpmon/Domain/Integrations/Composer/ComposerJson.swift +++ b/phpmon/Domain/Integrations/Composer/ComposerJson.swift @@ -28,6 +28,19 @@ struct ComposerJson: Decodable { return ("", "unknown") } + public func getNotableDependencies() -> [String: String] { + var notable: [String: String] = [:] + let scan = ["php", "laravel/framework"] + + scan.forEach { dependency in + if dependencies?[dependency] != nil { + notable[dependency] = dependencies![dependency] + } + } + + return notable + } + private enum CodingKeys: String, CodingKey { case dependencies = "require" case devDependencies = "require-dev" diff --git a/phpmon/Domain/Integrations/Valet/Valet.swift b/phpmon/Domain/Integrations/Valet/Valet.swift index 6223a55..8cc1ad4 100644 --- a/phpmon/Domain/Integrations/Valet/Valet.swift +++ b/phpmon/Domain/Integrations/Valet/Valet.swift @@ -162,10 +162,13 @@ class Valet { /// What driver is currently in use. If not detected, defaults to nil. var driver: String? = nil - /// The PHP version as discovered in composer.json + /// A list of notable Composer dependencies. + var notableComposerDependencies: [String: String] = [:] + + /// The PHP version as discovered in composer.json. var composerPhp: String = "???" - /// How the PHP version was determined + /// How the PHP version was determined. var composerPhpSource: String = "unknown" init() {} @@ -210,10 +213,13 @@ class Valet { let path = "\(absolutePath!)/composer.json" do { if Filesystem.fileExists(path) { - (self.composerPhp, self.composerPhpSource) = try JSONDecoder().decode( + let decoded = try JSONDecoder().decode( ComposerJson.self, from: String(contentsOf: URL(fileURLWithPath: path), encoding: .utf8).data(using: .utf8)! - ).getPhpVersion() + ) + + (self.composerPhp, self.composerPhpSource) = decoded.getPhpVersion() + self.notableComposerDependencies = decoded.getNotableDependencies() } } catch { Log.err("Something went wrong reading the composer JSON file.") diff --git a/phpmon/Domain/SiteList/SiteListCell.swift b/phpmon/Domain/SiteList/SiteListCell.swift index ec640a5..d4eea96 100644 --- a/phpmon/Domain/SiteList/SiteListCell.swift +++ b/phpmon/Domain/SiteList/SiteListCell.swift @@ -21,9 +21,6 @@ class SiteListCell: NSTableCellView @IBOutlet weak var labelDriver: NSTextField! - @IBOutlet weak var buttonWarning: NSButton! - @IBOutlet weak var labelWarning: NSTextField! - @IBOutlet weak var buttonPhpVersion: NSButton! override func draw(_ dirtyRect: NSRect) { @@ -36,11 +33,6 @@ class SiteListCell: NSTableCellView // Make sure to show the TLD labelSiteName.stringValue = "\(site.name!).\(Valet.shared.config.tld)" - let isProblematic = site.name.contains(" ") - buttonWarning.isHidden = !isProblematic - labelWarning.isHidden = !isProblematic - labelWarning.stringValue = "site_list.warning.spaces".localized - // Show the absolute path, except make sure to replace the /Users/username segment with ~ for readability labelPathName.stringValue = site.absolutePath .replacingOccurrences(of: "/Users/\(Paths.whoami)", with: "~") @@ -62,6 +54,11 @@ class SiteListCell: NSTableCellView // Show the current driver labelDriver.stringValue = "\(site.driver ?? "???")" + if site.driver == "Laravel" && site.notableComposerDependencies.keys.contains("laravel/framework") { + let constraint = site.notableComposerDependencies["laravel/framework"]! + labelDriver.stringValue = "Laravel (\(constraint))" + } + // Show the PHP version buttonPhpVersion.title = " PHP \(site.composerPhp) " buttonPhpVersion.isHidden = (site.composerPhp == "???") diff --git a/phpmon/Domain/SiteList/SiteListVC.swift b/phpmon/Domain/SiteList/SiteListVC.swift index d2dc655..039180b 100644 --- a/phpmon/Domain/SiteList/SiteListVC.swift +++ b/phpmon/Domain/SiteList/SiteListVC.swift @@ -186,7 +186,6 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource { DispatchQueue.main.async { self.tableView.reloadData() } - } // MARK: - Deinitialization