diff --git a/Package.resolved b/Package.resolved index 3c1f3b0..3eb3ce4 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,6 +1,15 @@ { "object": { "pins": [ + { + "package": "Files", + "repositoryURL": "https://github.com/JohnSundell/Files", + "state": { + "branch": null, + "revision": "22fe84797d499ffca911ccd896b34efaf06a50b9", + "version": "4.1.1" + } + }, { "package": "Yams", "repositoryURL": "https://github.com/jpsim/Yams.git", diff --git a/Package.swift b/Package.swift index d3a5f92..4e6bfdb 100644 --- a/Package.swift +++ b/Package.swift @@ -6,14 +6,15 @@ import PackageDescription let package = Package( name: "Downstream", dependencies: [ - .package(url: "https://github.com/jpsim/Yams.git", from: "4.0.0") + .package(url: "https://github.com/jpsim/Yams.git", from: "4.0.0"), + .package(url: "https://github.com/JohnSundell/Files", from: "4.0.0") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "Downstream", - dependencies: ["Yams"]), + dependencies: ["Yams", "Files"]), .testTarget( name: "DownstreamTests", dependencies: ["Downstream"]), diff --git a/Sources/Downstream/downstream.yml b/Sources/Downstream/downstream.yml new file mode 100644 index 0000000..d2d7035 --- /dev/null +++ b/Sources/Downstream/downstream.yml @@ -0,0 +1,2 @@ +associations: + main.swift: https://github.com/JohnSundell/Files/blob/master/Sources/Files.swift diff --git a/Sources/Downstream/main.swift b/Sources/Downstream/main.swift index ae12d66..77110e6 100644 --- a/Sources/Downstream/main.swift +++ b/Sources/Downstream/main.swift @@ -6,6 +6,7 @@ // import Yams +import Files let yaml = """ associations: @@ -17,5 +18,22 @@ associations: let decoder = YAMLDecoder() let associations = try! decoder.decode(AssociationsFile.self, from: yaml) -print(associations) +//print(associations) +let fileList = CommandLine.arguments[1...] +let todos = fileList.compactMap { filePath -> String? in + let changedFile = try! File(path: filePath) + + 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] + } + + return nil +} + +print(todos)