mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-04-04 18:30:09 +02:00
♻️ Various refactoring
This commit is contained in:
44
phpmon/Domain/Integrations/Homebrew/BrewTapFormulae.swift
Normal file
44
phpmon/Domain/Integrations/Homebrew/BrewTapFormulae.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// BrewTapFormulae.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 01/11/2023.
|
||||
// Copyright © 2023 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class BrewTapFormulae {
|
||||
public static func from(tap: String) -> [String: Set<String>] {
|
||||
let directory = "\(Paths.tapPath)/\(tap)/Formula"
|
||||
let files = try? FileSystem.getShallowContentsOfDirectory(directory)
|
||||
|
||||
var availableExtensions = [String: Set<String>]()
|
||||
|
||||
guard let files else {
|
||||
return availableExtensions
|
||||
}
|
||||
|
||||
let regex = try! NSRegularExpression(pattern: "(\\w+)@(\\d+\\.\\d+)\\.rb")
|
||||
|
||||
for file in files {
|
||||
let matches = regex.matches(in: file, range: NSRange(file.startIndex..., in: file))
|
||||
if let match = matches.first {
|
||||
if let phpExtensionRange = Range(match.range(at: 1), in: file),
|
||||
let versionRange = Range(match.range(at: 2), in: file) {
|
||||
let phpExtension = String(file[phpExtensionRange])
|
||||
let phpVersion = String(file[versionRange])
|
||||
|
||||
if var existingExtensions = availableExtensions[phpVersion] {
|
||||
existingExtensions.insert(phpExtension)
|
||||
availableExtensions[phpVersion] = existingExtensions
|
||||
} else {
|
||||
availableExtensions[phpVersion] = [phpExtension]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return availableExtensions
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user