expo-targets 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/.eslintrc.js +2 -0
  2. package/README.md +244 -0
  3. package/android/build.gradle +22 -0
  4. package/android/src/main/java/expo/modules/targets/ExpoTargetsLogger.kt +98 -0
  5. package/android/src/main/java/expo/modules/targets/ExpoTargetsReceiver.kt +136 -0
  6. package/android/src/main/java/expo/modules/targets/ExpoTargetsRemoteViewsProvider.kt +72 -0
  7. package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetProvider.kt +47 -0
  8. package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetSync.kt +78 -0
  9. package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetUpdateReceiver.kt +30 -0
  10. package/android/src/main/java/expo/modules/targets/extension/ExpoTargetsExtensionModule.kt +27 -0
  11. package/android/src/main/java/expo/modules/targets/messages/ExpoTargetsMessagesModule.kt +40 -0
  12. package/android/src/main/java/expo/modules/targets/storage/ExpoTargetsStorageModule.kt +119 -0
  13. package/app.plugin.js +1 -0
  14. package/build/metro/src/index.d.ts +2 -0
  15. package/build/metro/src/index.d.ts.map +1 -0
  16. package/build/metro/src/index.js +6 -0
  17. package/build/metro/src/index.js.map +1 -0
  18. package/build/metro/src/withTargetsMetro.d.ts +6 -0
  19. package/build/metro/src/withTargetsMetro.d.ts.map +1 -0
  20. package/build/metro/src/withTargetsMetro.js +171 -0
  21. package/build/metro/src/withTargetsMetro.js.map +1 -0
  22. package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts +7 -0
  23. package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts.map +1 -0
  24. package/build/plugin/src/android/config-plugins/withAndroidColors.js +56 -0
  25. package/build/plugin/src/android/config-plugins/withAndroidColors.js.map +1 -0
  26. package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts +7 -0
  27. package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts.map +1 -0
  28. package/build/plugin/src/android/config-plugins/withAndroidManifest.js +70 -0
  29. package/build/plugin/src/android/config-plugins/withAndroidManifest.js.map +1 -0
  30. package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts +7 -0
  31. package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts.map +1 -0
  32. package/build/plugin/src/android/config-plugins/withAndroidModule.js +41 -0
  33. package/build/plugin/src/android/config-plugins/withAndroidModule.js.map +1 -0
  34. package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts +7 -0
  35. package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts.map +1 -0
  36. package/build/plugin/src/android/config-plugins/withAndroidResources.js +75 -0
  37. package/build/plugin/src/android/config-plugins/withAndroidResources.js.map +1 -0
  38. package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts +28 -0
  39. package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts.map +1 -0
  40. package/build/plugin/src/android/config-plugins/withAndroidTarget.js +28 -0
  41. package/build/plugin/src/android/config-plugins/withAndroidTarget.js.map +1 -0
  42. package/build/plugin/src/android/config-plugins/withGradleModule.d.ts +7 -0
  43. package/build/plugin/src/android/config-plugins/withGradleModule.d.ts.map +1 -0
  44. package/build/plugin/src/android/config-plugins/withGradleModule.js +86 -0
  45. package/build/plugin/src/android/config-plugins/withGradleModule.js.map +1 -0
  46. package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts +7 -0
  47. package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts.map +1 -0
  48. package/build/plugin/src/android/config-plugins/withGradleSettings.js +23 -0
  49. package/build/plugin/src/android/config-plugins/withGradleSettings.js.map +1 -0
  50. package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts +7 -0
  51. package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts.map +1 -0
  52. package/build/plugin/src/android/withAndroidAppBuildGradle.js +31 -0
  53. package/build/plugin/src/android/withAndroidAppBuildGradle.js.map +1 -0
  54. package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts +3 -0
  55. package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts.map +1 -0
  56. package/build/plugin/src/android/withAndroidKotlinGradleProperty.js +24 -0
  57. package/build/plugin/src/android/withAndroidKotlinGradleProperty.js.map +1 -0
  58. package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts +3 -0
  59. package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts.map +1 -0
  60. package/build/plugin/src/android/withAndroidProjectKotlinVersion.js +27 -0
  61. package/build/plugin/src/android/withAndroidProjectKotlinVersion.js.map +1 -0
  62. package/build/plugin/src/android/withAndroidTarget.d.ts +10 -0
  63. package/build/plugin/src/android/withAndroidTarget.d.ts.map +1 -0
  64. package/build/plugin/src/android/withAndroidTarget.js +22 -0
  65. package/build/plugin/src/android/withAndroidTarget.js.map +1 -0
  66. package/build/plugin/src/android/withAndroidWidget.d.ts +13 -0
  67. package/build/plugin/src/android/withAndroidWidget.d.ts.map +1 -0
  68. package/build/plugin/src/android/withAndroidWidget.js +564 -0
  69. package/build/plugin/src/android/withAndroidWidget.js.map +1 -0
  70. package/build/plugin/src/config.d.ts +141 -0
  71. package/build/plugin/src/config.d.ts.map +1 -0
  72. package/build/plugin/src/config.js +54 -0
  73. package/build/plugin/src/config.js.map +1 -0
  74. package/build/plugin/src/index.d.ts +9 -0
  75. package/build/plugin/src/index.d.ts.map +1 -0
  76. package/build/plugin/src/index.js +11 -0
  77. package/build/plugin/src/index.js.map +1 -0
  78. package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts +11 -0
  79. package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts.map +1 -0
  80. package/build/plugin/src/ios/config-plugins/withEntitlements.js +49 -0
  81. package/build/plugin/src/ios/config-plugins/withEntitlements.js.map +1 -0
  82. package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts +17 -0
  83. package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts.map +1 -0
  84. package/build/plugin/src/ios/config-plugins/withIOSTarget.js +152 -0
  85. package/build/plugin/src/ios/config-plugins/withIOSTarget.js.map +1 -0
  86. package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts +8 -0
  87. package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts.map +1 -0
  88. package/build/plugin/src/ios/config-plugins/withIosColorset.js +25 -0
  89. package/build/plugin/src/ios/config-plugins/withIosColorset.js.map +1 -0
  90. package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts +8 -0
  91. package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts.map +1 -0
  92. package/build/plugin/src/ios/config-plugins/withIosStickerPack.js +52 -0
  93. package/build/plugin/src/ios/config-plugins/withIosStickerPack.js.map +1 -0
  94. package/build/plugin/src/ios/config-plugins/withPodfile.d.ts +12 -0
  95. package/build/plugin/src/ios/config-plugins/withPodfile.d.ts.map +1 -0
  96. package/build/plugin/src/ios/config-plugins/withPodfile.js +162 -0
  97. package/build/plugin/src/ios/config-plugins/withPodfile.js.map +1 -0
  98. package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts +15 -0
  99. package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts.map +1 -0
  100. package/build/plugin/src/ios/config-plugins/withXcodeChanges.js +646 -0
  101. package/build/plugin/src/ios/config-plugins/withXcodeChanges.js.map +1 -0
  102. package/build/plugin/src/ios/target.d.ts +41 -0
  103. package/build/plugin/src/ios/target.d.ts.map +1 -0
  104. package/build/plugin/src/ios/target.js +574 -0
  105. package/build/plugin/src/ios/target.js.map +1 -0
  106. package/build/plugin/src/ios/utils/asset.d.ts +60 -0
  107. package/build/plugin/src/ios/utils/asset.d.ts.map +1 -0
  108. package/build/plugin/src/ios/utils/asset.js +375 -0
  109. package/build/plugin/src/ios/utils/asset.js.map +1 -0
  110. package/build/plugin/src/ios/utils/file.d.ts +33 -0
  111. package/build/plugin/src/ios/utils/file.d.ts.map +1 -0
  112. package/build/plugin/src/ios/utils/file.js +88 -0
  113. package/build/plugin/src/ios/utils/file.js.map +1 -0
  114. package/build/plugin/src/ios/utils/index.d.ts +12 -0
  115. package/build/plugin/src/ios/utils/index.d.ts.map +1 -0
  116. package/build/plugin/src/ios/utils/index.js +38 -0
  117. package/build/plugin/src/ios/utils/index.js.map +1 -0
  118. package/build/plugin/src/ios/utils/paths.d.ts +128 -0
  119. package/build/plugin/src/ios/utils/paths.d.ts.map +1 -0
  120. package/build/plugin/src/ios/utils/paths.js +141 -0
  121. package/build/plugin/src/ios/utils/paths.js.map +1 -0
  122. package/build/plugin/src/ios/utils/plist.d.ts +29 -0
  123. package/build/plugin/src/ios/utils/plist.d.ts.map +1 -0
  124. package/build/plugin/src/ios/utils/plist.js +114 -0
  125. package/build/plugin/src/ios/utils/plist.js.map +1 -0
  126. package/build/plugin/src/ios/utils/podfile.d.ts +82 -0
  127. package/build/plugin/src/ios/utils/podfile.d.ts.map +1 -0
  128. package/build/plugin/src/ios/utils/podfile.js +408 -0
  129. package/build/plugin/src/ios/utils/podfile.js.map +1 -0
  130. package/build/plugin/src/ios/utils/reactNativeSwift.d.ts +11 -0
  131. package/build/plugin/src/ios/utils/reactNativeSwift.d.ts.map +1 -0
  132. package/build/plugin/src/ios/utils/reactNativeSwift.js +263 -0
  133. package/build/plugin/src/ios/utils/reactNativeSwift.js.map +1 -0
  134. package/build/plugin/src/ios/utils/xcode.d.ts +185 -0
  135. package/build/plugin/src/ios/utils/xcode.d.ts.map +1 -0
  136. package/build/plugin/src/ios/utils/xcode.js +706 -0
  137. package/build/plugin/src/ios/utils/xcode.js.map +1 -0
  138. package/build/plugin/src/logger.d.ts +10 -0
  139. package/build/plugin/src/logger.d.ts.map +1 -0
  140. package/build/plugin/src/logger.js +62 -0
  141. package/build/plugin/src/logger.js.map +1 -0
  142. package/build/plugin/src/parseTargetConfig.d.ts +3 -0
  143. package/build/plugin/src/parseTargetConfig.d.ts.map +1 -0
  144. package/build/plugin/src/parseTargetConfig.js +113 -0
  145. package/build/plugin/src/parseTargetConfig.js.map +1 -0
  146. package/build/plugin/src/withTargetsDir.d.ts +6 -0
  147. package/build/plugin/src/withTargetsDir.d.ts.map +1 -0
  148. package/build/plugin/src/withTargetsDir.js +90 -0
  149. package/build/plugin/src/withTargetsDir.js.map +1 -0
  150. package/build/src/Target.d.ts +43 -0
  151. package/build/src/Target.d.ts.map +1 -0
  152. package/build/src/Target.js +128 -0
  153. package/build/src/Target.js.map +1 -0
  154. package/build/src/index.d.ts +9 -0
  155. package/build/src/index.d.ts.map +1 -0
  156. package/build/src/index.js +27 -0
  157. package/build/src/index.js.map +1 -0
  158. package/build/src/modules/extension/index.d.ts +18 -0
  159. package/build/src/modules/extension/index.d.ts.map +1 -0
  160. package/build/src/modules/extension/index.js +44 -0
  161. package/build/src/modules/extension/index.js.map +1 -0
  162. package/build/src/modules/messages/index.d.ts +40 -0
  163. package/build/src/modules/messages/index.d.ts.map +1 -0
  164. package/build/src/modules/messages/index.js +94 -0
  165. package/build/src/modules/messages/index.js.map +1 -0
  166. package/build/src/modules/storage/index.d.ts +16 -0
  167. package/build/src/modules/storage/index.d.ts.map +1 -0
  168. package/build/src/modules/storage/index.js +122 -0
  169. package/build/src/modules/storage/index.js.map +1 -0
  170. package/expo-module.config.json +17 -0
  171. package/ios/ExpoTargetsExtension.podspec +23 -0
  172. package/ios/ExpoTargetsExtensionModule.swift +181 -0
  173. package/ios/ExpoTargetsMessages.podspec +23 -0
  174. package/ios/ExpoTargetsMessagesModule.swift +267 -0
  175. package/ios/ExpoTargetsStorage.podspec +23 -0
  176. package/ios/ExpoTargetsStorageModule.swift +91 -0
  177. package/ios/Tests/.swiftlint.yml +52 -0
  178. package/ios/Tests/Helpers/MockExtensionContext.swift +58 -0
  179. package/ios/Tests/Helpers/MockUserDefaults.swift +70 -0
  180. package/ios/Tests/Helpers/MockWidgetCenter.swift +71 -0
  181. package/ios/Tests/Helpers/TestHelpers.swift +90 -0
  182. package/ios/Tests/Integration/TargetIntegrationTests.swift +478 -0
  183. package/ios/Tests/Main/AllTests.swift +80 -0
  184. package/ios/Tests/Package.swift +66 -0
  185. package/ios/Tests/Performance/StoragePerformanceTests.swift +461 -0
  186. package/ios/Tests/Unit/Extension/ExpoTargetsExtensionModuleTests.swift +501 -0
  187. package/ios/Tests/Unit/Storage/ExpoTargetsStorageModuleTests.swift +578 -0
  188. package/ios/Tests/Unit/Template/ShareExtensionTemplateTests.swift +421 -0
  189. package/ios/Tests/XCTestPlan.xctestplan +87 -0
  190. package/metro/src/index.ts +1 -0
  191. package/metro/src/withTargetsMetro.ts +247 -0
  192. package/metro/tsconfig.build.json +9 -0
  193. package/package.json +74 -0
  194. package/plugin/src/android/withAndroidAppBuildGradle.ts +34 -0
  195. package/plugin/src/android/withAndroidTarget.ts +26 -0
  196. package/plugin/src/android/withAndroidWidget.ts +778 -0
  197. package/plugin/src/config.ts +255 -0
  198. package/plugin/src/index.ts +19 -0
  199. package/plugin/src/ios/config-plugins/withEntitlements.ts +69 -0
  200. package/plugin/src/ios/config-plugins/withIOSTarget.ts +179 -0
  201. package/plugin/src/ios/config-plugins/withIosColorset.ts +29 -0
  202. package/plugin/src/ios/config-plugins/withIosStickerPack.ts +65 -0
  203. package/plugin/src/ios/config-plugins/withPodfile.ts +238 -0
  204. package/plugin/src/ios/config-plugins/withXcodeChanges.ts +891 -0
  205. package/plugin/src/ios/target.ts +668 -0
  206. package/plugin/src/ios/templates/MessagesViewController.swift +120 -0
  207. package/plugin/src/ios/templates/ReactNativeViewController.swift +240 -0
  208. package/plugin/src/ios/templates/action-extension-data.swift +106 -0
  209. package/plugin/src/ios/templates/clip-extension-data.swift +28 -0
  210. package/plugin/src/ios/templates/messages-extension-data.swift +28 -0
  211. package/plugin/src/ios/templates/share-extension-data.swift +113 -0
  212. package/plugin/src/ios/utils/asset.ts +490 -0
  213. package/plugin/src/ios/utils/file.ts +80 -0
  214. package/plugin/src/ios/utils/index.ts +12 -0
  215. package/plugin/src/ios/utils/paths.ts +253 -0
  216. package/plugin/src/ios/utils/plist.ts +101 -0
  217. package/plugin/src/ios/utils/podfile.ts +534 -0
  218. package/plugin/src/ios/utils/reactNativeSwift.ts +283 -0
  219. package/plugin/src/ios/utils/xcode.ts +989 -0
  220. package/plugin/src/logger.ts +63 -0
  221. package/plugin/src/parseTargetConfig.ts +115 -0
  222. package/plugin/src/types/normalize-colors.d.ts +3 -0
  223. package/plugin/src/withTargetsDir.ts +120 -0
  224. package/plugin/tsconfig.build.json +9 -0
  225. package/plugin/tsconfig.json +9 -0
  226. package/src/Target.ts +239 -0
  227. package/src/index.ts +52 -0
  228. package/src/modules/extension/index.ts +54 -0
  229. package/src/modules/messages/index.ts +124 -0
  230. package/src/modules/storage/index.ts +126 -0
  231. package/tsconfig.json +8 -0
