Skip to content

Commit

Permalink
Appears to be working
Browse files Browse the repository at this point in the history
  • Loading branch information
twof committed Oct 23, 2020
1 parent bfe1d25 commit fe3c9c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Sources/Downstream/Associations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
//

struct AssociationsFile: Codable {
let associations: [String: String]
let associations: [String: [String]]
}
3 changes: 2 additions & 1 deletion Sources/Downstream/downstream.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
associations:
main.swift: https://github.com/JohnSundell/Files/blob/master/Sources/Files.swift
main.swift:
- https://github.com/JohnSundell/Files/blob/master/Sources/Files.swift
35 changes: 20 additions & 15 deletions Sources/Downstream/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,38 @@

import Yams
import Files

let yaml = """
associations:
name: Martin D'vloper
job: Developer
skill: Elite
"""
import Foundation

let decoder = YAMLDecoder()
let associations = try! decoder.decode(AssociationsFile.self, from: yaml)

//print(associations)

let fileList = CommandLine.arguments[1...]
let todos = fileList.compactMap { filePath -> String? in
let todos = fileList.flatMap { filePath -> [String] in
let changedFile = try! File(path: filePath)

// print("filePath", filePath)
// print("parent", changedFile.parent?.path)
// print("yaml", try? changedFile.parent?.file(named: "downstream.yml").read())
// let associationsData = (try? changedFile.parent?.file(named: "downstream.yml").read() as? Data).flatMap { try? decoder.decode(AssociationsFile.self, from: $0) }
// print("associations", associationsData)

if
let parent = changedFile.parent,
let downsteamYML = try? parent.file(named: "downstream.yml").read(),
let associationsFile = try? decoder.decode(AssociationsFile.self, from: downsteamYML)
{
let fileName = changedFile.path(relativeTo: parent)
return associationsFile.associations[fileName]
let fileName = changedFile.name
// print("relativeFileName", fileName)
let newTodos = associationsFile.associations[fileName] ?? []
return newTodos.map {
"Our records indicate that you may need to update the docs at \($0) because changes were made to \(fileName)"
}
}

return nil
return []
}

print(todos)
if !todos.isEmpty {
todos.forEach {
print($0)
}
}

0 comments on commit fe3c9c1

Please sign in to comment.