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.
- package/.eslintrc.js +2 -0
- package/README.md +244 -0
- package/android/build.gradle +22 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsLogger.kt +98 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsReceiver.kt +136 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsRemoteViewsProvider.kt +72 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetProvider.kt +47 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetSync.kt +78 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetUpdateReceiver.kt +30 -0
- package/android/src/main/java/expo/modules/targets/extension/ExpoTargetsExtensionModule.kt +27 -0
- package/android/src/main/java/expo/modules/targets/messages/ExpoTargetsMessagesModule.kt +40 -0
- package/android/src/main/java/expo/modules/targets/storage/ExpoTargetsStorageModule.kt +119 -0
- package/app.plugin.js +1 -0
- package/build/metro/src/index.d.ts +2 -0
- package/build/metro/src/index.d.ts.map +1 -0
- package/build/metro/src/index.js +6 -0
- package/build/metro/src/index.js.map +1 -0
- package/build/metro/src/withTargetsMetro.d.ts +6 -0
- package/build/metro/src/withTargetsMetro.d.ts.map +1 -0
- package/build/metro/src/withTargetsMetro.js +171 -0
- package/build/metro/src/withTargetsMetro.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js +56 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js +70 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js +41 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js +75 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js +86 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js +23 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts +7 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js +31 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts +3 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js +24 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts +3 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js +27 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts +10 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.js +22 -0
- package/build/plugin/src/android/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts +13 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.js +564 -0
- package/build/plugin/src/android/withAndroidWidget.js.map +1 -0
- package/build/plugin/src/config.d.ts +141 -0
- package/build/plugin/src/config.d.ts.map +1 -0
- package/build/plugin/src/config.js +54 -0
- package/build/plugin/src/config.js.map +1 -0
- package/build/plugin/src/index.d.ts +9 -0
- package/build/plugin/src/index.d.ts.map +1 -0
- package/build/plugin/src/index.js +11 -0
- package/build/plugin/src/index.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts +11 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js +49 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts +17 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js +152 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js +25 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js +52 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts +12 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js +162 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts +15 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js +646 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js.map +1 -0
- package/build/plugin/src/ios/target.d.ts +41 -0
- package/build/plugin/src/ios/target.d.ts.map +1 -0
- package/build/plugin/src/ios/target.js +574 -0
- package/build/plugin/src/ios/target.js.map +1 -0
- package/build/plugin/src/ios/utils/asset.d.ts +60 -0
- package/build/plugin/src/ios/utils/asset.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/asset.js +375 -0
- package/build/plugin/src/ios/utils/asset.js.map +1 -0
- package/build/plugin/src/ios/utils/file.d.ts +33 -0
- package/build/plugin/src/ios/utils/file.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/file.js +88 -0
- package/build/plugin/src/ios/utils/file.js.map +1 -0
- package/build/plugin/src/ios/utils/index.d.ts +12 -0
- package/build/plugin/src/ios/utils/index.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/index.js +38 -0
- package/build/plugin/src/ios/utils/index.js.map +1 -0
- package/build/plugin/src/ios/utils/paths.d.ts +128 -0
- package/build/plugin/src/ios/utils/paths.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/paths.js +141 -0
- package/build/plugin/src/ios/utils/paths.js.map +1 -0
- package/build/plugin/src/ios/utils/plist.d.ts +29 -0
- package/build/plugin/src/ios/utils/plist.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/plist.js +114 -0
- package/build/plugin/src/ios/utils/plist.js.map +1 -0
- package/build/plugin/src/ios/utils/podfile.d.ts +82 -0
- package/build/plugin/src/ios/utils/podfile.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/podfile.js +408 -0
- package/build/plugin/src/ios/utils/podfile.js.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts +11 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js +263 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js.map +1 -0
- package/build/plugin/src/ios/utils/xcode.d.ts +185 -0
- package/build/plugin/src/ios/utils/xcode.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/xcode.js +706 -0
- package/build/plugin/src/ios/utils/xcode.js.map +1 -0
- package/build/plugin/src/logger.d.ts +10 -0
- package/build/plugin/src/logger.d.ts.map +1 -0
- package/build/plugin/src/logger.js +62 -0
- package/build/plugin/src/logger.js.map +1 -0
- package/build/plugin/src/parseTargetConfig.d.ts +3 -0
- package/build/plugin/src/parseTargetConfig.d.ts.map +1 -0
- package/build/plugin/src/parseTargetConfig.js +113 -0
- package/build/plugin/src/parseTargetConfig.js.map +1 -0
- package/build/plugin/src/withTargetsDir.d.ts +6 -0
- package/build/plugin/src/withTargetsDir.d.ts.map +1 -0
- package/build/plugin/src/withTargetsDir.js +90 -0
- package/build/plugin/src/withTargetsDir.js.map +1 -0
- package/build/src/Target.d.ts +43 -0
- package/build/src/Target.d.ts.map +1 -0
- package/build/src/Target.js +128 -0
- package/build/src/Target.js.map +1 -0
- package/build/src/index.d.ts +9 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +27 -0
- package/build/src/index.js.map +1 -0
- package/build/src/modules/extension/index.d.ts +18 -0
- package/build/src/modules/extension/index.d.ts.map +1 -0
- package/build/src/modules/extension/index.js +44 -0
- package/build/src/modules/extension/index.js.map +1 -0
- package/build/src/modules/messages/index.d.ts +40 -0
- package/build/src/modules/messages/index.d.ts.map +1 -0
- package/build/src/modules/messages/index.js +94 -0
- package/build/src/modules/messages/index.js.map +1 -0
- package/build/src/modules/storage/index.d.ts +16 -0
- package/build/src/modules/storage/index.d.ts.map +1 -0
- package/build/src/modules/storage/index.js +122 -0
- package/build/src/modules/storage/index.js.map +1 -0
- package/expo-module.config.json +17 -0
- package/ios/ExpoTargetsExtension.podspec +23 -0
- package/ios/ExpoTargetsExtensionModule.swift +181 -0
- package/ios/ExpoTargetsMessages.podspec +23 -0
- package/ios/ExpoTargetsMessagesModule.swift +267 -0
- package/ios/ExpoTargetsStorage.podspec +23 -0
- package/ios/ExpoTargetsStorageModule.swift +91 -0
- package/ios/Tests/.swiftlint.yml +52 -0
- package/ios/Tests/Helpers/MockExtensionContext.swift +58 -0
- package/ios/Tests/Helpers/MockUserDefaults.swift +70 -0
- package/ios/Tests/Helpers/MockWidgetCenter.swift +71 -0
- package/ios/Tests/Helpers/TestHelpers.swift +90 -0
- package/ios/Tests/Integration/TargetIntegrationTests.swift +478 -0
- package/ios/Tests/Main/AllTests.swift +80 -0
- package/ios/Tests/Package.swift +66 -0
- package/ios/Tests/Performance/StoragePerformanceTests.swift +461 -0
- package/ios/Tests/Unit/Extension/ExpoTargetsExtensionModuleTests.swift +501 -0
- package/ios/Tests/Unit/Storage/ExpoTargetsStorageModuleTests.swift +578 -0
- package/ios/Tests/Unit/Template/ShareExtensionTemplateTests.swift +421 -0
- package/ios/Tests/XCTestPlan.xctestplan +87 -0
- package/metro/src/index.ts +1 -0
- package/metro/src/withTargetsMetro.ts +247 -0
- package/metro/tsconfig.build.json +9 -0
- package/package.json +74 -0
- package/plugin/src/android/withAndroidAppBuildGradle.ts +34 -0
- package/plugin/src/android/withAndroidTarget.ts +26 -0
- package/plugin/src/android/withAndroidWidget.ts +778 -0
- package/plugin/src/config.ts +255 -0
- package/plugin/src/index.ts +19 -0
- package/plugin/src/ios/config-plugins/withEntitlements.ts +69 -0
- package/plugin/src/ios/config-plugins/withIOSTarget.ts +179 -0
- package/plugin/src/ios/config-plugins/withIosColorset.ts +29 -0
- package/plugin/src/ios/config-plugins/withIosStickerPack.ts +65 -0
- package/plugin/src/ios/config-plugins/withPodfile.ts +238 -0
- package/plugin/src/ios/config-plugins/withXcodeChanges.ts +891 -0
- package/plugin/src/ios/target.ts +668 -0
- package/plugin/src/ios/templates/MessagesViewController.swift +120 -0
- package/plugin/src/ios/templates/ReactNativeViewController.swift +240 -0
- package/plugin/src/ios/templates/action-extension-data.swift +106 -0
- package/plugin/src/ios/templates/clip-extension-data.swift +28 -0
- package/plugin/src/ios/templates/messages-extension-data.swift +28 -0
- package/plugin/src/ios/templates/share-extension-data.swift +113 -0
- package/plugin/src/ios/utils/asset.ts +490 -0
- package/plugin/src/ios/utils/file.ts +80 -0
- package/plugin/src/ios/utils/index.ts +12 -0
- package/plugin/src/ios/utils/paths.ts +253 -0
- package/plugin/src/ios/utils/plist.ts +101 -0
- package/plugin/src/ios/utils/podfile.ts +534 -0
- package/plugin/src/ios/utils/reactNativeSwift.ts +283 -0
- package/plugin/src/ios/utils/xcode.ts +989 -0
- package/plugin/src/logger.ts +63 -0
- package/plugin/src/parseTargetConfig.ts +115 -0
- package/plugin/src/types/normalize-colors.d.ts +3 -0
- package/plugin/src/withTargetsDir.ts +120 -0
- package/plugin/tsconfig.build.json +9 -0
- package/plugin/tsconfig.json +9 -0
- package/src/Target.ts +239 -0
- package/src/index.ts +52 -0
- package/src/modules/extension/index.ts +54 -0
- package/src/modules/messages/index.ts +124 -0
- package/src/modules/storage/index.ts +126 -0
- 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
|
+
}
|