@@ -0,0 +1,283 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+
4
+ import type { ExtensionType } from '../../config';
5
+
6
+ const TEMPLATES_DIR = path.join(__dirname, '..', 'templates');
7
+
8
+ export interface ReactNativeViewControllerOptions {
9
+ type: ExtensionType;
10
+ moduleName: string;
11
+ targetName: string;
12
+ preprocessingFile?: string;
13
+ entry?: string;
14
+ }
15
+
16
+ function readTemplate(filename: string): string {
17
+ const templatePath = path.join(TEMPLATES_DIR, filename);
18
+ return fs.readFileSync(templatePath, 'utf-8');
19
+ }
20
+
21
+ function getExtensionDataForType(
22
+ type: ExtensionType,
23
+ preprocessingFile?: string
24
+ ): {
25
+ properties: string;
26
+ loadMethod: string;
27
+ propsMethod: string;
28
+ } {
29
+ switch (type) {
30
+ case 'share': {
31
+ const dataTemplate = readTemplate('share-extension-data.swift');
32
+
33
+ // Handle preprocessing file
34
+ let preprocessingLoad = '';
35
+ if (preprocessingFile) {
36
+ preprocessingLoad = `
37
+ // Load preprocessed web data
38
+ if let jsDict = extensionItem.userInfo?[NSExtensionJavaScriptPreprocessingResultsKey] as? [String: Any] {
39
+ self.preprocessedWebData = jsDict
40
+ }`;
41
+ }
42
+
43
+ const modifiedTemplate = dataTemplate.replace(
44
+ '{{PREPROCESSING_DATA_LOAD}}',
45
+ preprocessingLoad
46
+ );
47
+
48
+ // Split template into sections
49
+ const lines = modifiedTemplate.split('\n');
50
+ const properties: string[] = [];
51
+ const loadMethodLines: string[] = [];
52
+ const propsMethodLines: string[] = [];
53
+
54
+ let currentSection: 'properties' | 'load' | 'props' | null = null;
55
+
56
+ for (const line of lines) {
57
+ if (line.includes('private var ')) {
58
+ currentSection = 'properties';
59
+ properties.push(line);
60
+ } else if (line.includes('private func loadSharedContent()')) {
61
+ currentSection = 'load';
62
+ loadMethodLines.push(line);
63
+ } else if (line.includes('private func getSharedDataProps()')) {
64
+ currentSection = 'props';
65
+ propsMethodLines.push(line);
66
+ } else if (
67
+ currentSection === 'properties' &&
68
+ line.trim().startsWith('private')
69
+ ) {
70
+ properties.push(line);
71
+ } else if (currentSection === 'load') {
72
+ loadMethodLines.push(line);
73
+ } else if (currentSection === 'props') {
74
+ propsMethodLines.push(line);
75
+ }
76
+ }
77
+
78
+ return {
79
+ properties: properties.join('\n '),
80
+ loadMethod: `// Load shared content before creating React Native view
81
+ Task {
82
+ await loadSharedContent()
83
+ // Create React Native view with loaded content
84
+ await MainActor.run {
85
+ let sharedData = getSharedDataProps()
86
+ setupReactNativeView(with: sharedData)
87
+ }
88
+ }`,
89
+ propsMethod:
90
+ loadMethodLines.join('\n') + '\n\n' + propsMethodLines.join('\n'),
91
+ };
92
+ }
93
+
94
+ case 'action': {
95
+ const dataTemplate = readTemplate('action-extension-data.swift');
96
+ const lines = dataTemplate.split('\n');
97
+ const properties: string[] = [];
98
+ const loadMethodLines: string[] = [];
99
+ const propsMethodLines: string[] = [];
100
+
101
+ let currentSection: 'properties' | 'load' | 'props' | null = null;
102
+
103
+ for (const line of lines) {
104
+ if (line.includes('private var ')) {
105
+ currentSection = 'properties';
106
+ properties.push(line);
107
+ } else if (line.includes('private func loadActionContent()')) {
108
+ currentSection = 'load';
109
+ loadMethodLines.push(line);
110
+ } else if (line.includes('private func getActionDataProps()')) {
111
+ currentSection = 'props';
112
+ propsMethodLines.push(line);
113
+ } else if (
114
+ currentSection === 'properties' &&
115
+ line.trim().startsWith('private')
116
+ ) {
117
+ properties.push(line);
118
+ } else if (currentSection === 'load') {
119
+ loadMethodLines.push(line);
120
+ } else if (currentSection === 'props') {
121
+ propsMethodLines.push(line);
122
+ }
123
+ }
124
+
125
+ return {
126
+ properties: properties.join('\n '),
127
+ loadMethod: `// Load action content before creating React Native view
128
+ Task {
129
+ await loadActionContent()
130
+ // Create React Native view with loaded content
131
+ await MainActor.run {
132
+ let actionData = getActionDataProps()
133
+ setupReactNativeView(with: actionData)
134
+ }
135
+ }`,
136
+ propsMethod:
137
+ loadMethodLines.join('\n') + '\n\n' + propsMethodLines.join('\n'),
138
+ };
139
+ }
140
+
141
+ case 'clip': {
142
+ const dataTemplate = readTemplate('clip-extension-data.swift');
143
+ const lines = dataTemplate.split('\n');
144
+ const properties: string[] = [];
145
+ const loadMethodLines: string[] = [];
146
+ const propsMethodLines: string[] = [];
147
+
148
+ let currentSection: 'properties' | 'load' | 'props' | null = null;
149
+
150
+ for (const line of lines) {
151
+ if (line.includes('private var ')) {
152
+ currentSection = 'properties';
153
+ properties.push(line);
154
+ } else if (line.includes('private func loadClipContent()')) {
155
+ currentSection = 'load';
156
+ loadMethodLines.push(line);
157
+ } else if (line.includes('private func getClipDataProps()')) {
158
+ currentSection = 'props';
159
+ propsMethodLines.push(line);
160
+ } else if (
161
+ currentSection === 'properties' &&
162
+ line.trim().startsWith('private')
163
+ ) {
164
+ properties.push(line);
165
+ } else if (currentSection === 'load') {
166
+ loadMethodLines.push(line);
167
+ } else if (currentSection === 'props') {
168
+ propsMethodLines.push(line);
169
+ }
170
+ }
171
+
172
+ return {
173
+ properties: properties.join('\n '),
174
+ loadMethod: `loadClipContent()
175
+ let clipData = getClipDataProps()
176
+ setupReactNativeView(with: clipData)`,
177
+ propsMethod:
178
+ loadMethodLines.join('\n') + '\n\n' + propsMethodLines.join('\n'),
179
+ };
180
+ }
181
+
182
+ case 'messages': {
183
+ const dataTemplate = readTemplate('messages-extension-data.swift');
184
+ const lines = dataTemplate.split('\n');
185
+ const properties: string[] = [];
186
+ const loadMethodLines: string[] = [];
187
+ const propsMethodLines: string[] = [];
188
+
189
+ let currentSection: 'properties' | 'load' | 'props' | null = null;
190
+
191
+ for (const line of lines) {
192
+ if (line.includes('private var ')) {
193
+ currentSection = 'properties';
194
+ properties.push(line);
195
+ } else if (line.includes('private func loadMessagesContent()')) {
196
+ currentSection = 'load';
197
+ loadMethodLines.push(line);
198
+ } else if (line.includes('private func getMessagesDataProps()')) {
199
+ currentSection = 'props';
200
+ propsMethodLines.push(line);
201
+ } else if (
202
+ currentSection === 'properties' &&
203
+ line.trim().startsWith('private')
204
+ ) {
205
+ properties.push(line);
206
+ } else if (currentSection === 'load') {
207
+ loadMethodLines.push(line);
208
+ } else if (currentSection === 'props') {
209
+ propsMethodLines.push(line);
210
+ }
211
+ }
212
+
213
+ return {
214
+ properties: properties.join('\n '),
215
+ loadMethod: `loadMessagesContent()
216
+ let messagesData = getMessagesDataProps()
217
+ setupReactNativeView(with: messagesData)`,
218
+ propsMethod:
219
+ loadMethodLines.join('\n') + '\n\n' + propsMethodLines.join('\n'),
220
+ };
221
+ }
222
+
223
+ default:
224
+ // For other types, no extension-specific data
225
+ return {
226
+ properties: '',
227
+ loadMethod: 'setupReactNativeView(with: nil)',
228
+ propsMethod: '',
229
+ };
230
+ }
231
+ }
232
+
233
+ export function generateMessagesViewController(): string {
234
+ return readTemplate('MessagesViewController.swift');
235
+ }
236
+
237
+ export function generateReactNativeViewController(
238
+ options: ReactNativeViewControllerOptions
239
+ ): string {
240
+ let baseTemplate = readTemplate('ReactNativeViewController.swift');
241
+ const extensionData = getExtensionDataForType(
242
+ options.type,
243
+ options.preprocessingFile
244
+ );
245
+
246
+ // Add Messages import for messages type
247
+ if (options.type === 'messages') {
248
+ baseTemplate = baseTemplate.replace(
249
+ 'import ReactAppDependencyProvider',
250
+ 'import ReactAppDependencyProvider\nimport Messages'
251
+ );
252
+ }
253
+
254
+ // Convert entry path to bundle root for Metro
255
+ // e.g., "./targets/rn-share/index.tsx" -> "targets/rn-share/index"
256
+ let bundleRoot = '.expo/.virtual-metro-entry';
257
+ if (options.entry) {
258
+ bundleRoot = options.entry
259
+ .replace(/^\.\//, '') // Remove leading ./
260
+ .replace(/\.(tsx?|jsx?)$/, ''); // Remove file extension
261
+ }
262
+
263
+ // Replace placeholders (use replaceAll to catch multiple occurrences)
264
+ let result = baseTemplate
265
+ .replace(/{{MODULE_NAME}}/g, options.moduleName)
266
+ .replace(/{{TARGET_NAME}}/g, options.targetName)
267
+ .replace(/{{BUNDLE_ROOT}}/g, bundleRoot)
268
+ .replace('{{EXTENSION_DATA_PROPERTIES}}', extensionData.properties)
269
+ .replace('{{LOAD_EXTENSION_DATA}}', extensionData.loadMethod);
270
+
271
+ // Add extension data methods if needed
272
+ if (extensionData.propsMethod) {
273
+ const closingBraceIndex = result.lastIndexOf('}');
274
+ result =
275
+ result.slice(0, closingBraceIndex) +
276
+ '\n // MARK: - Extension Data\n \n' +
277
+ extensionData.propsMethod +
278
+ '\n' +
279
+ result.slice(closingBraceIndex);
280
+ }
281
+
282
+ return result;
283
+ }