@@ -74,7 +74,7 @@ package extension SwiftPackageDescription {
74
74
75
75
struct Product : Codable , Equatable , Hashable {
76
76
77
- // TODO: Add `rule ` property
77
+ // TODO: Add `type ` property
78
78
79
79
package let name : String
80
80
package let targets : [ String ]
@@ -179,28 +179,31 @@ package extension SwiftPackageDescription {
179
179
package let productDependencies : [ String ] ?
180
180
/// `.target(name: ...) dependency
181
181
package let targetDependencies : [ String ] ?
182
-
182
+ // TODO: check this in the SwiftPackageFileAnalyzer
183
+ package let resources : [ Resource ] ?
184
+
183
185
// Ignoring following properties for now as they are not handled in the `PackageAnalyzer`
184
186
// and thus would produce changes that are not visible
185
187
//
186
188
// let productMemberships: [String]?
187
189
// let sources: [String]
188
- // let resources: [Resource]?
189
190
190
191
init (
191
192
name: String ,
192
193
type: TargetType ,
193
194
path: String ,
194
195
moduleType: ModuleType ,
195
196
productDependencies: [ String ] ? = nil ,
196
- targetDependencies: [ String ] ? = nil
197
+ targetDependencies: [ String ] ? = nil ,
198
+ resources: [ Resource ] ? = nil
197
199
) {
198
200
self . name = name
199
201
self . type = type
200
202
self . path = path
201
203
self . moduleType = moduleType
202
204
self . productDependencies = productDependencies
203
205
self . targetDependencies = targetDependencies
206
+ self . resources = resources
204
207
}
205
208
206
209
enum CodingKeys : String , CodingKey {
@@ -210,6 +213,7 @@ package extension SwiftPackageDescription {
210
213
case targetDependencies = " target_dependencies "
211
214
case type
212
215
case path
216
+ case resources
213
217
}
214
218
}
215
219
}
@@ -257,9 +261,77 @@ extension SwiftPackageDescription.Target: CustomStringConvertible {
257
261
package extension SwiftPackageDescription . Target {
258
262
259
263
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
+ }
260
322
261
- // TODO: Add `rule` property
323
+ extension SwiftPackageDescription . Target . Resource . Rule : CustomStringConvertible {
262
324
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
+ }
264
336
}
265
337
}
0 commit comments