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,490 @@
1
+ import normalizeColor from '@react-native/normalize-colors';
2
+ import path from 'path';
3
+
4
+ import * as FileUtils from './file';
5
+
6
+ /**
7
+ * iOS asset utilities for creating colorsets, imagesets, etc.
8
+ */
9
+
10
+ /**
11
+ * Color components for iOS colorset.
12
+ */
13
+ interface ColorComponents {
14
+ red: string;
15
+ green: string;
16
+ blue: string;
17
+ alpha: string;
18
+ }
19
+
20
+ /**
21
+ * Normalize a color string to RGBA components for iOS.
22
+ */
23
+ export function normalizeColorToComponents(color: string): ColorComponents {
24
+ const normalized = normalizeColor(color);
25
+ if (normalized === null || normalized === undefined) {
26
+ throw new Error(`Invalid color: ${color}`);
27
+ }
28
+ const r = ((normalized >> 16) & 0xff) / 255;
29
+ const g = ((normalized >> 8) & 0xff) / 255;
30
+ const b = (normalized & 0xff) / 255;
31
+ const a = ((normalized >> 24) & 0xff) / 255;
32
+ return {
33
+ red: r.toFixed(3),
34
+ green: g.toFixed(3),
35
+ blue: b.toFixed(3),
36
+ alpha: a.toFixed(3),
37
+ };
38
+ }
39
+
40
+ /**
41
+ * Create a colorset in Assets.xcassets.
42
+ */
43
+ export function createColorset({
44
+ colorsetPath,
45
+ color,
46
+ darkColor,
47
+ }: {
48
+ colorsetPath: string;
49
+ color: string;
50
+ darkColor?: string;
51
+ }): void {
52
+ FileUtils.ensureDirectoryExists(colorsetPath);
53
+
54
+ const colors: any[] = [
55
+ {
56
+ color: {
57
+ 'color-space': 'srgb',
58
+ components: normalizeColorToComponents(color),
59
+ },
60
+ idiom: 'universal',
61
+ },
62
+ ];
63
+
64
+ if (darkColor) {
65
+ colors.push({
66
+ appearances: [{ appearance: 'luminosity', value: 'dark' }],
67
+ color: {
68
+ 'color-space': 'srgb',
69
+ components: normalizeColorToComponents(darkColor),
70
+ },
71
+ idiom: 'universal',
72
+ });
73
+ }
74
+
75
+ const contentsJson = {
76
+ colors,
77
+ info: { author: 'xcode', version: 1 },
78
+ };
79
+
80
+ FileUtils.writeFileSafe(
81
+ path.join(colorsetPath, 'Contents.json'),
82
+ JSON.stringify(contentsJson, null, 2)
83
+ );
84
+ }
85
+
86
+ /**
87
+ * Create an empty imageset in Assets.xcassets.
88
+ */
89
+ export function createImageset({
90
+ imagesetPath,
91
+ imageFilename,
92
+ }: {
93
+ imagesetPath: string;
94
+ imageFilename?: string;
95
+ }): void {
96
+ FileUtils.ensureDirectoryExists(imagesetPath);
97
+
98
+ const contentsJson: any = {
99
+ images: [
100
+ {
101
+ idiom: 'universal',
102
+ scale: '1x',
103
+ },
104
+ {
105
+ idiom: 'universal',
106
+ scale: '2x',
107
+ },
108
+ {
109
+ idiom: 'universal',
110
+ scale: '3x',
111
+ },
112
+ ],
113
+ info: { author: 'xcode', version: 1 },
114
+ };
115
+
116
+ if (imageFilename) {
117
+ contentsJson.images[0].filename = imageFilename;
118
+ }
119
+
120
+ FileUtils.writeFileSafe(
121
+ path.join(imagesetPath, 'Contents.json'),
122
+ JSON.stringify(contentsJson, null, 2)
123
+ );
124
+ }
125
+
126
+ /**
127
+ * Create the root Contents.json for Assets.xcassets.
128
+ */
129
+ export function createAssetsXcassetsRoot(assetsPath: string): void {
130
+ FileUtils.ensureDirectoryExists(assetsPath);
131
+
132
+ const contentsJson = {
133
+ info: { author: 'xcode', version: 1 },
134
+ };
135
+
136
+ FileUtils.writeFileSafe(
137
+ path.join(assetsPath, 'Contents.json'),
138
+ JSON.stringify(contentsJson, null, 2)
139
+ );
140
+ }
141
+
142
+ /**
143
+ * Create an individual sticker in a sticker pack.
144
+ */
145
+ export function createSticker({
146
+ stickerPath,
147
+ filename,
148
+ }: {
149
+ stickerPath: string;
150
+ filename: string;
151
+ }): void {
152
+ FileUtils.ensureDirectoryExists(stickerPath);
153
+
154
+ const contentsJson = {
155
+ info: { author: 'xcode', version: 1 },
156
+ properties: {
157
+ filename,
158
+ },
159
+ };
160
+
161
+ FileUtils.writeFileSafe(
162
+ path.join(stickerPath, 'Contents.json'),
163
+ JSON.stringify(contentsJson, null, 2)
164
+ );
165
+ }
166
+
167
+ /**
168
+ * Create a sticker pack in Assets.xcassets.
169
+ */
170
+ export function createStickerPack({
171
+ stickerPackPath,
172
+ name,
173
+ assets,
174
+ }: {
175
+ stickerPackPath: string;
176
+ name: string;
177
+ assets: string[];
178
+ }): void {
179
+ FileUtils.ensureDirectoryExists(stickerPackPath);
180
+
181
+ const stickers = assets.map((asset) => {
182
+ const baseName = path.basename(asset, path.extname(asset));
183
+ return {
184
+ filename: `${baseName}.sticker`,
185
+ };
186
+ });
187
+
188
+ const contentsJson = {
189
+ properties: {
190
+ 'grid-size': 'regular',
191
+ },
192
+ stickers,
193
+ info: { author: 'xcode', version: 1 },
194
+ };
195
+
196
+ FileUtils.writeFileSafe(
197
+ path.join(stickerPackPath, 'Contents.json'),
198
+ JSON.stringify(contentsJson, null, 2)
199
+ );
200
+ }
201
+
202
+ /**
203
+ * Icon size configuration for iMessage App Icons.
204
+ */
205
+ interface IconSize {
206
+ filename: string;
207
+ width: number;
208
+ height: number;
209
+ size: string;
210
+ idiom: string;
211
+ scale: string;
212
+ platform?: string;
213
+ }
214
+
215
+ /**
216
+ * Generate a single icon size using sips with proper cropping.
217
+ */
218
+ function generateIcon({
219
+ sourceIconPath,
220
+ outputPath,
221
+ width,
222
+ height,
223
+ }: {
224
+ sourceIconPath: string;
225
+ outputPath: string;
226
+ width: number;
227
+ height: number;
228
+ }): boolean {
229
+ try {
230
+ const { execSync } = require('child_process');
231
+
232
+ // Use sips -Z to crop to aspect ratio, then resize
233
+ // First crop to match aspect ratio, then resize to exact dimensions
234
+ const targetRatio = width / height;
235
+
236
+ // Create a temporary intermediate file for the cropped version
237
+ const tempPath = outputPath + '.temp.png';
238
+
239
+ // Get source dimensions
240
+ const sizeOutput = execSync(
241
+ `sips -g pixelWidth -g pixelHeight "${sourceIconPath}"`,
242
+ { encoding: 'utf-8' }
243
+ );
244
+ const widthMatch = sizeOutput.match(/pixelWidth: (\d+)/);
245
+ const heightMatch = sizeOutput.match(/pixelHeight: (\d+)/);
246
+
247
+ if (!widthMatch || !heightMatch) {
248
+ throw new Error('Could not determine source image dimensions');
249
+ }
250
+
251
+ const sourceWidth = parseInt(widthMatch[1], 10);
252
+ const sourceHeight = parseInt(heightMatch[1], 10);
253
+ const sourceRatio = sourceWidth / sourceHeight;
254
+
255
+ let cropWidth: number;
256
+ let cropHeight: number;
257
+
258
+ if (sourceRatio > targetRatio) {
259
+ // Source is wider, crop width
260
+ cropHeight = sourceHeight;
261
+ cropWidth = Math.round(sourceHeight * targetRatio);
262
+ } else {
263
+ // Source is taller, crop height
264
+ cropWidth = sourceWidth;
265
+ cropHeight = Math.round(sourceWidth / targetRatio);
266
+ }
267
+
268
+ // Calculate crop position (center crop)
269
+ const cropX = Math.round((sourceWidth - cropWidth) / 2);
270
+ const cropY = Math.round((sourceHeight - cropHeight) / 2);
271
+
272
+ // Crop the image to the correct aspect ratio
273
+ execSync(
274
+ `sips -c ${cropHeight} ${cropWidth} --cropOffset ${cropY} ${cropX} "${sourceIconPath}" --out "${tempPath}"`,
275
+ { stdio: 'ignore' }
276
+ );
277
+
278
+ // Now resize to exact dimensions
279
+ execSync(`sips -z ${height} ${width} "${tempPath}" --out "${outputPath}"`, {
280
+ stdio: 'ignore',
281
+ });
282
+
283
+ // Clean up temp file
284
+ const fs = require('fs');
285
+ if (fs.existsSync(tempPath)) {
286
+ fs.unlinkSync(tempPath);
287
+ }
288
+
289
+ return true;
290
+ } catch (error) {
291
+ console.error(
292
+ `[expo-targets] Failed to generate icon ${outputPath}:`,
293
+ error
294
+ );
295
+ return false;
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Create iMessage App Icon set in Assets.xcassets.
301
+ * Generates all 13 required icon sizes with proper cropping to maintain aspect ratio.
302
+ */
303
+ export function createIMessageAppIcon({
304
+ iconsetPath,
305
+ sourceIconPath,
306
+ }: {
307
+ iconsetPath: string;
308
+ sourceIconPath?: string;
309
+ }): void {
310
+ FileUtils.ensureDirectoryExists(iconsetPath);
311
+
312
+ // All required icon sizes for iMessage sticker packs
313
+ const iconSizes: IconSize[] = [
314
+ {
315
+ filename: 'icon-iphone-29x29@2x.png',
316
+ width: 58,
317
+ height: 58,
318
+ size: '29x29',
319
+ idiom: 'iphone',
320
+ scale: '2x',
321
+ },
322
+ {
323
+ filename: 'icon-iphone-29x29@3x.png',
324
+ width: 87,
325
+ height: 87,
326
+ size: '29x29',
327
+ idiom: 'iphone',
328
+ scale: '3x',
329
+ },
330
+ {
331
+ filename: 'icon-iphone-60x45@2x.png',
332
+ width: 120,
333
+ height: 90,
334
+ size: '60x45',
335
+ idiom: 'iphone',
336
+ scale: '2x',
337
+ },
338
+ {
339
+ filename: 'icon-iphone-60x45@3x.png',
340
+ width: 180,
341
+ height: 135,
342
+ size: '60x45',
343
+ idiom: 'iphone',
344
+ scale: '3x',
345
+ },
346
+ {
347
+ filename: 'icon-ipad-29x29@2x.png',
348
+ width: 58,
349
+ height: 58,
350
+ size: '29x29',
351
+ idiom: 'ipad',
352
+ scale: '2x',
353
+ },
354
+ {
355
+ filename: 'icon-ipad-67x50@2x.png',
356
+ width: 134,
357
+ height: 100,
358
+ size: '67x50',
359
+ idiom: 'ipad',
360
+ scale: '2x',
361
+ },
362
+ {
363
+ filename: 'icon-ipad-74x55@2x.png',
364
+ width: 148,
365
+ height: 110,
366
+ size: '74x55',
367
+ idiom: 'ipad',
368
+ scale: '2x',
369
+ },
370
+ {
371
+ filename: 'icon-ios-marketing-1024x1024.png',
372
+ width: 1024,
373
+ height: 1024,
374
+ size: '1024x1024',
375
+ idiom: 'ios-marketing',
376
+ scale: '1x',
377
+ },
378
+ {
379
+ filename: 'icon-ios-27x20@2x.png',
380
+ width: 54,
381
+ height: 40,
382
+ size: '27x20',
383
+ idiom: 'universal',
384
+ scale: '2x',
385
+ platform: 'ios',
386
+ },
387
+ {
388
+ filename: 'icon-ios-27x20@3x.png',
389
+ width: 81,
390
+ height: 60,
391
+ size: '27x20',
392
+ idiom: 'universal',
393
+ scale: '3x',
394
+ platform: 'ios',
395
+ },
396
+ {
397
+ filename: 'icon-ios-32x24@2x.png',
398
+ width: 64,
399
+ height: 48,
400
+ size: '32x24',
401
+ idiom: 'universal',
402
+ scale: '2x',
403
+ platform: 'ios',
404
+ },
405
+ {
406
+ filename: 'icon-ios-32x24@3x.png',
407
+ width: 96,
408
+ height: 72,
409
+ size: '32x24',
410
+ idiom: 'universal',
411
+ scale: '3x',
412
+ platform: 'ios',
413
+ },
414
+ {
415
+ filename: 'icon-ios-1024x768.png',
416
+ width: 1024,
417
+ height: 768,
418
+ size: '1024x768',
419
+ idiom: 'ios-marketing',
420
+ scale: '1x',
421
+ platform: 'ios',
422
+ },
423
+ ];
424
+
425
+ // Create Contents.json with all icon references
426
+ const images = iconSizes.map((iconSize) => {
427
+ const entry: any = {
428
+ size: iconSize.size,
429
+ idiom: iconSize.idiom,
430
+ filename: iconSize.filename,
431
+ scale: iconSize.scale,
432
+ };
433
+
434
+ if (iconSize.platform) {
435
+ entry.platform = iconSize.platform;
436
+ }
437
+
438
+ return entry;
439
+ });
440
+
441
+ const contentsJson = {
442
+ images,
443
+ info: { author: 'xcode', version: 1 },
444
+ };
445
+
446
+ FileUtils.writeFileSafe(
447
+ path.join(iconsetPath, 'Contents.json'),
448
+ JSON.stringify(contentsJson, null, 2)
449
+ );
450
+
451
+ // Generate all icon sizes from source
452
+ if (sourceIconPath && FileUtils.isFile(sourceIconPath)) {
453
+ console.log(
454
+ `[expo-targets] Generating iMessage App Icons from ${path.basename(sourceIconPath)}...`
455
+ );
456
+
457
+ let successCount = 0;
458
+
459
+ for (const iconSize of iconSizes) {
460
+ const outputPath = path.join(iconsetPath, iconSize.filename);
461
+ const success = generateIcon({
462
+ sourceIconPath,
463
+ outputPath,
464
+ width: iconSize.width,
465
+ height: iconSize.height,
466
+ });
467
+
468
+ if (success) {
469
+ successCount++;
470
+ }
471
+ }
472
+
473
+ console.log(
474
+ `[expo-targets] Generated ${successCount}/${iconSizes.length} iMessage App Icons`
475
+ );
476
+
477
+ if (successCount < iconSizes.length) {
478
+ console.warn(
479
+ `[expo-targets] Warning: Failed to generate ${iconSizes.length - successCount} icons. Build may fail.`
480
+ );
481
+ }
482
+ } else if (sourceIconPath) {
483
+ console.warn(
484
+ `[expo-targets] iMessage App Icon source not found: ${sourceIconPath}`
485
+ );
486
+ console.warn(
487
+ `[expo-targets] Build will fail without proper icons. Please provide a valid icon source.`
488
+ );
489
+ }
490
+ }
@@ -0,0 +1,80 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ /**
5
+ * File system utilities for iOS target plugin operations.
6
+ * Provides safe, convenient wrappers for common file operations.
7
+ */
8
+
9
+ /**
10
+ * Ensure a directory exists, creating it recursively if needed.
11
+ */
12
+ export function ensureDirectoryExists(dirPath: string): void {
13
+ if (!fs.existsSync(dirPath)) {
14
+ fs.mkdirSync(dirPath, { recursive: true });
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Write content to a file, ensuring the directory exists first.
20
+ */
21
+ export function writeFileSafe(filePath: string, content: string): void {
22
+ ensureDirectoryExists(path.dirname(filePath));
23
+ fs.writeFileSync(filePath, content);
24
+ }
25
+
26
+ /**
27
+ * Copy a file, ensuring the destination directory exists.
28
+ */
29
+ export function copyFileSafe(source: string, destination: string): void {
30
+ if (!fs.existsSync(source)) {
31
+ throw new Error(`Source file does not exist: ${source}`);
32
+ }
33
+ ensureDirectoryExists(path.dirname(destination));
34
+ fs.copyFileSync(source, destination);
35
+ }
36
+
37
+ /**
38
+ * Copy a directory recursively, ensuring the destination exists.
39
+ */
40
+ export function copyDirectorySafe(source: string, destination: string): void {
41
+ if (!fs.existsSync(source)) {
42
+ throw new Error(`Source directory does not exist: ${source}`);
43
+ }
44
+ ensureDirectoryExists(path.dirname(destination));
45
+ fs.cpSync(source, destination, { recursive: true });
46
+ }
47
+
48
+ /**
49
+ * Read a file if it exists, otherwise return undefined.
50
+ */
51
+ export function readFileIfExists(filePath: string): string | undefined {
52
+ if (fs.existsSync(filePath)) {
53
+ return fs.readFileSync(filePath, 'utf-8');
54
+ }
55
+ return undefined;
56
+ }
57
+
58
+ /**
59
+ * Check if a file exists and is a file (not a directory).
60
+ */
61
+ export function isFile(filePath: string): boolean {
62
+ try {
63
+ const stat = fs.statSync(filePath);
64
+ return stat.isFile();
65
+ } catch {
66
+ return false;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Check if a path exists and is a directory.
72
+ */
73
+ export function isDirectory(dirPath: string): boolean {
74
+ try {
75
+ const stat = fs.statSync(dirPath);
76
+ return stat.isDirectory();
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Centralized utilities for iOS plugin operations.
3
+ * Re-exports all utility modules for convenient access.
4
+ */
5
+
6
+ export * as Xcode from './xcode';
7
+ export * as Paths from './paths';
8
+ export * as File from './file';
9
+ export * as Plist from './plist';
10
+ export * as Podfile from './podfile';
11
+ export * as Asset from './asset';
12
+ export * as ReactNativeSwift from './reactNativeSwift';