@@ -74,7 +74,7 @@ package extension SwiftPackageDescription {
7474
7575 struct Product : Codable , Equatable , Hashable {
7676
77- // TODO: Add `rule ` property
77+ // TODO: Add `type ` property
7878
7979 package let name : String
8080 package let targets : [ String ]
@@ -179,28 +179,31 @@ package extension SwiftPackageDescription {
179179 package let productDependencies : [ String ] ?
180180 /// `.target(name: ...) dependency
181181 package let targetDependencies : [ String ] ?
182-
182+ // TODO: check this in the SwiftPackageFileAnalyzer
183+ package let resources : [ Resource ] ?
184+
183185 // Ignoring following properties for now as they are not handled in the `PackageAnalyzer`
184186 // and thus would produce changes that are not visible
185187 //
186188 // let productMemberships: [String]?
187189 // let sources: [String]
188- // let resources: [Resource]?
189190
190191 init (
191192 name: String ,
192193 type: TargetType ,
193194 path: String ,
194195 moduleType: ModuleType ,
195196 productDependencies: [ String ] ? = nil ,
196- targetDependencies: [ String ] ? = nil
197+ targetDependencies: [ String ] ? = nil ,
198+ resources: [ Resource ] ? = nil
197199 ) {
198200 self . name = name
199201 self . type = type
200202 self . path = path
201203 self . moduleType = moduleType
202204 self . productDependencies = productDependencies
203205 self . targetDependencies = targetDependencies
206+ self . resources = resources
204207 }
205208
206209 enum CodingKeys : String , CodingKey {
@@ -210,6 +213,7 @@ package extension SwiftPackageDescription {
210213 case targetDependencies = " target_dependencies "
211214 case type
212215 case path
216+ case resources
213217 }
214218 }
215219}
@@ -257,9 +261,77 @@ extension SwiftPackageDescription.Target: CustomStringConvertible {
257261package extension SwiftPackageDescription . Target {
258262
259263 struct Resource : Codable , Equatable {
264+ package let path : String
265+ package let rule : Rule
266+ }
267+ }
268+
269+ package extension SwiftPackageDescription . Target . Resource {
270+
271+ enum Rule : Codable , Equatable {
272+ case copy
273+ case embeddInCode
274+ case process( [ String : String ] )
275+
276+ package init ( from decoder: any Decoder ) throws {
277+
278+ enum RuleError : Error {
279+ case unsupportedRule
280+ }
281+
282+ let container = try decoder. container ( keyedBy: CodingKeys . self)
283+
284+ if ( try ? container. decode ( [ String : String ] . self, forKey: . copy) ) != nil {
285+ self = . copy
286+ return
287+ }
288+
289+ if ( try ? container. decode ( [ String : String ] . self, forKey: . embeddInCode) ) != nil {
290+ self = . embeddInCode
291+ return
292+ }
293+
294+ if let metadata = try ? container. decode ( [ String : String ] . self, forKey: . process) {
295+ self = . process( metadata)
296+ return
297+ }
298+
299+ throw RuleError . unsupportedRule
300+ }
301+
302+ package func encode( to encoder: any Encoder ) throws {
303+ var container = encoder. container ( keyedBy: CodingKeys . self)
304+
305+ switch self {
306+ case . copy:
307+ try container. encode ( [ : ] as [ String : String ] , forKey: . copy)
308+ case . embeddInCode:
309+ try container. encode ( [ : ] as [ String : String ] , forKey: . embeddInCode)
310+ case let . process( metadata) :
311+ try container. encode ( metadata, forKey: . process)
312+ }
313+ }
314+
315+ enum CodingKeys : String , CodingKey {
316+ case copy
317+ case embeddInCode = " embed_in_code "
318+ case process
319+ }
320+ }
321+ }
260322
261- // TODO: Add `rule` property
323+ extension SwiftPackageDescription . Target . Resource . Rule : CustomStringConvertible {
262324
263- package let path : String
325+ package var description : String {
326+ return switch self {
327+ case . copy: " copy "
328+ case . embeddInCode: " embeddInCode "
329+ case let . process( metadata) :
330+ if let localization = metadata [ " localization " ] {
331+ " process (localization: \( localization) ) "
332+ } else {
333+ " process "
334+ }
335+ }
264336 }
265337}
0 commit comments