BarredEwe / Prefire

🔥 A library based on SwiftUI Preview, for easy generation: Playbook view, Snapshot and Accessibility tests
Apache License 2.0
290 stars 18 forks source link

Adding sources to the 'prefire.yml' configuration #61

Closed BarredEwe closed 5 months ago

BarredEwe commented 5 months ago

Short description 📝

Adding the ability to specify sources in the prefire.yml file.

Solution 📦

The easiest thing to do is to make it possible to pass an array of strings with paths through a configuration file. That's what I did.

Example of use:

test_configuration:
  - sources:
      - ${PROJECT_DIR}/Sources/
      - ${PROJECT_DIR}/Scripts/File.swift

Implementation 👩‍💻👨‍💻

Added a new key for parsing:

extension Config {
    enum Keys: String {
        case sources
        // ...

If the path to a directory is passed, you need to find all .swift files inside it. For this purpose I wrote a simple but not the most optimal implementation of search:

let contents = try contentsOfDirectory(atPath: path)
var paths: [String] = []

for item in contents {
    let itemPath = "\(path)/\(item)"
    if item.hasSuffix(".swift") {
        paths.append(itemPath)
    }

    if (try? contentsOfDirectory(atPath: itemPath)) != nil {
        paths += listFiles(atPath: itemPath)
    }
}

return paths

After, passed the resulting array of strings to sourcery and macro search.