-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
50 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,61 @@ | ||
// ModelFileFinder.swift | ||
// Created by swiftanon on 7/22/24 | ||
// Created by swiftanon on 8/27/24. | ||
|
||
import Foundation | ||
import os | ||
|
||
public struct ModelFileFinder { | ||
private let fileManager: FileManagerProtocol | ||
private let fileManager: FileManagerProtocol | ||
|
||
private let logger = Logger( | ||
subsystem: "io.swiftpackage.ListMaker", | ||
category: "LibraryPackage" | ||
) | ||
private let logger = Logger( | ||
subsystem: "io.swiftpackage.ListMaker", | ||
category: "LibraryPackage" | ||
) | ||
|
||
public init(fileManager: FileManagerProtocol = FileManager.default) { | ||
self.fileManager = fileManager | ||
} | ||
public init(fileManager: FileManagerProtocol = FileManager.default) { | ||
self.fileManager = fileManager | ||
} | ||
|
||
public func makeList() throws -> [String] { | ||
var fileNames = [String]() | ||
public func makeList() throws -> [String] { | ||
var fileNames = [String]() | ||
|
||
let currentFilePath = #file | ||
let currentFileURL = URL(filePath: currentFilePath, directoryHint: .inferFromPath) | ||
let sourceDirectoryURL = currentFileURL.deletingLastPathComponent() | ||
let currentFilePath = #file | ||
let currentFileURL = URL(filePath: currentFilePath, directoryHint: .inferFromPath) | ||
let sourceDirectoryURL = currentFileURL.deletingLastPathComponent() | ||
|
||
do { | ||
let contents = try fileManager.contentsOfDirectory( | ||
at: sourceDirectoryURL, | ||
includingPropertiesForKeys: nil, | ||
options: [] | ||
) | ||
do { | ||
let contents = try fileManager.contentsOfDirectory( | ||
at: sourceDirectoryURL, | ||
includingPropertiesForKeys: nil, | ||
options: [] | ||
) | ||
|
||
fileNames = contents.map(\.lastPathComponent) | ||
fileNames = contents.map(\.lastPathComponent) | ||
|
||
} catch { | ||
logger.error("Error occurred: \(error.localizedDescription)") | ||
throw error | ||
} | ||
} catch { | ||
logger.error("Error occurred: \(error.localizedDescription)") | ||
throw error | ||
} | ||
|
||
let currentFileName = URL( | ||
filePath: currentFilePath, | ||
directoryHint: .inferFromPath | ||
).lastPathComponent | ||
let currentFileName = URL( | ||
filePath: currentFilePath, | ||
directoryHint: .inferFromPath | ||
).lastPathComponent | ||
|
||
let intermediateResult = fileNames.filter { $0 != currentFileName } | ||
let filesBySuffix = filteredBySuffix(intermediateResult) | ||
return stripFileNamesOfSuffix(filesBySuffix) | ||
} | ||
let intermediateResult = fileNames.filter { $0 != currentFileName } | ||
let filesBySuffix = filteredBySuffix(intermediateResult) | ||
return stripFileNamesOfSuffix(filesBySuffix) | ||
} | ||
|
||
private func filteredBySuffix(_ fileNamesList: [String]) -> [String] { | ||
fileNamesList.filter { str in | ||
str.hasSuffix("Model.swift") | ||
private func filteredBySuffix(_ fileNamesList: [String]) -> [String] { | ||
fileNamesList.filter { str in | ||
str.hasSuffix("Model.swift") | ||
} | ||
} | ||
} | ||
|
||
private func stripFileNamesOfSuffix(_ fileNamesList: [String]) -> [String] { | ||
fileNamesList.map { str in | ||
str.replacingOccurrences(of: ".swift", with: "", options: .regularExpression) | ||
private func stripFileNamesOfSuffix(_ fileNamesList: [String]) -> [String] { | ||
fileNamesList.map { str in | ||
str.replacingOccurrences(of: ".swift", with: "", options: .regularExpression) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters