99import Foundation
1010import PackagePlugin
1111
12+ // Declared to build
13+ public struct JellyfinClient { }
14+
1215@main
1316struct Plugin : CommandPlugin {
1417
@@ -27,6 +30,9 @@ struct Plugin: CommandPlugin {
2730 // Move patch files
2831 try await addTaskTriggerType ( context: context)
2932
33+ // Create the version SDK
34+ try await generateVersionFile ( context: context)
35+
3036 try await lint ( context: context)
3137
3238 try await deletePatchedSchema ( context: context)
@@ -134,7 +140,7 @@ struct Plugin: CommandPlugin {
134140 . directory
135141 . appending ( [ " Sources " , " Entities " , " RemoteSearchResult.swift " ] )
136142
137- let contents = try String ( contentsOfFile: filePath. string)
143+ let contents = try String ( contentsOfFile: filePath. string, encoding : . utf8 )
138144 var lines = contents
139145 . split ( separator: " \n " )
140146 . map { String ( $0) }
@@ -154,7 +160,7 @@ struct Plugin: CommandPlugin {
154160 . directory
155161 . appending ( [ " Sources " , " Extensions " , " AnyJSON.swift " ] )
156162
157- let contents = try String ( contentsOfFile: filePath. string)
163+ let contents = try String ( contentsOfFile: filePath. string, encoding : . utf8 )
158164 var lines = contents
159165 . split ( separator: " \n " )
160166 . map { String ( $0) }
@@ -195,11 +201,39 @@ struct Plugin: CommandPlugin {
195201 . directory
196202 . appending ( [ " Sources " , " Entities " , " GroupUpdate.swift " ] )
197203
198- let contents = try String ( contentsOfFile: filePath. string)
204+ let contents = try String ( contentsOfFile: filePath. string, encoding : . utf8 )
199205 . replacingOccurrences ( of: " Type " , with: " _Type " )
200206
201207 try contents
202208 . data ( using: . utf8) ?
203209 . write ( to: URL ( fileURLWithPath: filePath. string) )
204210 }
211+
212+ // TODO: Remove if/when fixed within CreateAPI
213+ // Adds JellyfinClient.sdkVersion
214+ private func generateVersionFile( context: PluginContext ) async throws {
215+ let schema = try await parseOriginalSchema ( context: context)
216+
217+ guard case let . object( file) = schema else { return }
218+ guard case let . object( info) = file [ " info " ] else { return }
219+ guard let version = info [ " version " ] ? . value as? String else { return }
220+
221+ let sourceFilePath = context
222+ . package
223+ . directory
224+ . appending ( [ " Plugins " , " CreateAPI " , " PatchFiles " , " JellyfinClient+Version.swift " ] )
225+
226+ var contents = try String ( contentsOfFile: sourceFilePath. string, encoding: . utf8)
227+
228+ contents. replace ( #/<SDK_VERSION>/# , with: version)
229+
230+ let destinationFilePath = context
231+ . package
232+ . directory
233+ . appending ( [ " Sources " , " Extensions " , " JellyfinClient+Version.swift " ] )
234+
235+ try contents
236+ . data ( using: . utf8) ?
237+ . write ( to: URL ( fileURLWithPath: destinationFilePath. string) )
238+ }
205239}
0 commit comments