@@ -19,7 +19,6 @@ import PackagePlugin
1919
2020// There are a few things to do
2121// - the stencil template file should be in the plugin directory, and be accessed from there
22- // - XCode way needs to adopt paths ... find the common path from the model files, and work there
2322
2423/// This is used when the command plugin is used from a Swift package
2524/// (so when running via the swift package plugin command).
@@ -28,7 +27,36 @@ import PackagePlugin
2827@main
2928struct GeneratorCommand : CommandPlugin {
3029
31- func runGenerator( generator: PluginContext . Tool , args: [ String ] ) {
30+ // Path should match with CocoaPods setup for easy migration
31+ private func buildModelJsonFilePath( targetName: String ) -> String {
32+ return " model- \( targetName) .json "
33+ }
34+
35+ // Path should match with CocoaPods setup for easy migration
36+ private func buildEntityInfoFilePath( targetName: String ) -> String {
37+ return " generated/EntityInfo- \( targetName) .generated.swift "
38+ }
39+
40+ private func runGenerator(
41+ generator: PluginContext . Tool , targetPath: Path , codeFilePath: String , modelFilePath: String
42+ ) {
43+ let modelFileTargetPath = targetPath. appending ( modelFilePath) . string
44+ let codeFileTargetPath = targetPath. appending ( codeFilePath) . string
45+
46+ // Specify --sources for Xcode project setup as well, Sourcery does not seem able to detect Xcode project
47+ let args : [ String ] = [
48+ " --sources " , targetPath. string,
49+ " --model-json " , modelFileTargetPath,
50+ " --output " , codeFileTargetPath,
51+ " --disableCache " ,
52+ " --verbose " ,
53+ " --no-statistics " ,
54+ ]
55+
56+ runGenerator ( generator: generator, args: args)
57+ }
58+
59+ private func runGenerator( generator: PluginContext . Tool , args: [ String ] ) {
3260
3361 let generatorUrl = URL ( fileURLWithPath: generator. path. string)
3462
@@ -117,18 +145,11 @@ struct GeneratorCommand: CommandPlugin {
117145
118146 let targetPath = target. directory
119147 print ( " Generating ObjectBox code for \( target. name) at \( targetPath) " )
120-
121- let args : [ String ] = [
122- " --sources " , targetPath. string,
123- " --model-json " , targetPath. appending ( " ObjectBox-models.json " ) . string,
124- " --output " , targetPath. appending ( " ObjectBox-generated " ) . string,
125- " --disableCache " ,
126- " --verbose " ,
127- " --no-statistics " ,
128- ]
129-
130- runGenerator ( generator: tool, args: args)
131-
148+ let codeFilePath = buildEntityInfoFilePath ( targetName: target. name)
149+ let modelFilePath = buildModelJsonFilePath ( targetName: target. name)
150+ runGenerator (
151+ generator: tool, targetPath: targetPath, codeFilePath: codeFilePath,
152+ modelFilePath: modelFilePath)
132153 }
133154 }
134155}
@@ -183,26 +204,19 @@ struct GeneratorCommand: CommandPlugin {
183204 }
184205
185206 let targetPath = context. xcodeProject. directory
186- let outputFolder = targetPath. appending ( " ObjectBox-generated " ) . string
187- let jsonModel = targetPath. appending ( " ObjectBox-models.json " ) . string
188-
189- let args : [ String ] =
190- sourcesArgs + [
191- " --model-json " , jsonModel,
192- " --output " , outputFolder,
193- " --disableCache " ,
194- " --verbose " ,
195- " --no-statistics " ,
196- ]
207+ let codeFilePath = buildEntityInfoFilePath ( targetName: targetName)
208+ let modelFilePath = buildModelJsonFilePath ( targetName: targetName)
197209
198- runGenerator ( generator: tool, args: args)
210+ runGenerator (
211+ generator: tool, targetPath: targetPath, codeFilePath: codeFilePath,
212+ modelFilePath: modelFilePath)
199213
200214 // TODO Add the generated files to the Xcode project
201215 Diagnostics . remark (
202- " ! Don't forget to add the generated source file in 'ObjectBox-generated/EntityInfo.generated.swift ' to the project, and to git if you want to keep it "
216+ " ! Add the generated source file in ' \( codeFilePath ) ' to the project and version control "
203217 )
204218 Diagnostics . remark (
205- " ! Don't forget to add the generated model file in 'ObjectBox-models.json ' to git , this is important for the ObjectBox model generation "
219+ " ! Add the generated model file in ' \( modelFilePath ) ' to version control , this is important for ObjectBox model generation "
206220 )
207221
208222 }
0 commit comments