mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
🏗 WIP: Detect linked and parked sites (#58)
This commit is contained in:
@ -12,7 +12,8 @@ class Valet {
|
|||||||
|
|
||||||
var version: String
|
var version: String
|
||||||
var config: Valet.Configuration
|
var config: Valet.Configuration
|
||||||
var detectedSites: [String]
|
var parkedSites: [Site] = []
|
||||||
|
var linkedSites: [Site] = []
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
self.version = Actions.valet("--version")
|
self.version = Actions.valet("--version")
|
||||||
@ -27,16 +28,77 @@ class Valet {
|
|||||||
from: try! String(contentsOf: file, encoding: .utf8).data(using: .utf8)!
|
from: try! String(contentsOf: file, encoding: .utf8).data(using: .utf8)!
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
|
||||||
print("PHP Monitor should scan the following paths:")
|
print("PHP Monitor should scan the following paths:")
|
||||||
print(self.config.paths)
|
print(self.config.paths)
|
||||||
*/
|
|
||||||
|
|
||||||
self.detectedSites = []
|
resolvePaths()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func resolvePaths() {
|
||||||
|
self.linkedSites = []
|
||||||
|
self.parkedSites = []
|
||||||
|
|
||||||
|
for path in self.config.paths {
|
||||||
|
let entries = try! FileManager.default.contentsOfDirectory(atPath: path)
|
||||||
|
for entry in entries {
|
||||||
|
self.resolvePath(entry, forPath: path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func resolvePath(_ entry: String, forPath path: String) {
|
||||||
|
let siteDir = path + "/" + entry
|
||||||
|
|
||||||
|
// See if the file is a symlink, if so, resolve it
|
||||||
|
let attrs = try! FileManager.default.attributesOfItem(atPath: siteDir)
|
||||||
|
|
||||||
|
// We can also determine whether the thing at the path is a directory, too
|
||||||
|
let type = attrs[FileAttributeKey.type] as! FileAttributeType
|
||||||
|
|
||||||
|
if type == FileAttributeType.typeSymbolicLink {
|
||||||
|
self.linkedSites.append(Site(aliasPath: siteDir))
|
||||||
|
} else if type == FileAttributeType.typeDirectory {
|
||||||
|
self.parkedSites.append(Site(absolutePath: siteDir))
|
||||||
|
} else {
|
||||||
|
print("The item at: `\(siteDir)` was neither a symlink nor a directory. Skipping.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Structs
|
// MARK: - Structs
|
||||||
|
|
||||||
|
class Site {
|
||||||
|
var name: String
|
||||||
|
|
||||||
|
var absolutePath: String
|
||||||
|
var aliasPath: String?
|
||||||
|
|
||||||
|
init(absolutePath: String) {
|
||||||
|
self.absolutePath = absolutePath
|
||||||
|
self.aliasPath = nil
|
||||||
|
self.name = URL(string: absolutePath)!.lastPathComponent
|
||||||
|
self.detectSiteProperties()
|
||||||
|
}
|
||||||
|
|
||||||
|
convenience init(aliasPath: String) {
|
||||||
|
// Resolve the symlink
|
||||||
|
let absolutePath = try! FileManager.default
|
||||||
|
.destinationOfSymbolicLink(atPath: aliasPath)
|
||||||
|
self.init(absolutePath: absolutePath)
|
||||||
|
|
||||||
|
// TODO: Make sure the destination is a valid directory!
|
||||||
|
|
||||||
|
// The name should be identical to the alias' name
|
||||||
|
self.name = URL(string: aliasPath)!.lastPathComponent
|
||||||
|
|
||||||
|
// Update the alias' path
|
||||||
|
self.aliasPath = aliasPath
|
||||||
|
}
|
||||||
|
|
||||||
|
private func detectSiteProperties() {
|
||||||
|
// TODO: Determine additional information, like Composer status and PHP version?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Configuration: Decodable {
|
struct Configuration: Decodable {
|
||||||
let tld: String
|
let tld: String
|
||||||
let paths: [String]
|
let paths: [String]
|
||||||
|
Reference in New Issue
Block a user