cordova-plugin-firebasex-firestore 1.0.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/plugin.xml ADDED
@@ -0,0 +1,72 @@
1
+ <?xml version='1.0' encoding='utf-8'?>
2
+ <plugin id="cordova-plugin-firebasex-firestore"
3
+ version="1.0.0"
4
+ xmlns="http://apache.org/cordova/ns/plugins/1.0"
5
+ xmlns:android="http://schemas.android.com/apk/res/android">
6
+
7
+ <name>Cordova FirebaseX Firestore</name>
8
+ <description>Firestore module for cordova-plugin-firebasex</description>
9
+ <license>MIT</license>
10
+ <keywords>cordova,firebase,firestore</keywords>
11
+
12
+ <engines>
13
+ <engine name="cordova" version=">=12.0.0" />
14
+ <engine name="cordova-android" version=">=14.0.0" />
15
+ <engine name="cordova-ios" version=">=7.0.0" />
16
+ </engines>
17
+
18
+ <dependency id="cordova-plugin-firebasex-core" />
19
+
20
+ <preference name="IOS_USE_PRECOMPILED_FIRESTORE_POD" default="false" />
21
+
22
+ <hook type="after_prepare" src="scripts/post_install.js" />
23
+
24
+ <js-module src="www/firebasex-firestore.js" name="FirebasexFirestorePlugin">
25
+ <merges target="FirebasexFirestore" />
26
+ </js-module>
27
+
28
+ <!-- Android -->
29
+ <platform name="android">
30
+ <config-file target="res/xml/config.xml" parent="/*">
31
+ <feature name="FirebasexFirestorePlugin">
32
+ <param name="android-package" value="org.apache.cordova.firebasex.FirebasexFirestorePlugin" />
33
+ <param name="onload" value="true" />
34
+ </feature>
35
+ </config-file>
36
+
37
+ <preference name="ANDROID_FIREBASE_FIRESTORE_VERSION" default="26.1.0" />
38
+ <preference name="ANDROID_GRPC_OKHTTP" default="1.75.0" />
39
+ <preference name="ANDROID_GSON_VERSION" default="2.13.2" />
40
+
41
+ <source-file src="src/android/FirebasexFirestorePlugin.java" target-dir="src/org/apache/cordova/firebasex" />
42
+ <framework src="com.google.firebase:firebase-firestore:$ANDROID_FIREBASE_FIRESTORE_VERSION" />
43
+ <framework src="io.grpc:grpc-okhttp:$ANDROID_GRPC_OKHTTP" />
44
+ <framework src="com.google.code.gson:gson:$ANDROID_GSON_VERSION" />
45
+ </platform>
46
+
47
+ <!-- iOS -->
48
+ <platform name="ios">
49
+ <config-file target="config.xml" parent="/*">
50
+ <feature name="FirebasexFirestorePlugin">
51
+ <param name="ios-package" value="FirebasexFirestorePlugin" />
52
+ <param name="onload" value="true" />
53
+ </feature>
54
+ </config-file>
55
+
56
+ <header-file src="src/ios/FirebasexFirestorePlugin.h" />
57
+ <source-file src="src/ios/FirebasexFirestorePlugin.m" />
58
+
59
+ <preference name="IOS_FIREBASE_SDK_VERSION" default="12.9.0" />
60
+
61
+ <podspec>
62
+ <config>
63
+ <source url="https://cdn.cocoapods.org/"/>
64
+ </config>
65
+ <pods use-frameworks="true">
66
+ <pod name="FirebaseFirestore" tag="12.9.0" git="https://github.com/invertase/firestore-ios-sdk-frameworks.git" />
67
+ </pods>
68
+ </podspec>
69
+
70
+ <hook type="after_plugin_install" src="scripts/ios/after_plugin_install.js" />
71
+ </platform>
72
+ </plugin>
@@ -0,0 +1,137 @@
1
+ /**
2
+ * @file after_plugin_install.js
3
+ * @brief Hook script that runs after the firestore plugin is installed on iOS.
4
+ *
5
+ * Updates the FirebaseFirestore pod version tag in the Podfile based on the
6
+ * IOS_FIREBASE_SDK_VERSION plugin variable. FirebaseFirestore uses a git-based
7
+ * pod declaration with a `:tag` instead of a spec version:
8
+ *
9
+ * pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => 'X.Y.Z'
10
+ *
11
+ * Plugin variables are resolved using a 4-layer override strategy:
12
+ * 1. Defaults from plugin.xml preferences (via hook context).
13
+ * 2. Overrides from `config.xml` `<plugin><variable>` elements (wrapper and own plugin ID).
14
+ * 3. Overrides from `package.json` `cordova.plugins` entries (wrapper and own plugin ID).
15
+ * 4. CLI variables passed at install time (highest priority).
16
+ */
17
+ var fs = require("fs");
18
+ var path = require("path");
19
+
20
+ /** @constant {string} The plugin identifier. */
21
+ var PLUGIN_ID = "cordova-plugin-firebasex-firestore";
22
+ /** @constant {string} The wrapper meta-plugin identifier used as a fallback source for plugin variables. */
23
+ var WRAPPER_PLUGIN_ID = "cordova-plugin-firebasex";
24
+
25
+ /**
26
+ * Resolves plugin variables using the 4-layer override strategy.
27
+ *
28
+ * @param {object} context - The Cordova hook context.
29
+ * @returns {Object} Resolved plugin variable key/value pairs.
30
+ */
31
+ function resolvePluginVariables(context) {
32
+ var pluginVariables = {};
33
+
34
+ // 1. Defaults from plugin.xml preferences
35
+ var plugin = context.opts.plugin;
36
+ if (plugin && plugin.pluginInfo && plugin.pluginInfo._et && plugin.pluginInfo._et._root && plugin.pluginInfo._et._root._children) {
37
+ plugin.pluginInfo._et._root._children.forEach(function(child) {
38
+ if (child.tag === "preference") {
39
+ pluginVariables[child.attrib.name] = child.attrib.default;
40
+ }
41
+ });
42
+ }
43
+
44
+ // 2. Overrides from config.xml
45
+ try {
46
+ var configXmlPath = path.join(context.opts.projectRoot, "config.xml");
47
+ if (fs.existsSync(configXmlPath)) {
48
+ var configXml = fs.readFileSync(configXmlPath, "utf-8");
49
+ [WRAPPER_PLUGIN_ID, PLUGIN_ID].forEach(function(pluginId) {
50
+ var pluginRegex = new RegExp('<plugin[^>]+name="' + pluginId + '"[^>]*>(.*?)</plugin>', "s");
51
+ var pluginMatch = configXml.match(pluginRegex);
52
+ if (pluginMatch) {
53
+ var varRegex = /<variable\s+name="([^"]+)"\s+value="([^"]+)"\s*\/>/g;
54
+ var varMatch;
55
+ while ((varMatch = varRegex.exec(pluginMatch[1])) !== null) {
56
+ pluginVariables[varMatch[1]] = varMatch[2];
57
+ }
58
+ }
59
+ });
60
+ }
61
+ } catch (e) {
62
+ console.warn("[FirebasexFirestore] Could not read config.xml for plugin variables: " + e.message);
63
+ }
64
+
65
+ // 3. Overrides from package.json
66
+ try {
67
+ var packageJsonPath = path.join(context.opts.projectRoot, "package.json");
68
+ if (fs.existsSync(packageJsonPath)) {
69
+ var packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
70
+ if (packageJson.cordova && packageJson.cordova.plugins) {
71
+ [WRAPPER_PLUGIN_ID, PLUGIN_ID].forEach(function(pluginId) {
72
+ if (packageJson.cordova.plugins[pluginId]) {
73
+ var pluginVars = packageJson.cordova.plugins[pluginId];
74
+ for (var key in pluginVars) {
75
+ pluginVariables[key] = pluginVars[key];
76
+ }
77
+ }
78
+ });
79
+ }
80
+ }
81
+ } catch (e) {
82
+ console.warn("[FirebasexFirestore] Could not read package.json for plugin variables: " + e.message);
83
+ }
84
+
85
+ // 4. CLI variable overrides (highest priority)
86
+ if (context.opts && context.opts.cli_variables) {
87
+ Object.keys(context.opts.cli_variables).forEach(function(key) {
88
+ pluginVariables[key] = context.opts.cli_variables[key];
89
+ });
90
+ }
91
+
92
+ return pluginVariables;
93
+ }
94
+
95
+ /**
96
+ * Cordova hook entry point.
97
+ * Updates the FirebaseFirestore git pod tag in the Podfile.
98
+ *
99
+ * @param {object} context - The Cordova hook context.
100
+ */
101
+ module.exports = function(context) {
102
+ var pluginVariables = resolvePluginVariables(context);
103
+ if (!pluginVariables["IOS_FIREBASE_SDK_VERSION"]) return;
104
+
105
+ var iosPlatformPath = path.join(context.opts.projectRoot, "platforms", "ios");
106
+ var podFilePath = path.join(iosPlatformPath, "Podfile");
107
+ if (!fs.existsSync(podFilePath)) return;
108
+
109
+ try {
110
+ var podFileContents = fs.readFileSync(podFilePath, "utf-8");
111
+ var sdkVersion = pluginVariables["IOS_FIREBASE_SDK_VERSION"];
112
+ // FirebaseFirestore uses a git-based pod with :tag instead of a spec version
113
+ var firestorePodRegEx = /pod 'FirebaseFirestore'[^,]+,:tag\s*=>\s*'(\d+\.\d+\.\d+[^']*)'/g;
114
+ var tagVersionRegex = /:tag\s*=>\s*'(\d+\.\d+\.\d+[^']*)'/;
115
+ var matches = podFileContents.match(firestorePodRegEx);
116
+ if (matches) {
117
+ var modified = false;
118
+ matches.forEach(function(match) {
119
+ var tagMatch = match.match(tagVersionRegex);
120
+ if (tagMatch) {
121
+ var currentVersion = tagMatch[1];
122
+ if (currentVersion !== sdkVersion) {
123
+ var updatedMatch = match.replace(":tag => '" + currentVersion + "'", ":tag => '" + sdkVersion + "'");
124
+ podFileContents = podFileContents.replace(match, updatedMatch);
125
+ modified = true;
126
+ }
127
+ }
128
+ });
129
+ if (modified) {
130
+ fs.writeFileSync(podFilePath, podFileContents);
131
+ console.log("[FirebasexFirestore] Firebase Firestore version set to v" + sdkVersion + " in Podfile");
132
+ }
133
+ }
134
+ } catch(e) {
135
+ console.warn("[FirebasexFirestore] Error updating Firebase Firestore pod version: " + e.message);
136
+ }
137
+ };
@@ -0,0 +1,157 @@
1
+ /**
2
+ * @file post_install.js
3
+ * @brief Cordova "after_prepare" hook for the cordova-plugin-firebasex-firestore plugin.
4
+ *
5
+ * Modifies the plugin's `plugin.xml` to switch between the standard and precompiled
6
+ * FirebaseFirestore iOS pods based on the `IOS_USE_PRECOMPILED_FIRESTORE_POD` plugin variable.
7
+ *
8
+ * When enabled, the standard `FirebaseFirestore` pod (installed from CocoaPods) is replaced
9
+ * with the precompiled version from the `invertase/firestore-ios-sdk-frameworks` GitHub
10
+ * repository, which significantly reduces iOS build times.
11
+ *
12
+ * When disabled (or not set), restores the standard CocoaPods-based pod if the precompiled
13
+ * version was previously applied.
14
+ *
15
+ * Plugin variables are resolved using a 3-layer override strategy:
16
+ * 1. Defaults from `plugin.xml` `<preference>` elements.
17
+ * 2. Overrides from `config.xml` `<plugin><variable>` elements.
18
+ * 3. Overrides from `package.json` `cordova.plugins` entries (highest priority).
19
+ *
20
+ * For layers 2 and 3, variables are checked under both the wrapper meta-plugin ID
21
+ * (`cordova-plugin-firebasex`) and this plugin's own ID, allowing users who install
22
+ * via the wrapper to specify variables under the original monolithic plugin name.
23
+ *
24
+ * @module scripts/post_install
25
+ */
26
+ var fs = require("fs");
27
+ var path = require("path");
28
+
29
+ /** @constant {string} The plugin identifier. */
30
+ var PLUGIN_ID = "cordova-plugin-firebasex-firestore";
31
+ /** @constant {string} The wrapper meta-plugin identifier used as a fallback source for plugin variables. */
32
+ var WRAPPER_PLUGIN_ID = "cordova-plugin-firebasex";
33
+
34
+ /**
35
+ * Resolves plugin variables using a 3-layer override strategy:
36
+ * 1. Default values from `plugin.xml` `<preference>` elements.
37
+ * 2. Overrides from `config.xml` `<plugin><variable>` elements.
38
+ * 3. Overrides from `package.json` `cordova.plugins` entries (highest priority).
39
+ *
40
+ * @returns {Object} Resolved plugin variable key/value pairs.
41
+ */
42
+ function getPluginVariables() {
43
+ var variables = {};
44
+
45
+ // Try reading from plugin.xml
46
+ try {
47
+ var pluginXmlPath = path.join("plugins", PLUGIN_ID, "plugin.xml");
48
+ if (fs.existsSync(pluginXmlPath)) {
49
+ var pluginXml = fs.readFileSync(pluginXmlPath, "utf-8");
50
+ var prefRegex = /<preference\s+name="([^"]+)"\s+default="([^"]+)"\s*\/>/g;
51
+ var match;
52
+ while ((match = prefRegex.exec(pluginXml)) !== null) {
53
+ variables[match[1]] = match[2];
54
+ }
55
+ }
56
+ } catch (e) {
57
+ console.warn("Could not read plugin.xml: " + e.message);
58
+ }
59
+
60
+ // Override with values from config.xml (check both wrapper and own plugin ID)
61
+ try {
62
+ var configXmlPath = path.join("config.xml");
63
+ if (fs.existsSync(configXmlPath)) {
64
+ var configXml = fs.readFileSync(configXmlPath, "utf-8");
65
+ [WRAPPER_PLUGIN_ID, PLUGIN_ID].forEach(function(pluginId) {
66
+ var pluginRegex = new RegExp('<plugin[^>]+name="' + pluginId + '"[^>]*>(.*?)</plugin>', "s");
67
+ var pluginMatch = configXml.match(pluginRegex);
68
+ if (pluginMatch) {
69
+ var varRegex = /<variable\s+name="([^"]+)"\s+value="([^"]+)"\s*\/>/g;
70
+ var varMatch;
71
+ while ((varMatch = varRegex.exec(pluginMatch[1])) !== null) {
72
+ variables[varMatch[1]] = varMatch[2];
73
+ }
74
+ }
75
+ });
76
+ }
77
+ } catch (e) {
78
+ console.warn("Could not read config.xml: " + e.message);
79
+ }
80
+
81
+ // Override with values from package.json (check wrapper first as base, then own plugin)
82
+ try {
83
+ var packageJsonPath = path.join("package.json");
84
+ if (fs.existsSync(packageJsonPath)) {
85
+ var packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
86
+ if (packageJson.cordova && packageJson.cordova.plugins) {
87
+ [WRAPPER_PLUGIN_ID, PLUGIN_ID].forEach(function(pluginId) {
88
+ if (packageJson.cordova.plugins[pluginId]) {
89
+ var pluginVars = packageJson.cordova.plugins[pluginId];
90
+ for (var key in pluginVars) {
91
+ variables[key] = pluginVars[key];
92
+ }
93
+ }
94
+ });
95
+ }
96
+ }
97
+ } catch (e) {
98
+ console.warn("Could not read package.json: " + e.message);
99
+ }
100
+
101
+ return variables;
102
+ }
103
+
104
+ /**
105
+ * Cordova hook entry point.
106
+ *
107
+ * Reads plugin variables, then either replaces the standard FirebaseFirestore pod
108
+ * with the precompiled version (if `IOS_USE_PRECOMPILED_FIRESTORE_POD` is `true`)
109
+ * or restores the standard pod (if the precompiled version was previously applied).
110
+ *
111
+ * @param {object} context - The Cordova hook context.
112
+ */
113
+ module.exports = function (context) {
114
+ var pluginVariables = getPluginVariables();
115
+ var pluginXmlPath = path.join("plugins", PLUGIN_ID, "plugin.xml");
116
+
117
+ if (!fs.existsSync(pluginXmlPath)) {
118
+ console.warn(PLUGIN_ID + " plugin.xml not found at " + pluginXmlPath);
119
+ return;
120
+ }
121
+
122
+ var pluginXmlText = fs.readFileSync(pluginXmlPath, "utf-8");
123
+ var pluginXmlModified = false;
124
+
125
+ // Handle IOS_USE_PRECOMPILED_FIRESTORE_POD
126
+ /** @constant {RegExp} Matches the standard CocoaPods-based FirebaseFirestore pod entry. */
127
+ var standardPodRegExp = /<pod\s+name="FirebaseFirestore"\s+spec="([^"]+)"\s*\/>/;
128
+ /** @constant {RegExp} Matches the precompiled FirebaseFirestore pod entry (from invertase git repo). */
129
+ var precompiledPodRegExp = /<pod\s+name="FirebaseFirestore"\s+tag="([^"]+)"\s+git="[^"]+"\s*\/>/;;
130
+
131
+ if (pluginVariables["IOS_USE_PRECOMPILED_FIRESTORE_POD"] === "true") {
132
+ var match = pluginXmlText.match(standardPodRegExp);
133
+ if (match) {
134
+ var replacement = '<pod name="FirebaseFirestore" tag="' + match[1] + '" git="https://github.com/invertase/firestore-ios-sdk-frameworks.git" />';
135
+ pluginXmlText = pluginXmlText.replace(standardPodRegExp, replacement);
136
+ pluginXmlModified = true;
137
+ console.log("Replaced FirebaseFirestore pod with precompiled version (tag " + match[1] + ") in " + PLUGIN_ID + "/plugin.xml");
138
+ } else if (pluginXmlText.match(precompiledPodRegExp)) {
139
+ console.log("FirebaseFirestore pod already using precompiled version in " + PLUGIN_ID + "/plugin.xml");
140
+ } else {
141
+ console.warn('Failed to find <pod name="FirebaseFirestore"> in ' + PLUGIN_ID + "/plugin.xml");
142
+ }
143
+ } else {
144
+ // Restore standard pod if precompiled was previously applied
145
+ var preMatch = pluginXmlText.match(precompiledPodRegExp);
146
+ if (preMatch) {
147
+ var restored = '<pod name="FirebaseFirestore" spec="' + preMatch[1] + '"/>';
148
+ pluginXmlText = pluginXmlText.replace(precompiledPodRegExp, restored);
149
+ pluginXmlModified = true;
150
+ console.log("Restored standard FirebaseFirestore pod (spec " + preMatch[1] + ") in " + PLUGIN_ID + "/plugin.xml");
151
+ }
152
+ }
153
+
154
+ if (pluginXmlModified) {
155
+ fs.writeFileSync(pluginXmlPath, pluginXmlText, "utf-8");
156
+ }
157
+ };