react-native-3rddigital-appupdate 1.0.4 → 1.0.6

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.
@@ -23,7 +23,11 @@ export const checkOTAUpdate = async ({
23
23
  const forceUpdate = data?.forceUpdate ?? false;
24
24
  const url = data?.url ?? '';
25
25
  const bundleId = data?.bundleId ?? '';
26
- if (version <= currentVersion) return;
26
+ const currentAppVersion = DeviceInfo.getVersion();
27
+ const bundleAppVersion = data?.appVersion ?? currentAppVersion;
28
+ if (version <= currentVersion || currentAppVersion != bundleAppVersion) {
29
+ return;
30
+ }
27
31
  const downloadAndReport = () => {
28
32
  AppLoader.show(loaderOptions);
29
33
  hotUpdate.downloadBundleUri(ReactNativeBlobUtil, url, version, {
@@ -1 +1 @@
1
- {"version":3,"names":["axios","Platform","ReactNativeBlobUtil","DeviceInfo","hotUpdate","AppAlertDialog","AppLoader","API_URL","checkOTAUpdate","key","iosPackage","androidPackage","loaderOptions","dialogOptions","response","get","currentVersion","getCurrentVersion","data","OS","android","ios","version","forceUpdate","url","bundleId","downloadAndReport","show","downloadBundleUri","updateSuccess","post","status","headers","finally","hide","updateFail","error","JSON","stringify","deviceInfo","model","getModel","brand","getBrand","systemName","getSystemName","systemVersion","getSystemVersion","restartAfterInstall","restartDelay","showMessage","title","message","confirmText","cancelText","onConfirm","onCancel","err","console","warn"],"sourceRoot":"../../src","sources":["checkOTAUpdate.ts"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,QAAQ,cAAc;AACvC,OAAOC,mBAAmB,MAAM,wBAAwB;AACxD,OAAOC,UAAU,MAAM,0BAA0B;AACjD,OAAOC,SAAS,MAAM,6BAA6B;AACnD,SAASC,cAAc,QAA4B,qBAAkB;AACrE,SAASC,SAAS,QAA4B,gBAAa;AAE3D,MAAMC,OAAO,GAAG,+CAA+C;AAU/D,OAAO,MAAMC,cAAc,GAAG,MAAAA,CAAO;EACnCC,G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AQ,QAAQ,EACrC;YACEM,MAAM,EAAE,SAAS;YACjBK,KAAK,EAAEC,IAAI,CAACC,SAAS,CAACF,KAAK,CAAC;YAC5BG,UAAU,EAAE;cACVC,KAAK,EAAErC,UAAU,CAACsC,QAAQ,CAAC,CAAC;cAC5BC,KAAK,EAAEvC,UAAU,CAACwC,QAAQ,CAAC,CAAC;cAC5BC,UAAU,EAAEzC,UAAU,CAAC0C,aAAa,CAAC,CAAC;cACtCC,aAAa,EAAE3C,UAAU,CAAC4C,gBAAgB,CAAC;YAC7C;UACF,CAAC,EACD;YAAEf,OAAO,EAAE;cAAE,cAAc,EAAE;YAAmB;UAAE,CACpD,CAAC,CACAC,OAAO,CAAC,MAAM3B,SAAS,CAAC4B,IAAI,CAAC,CAAC,CAAC;QACpC,CAAC;QACDc,mBAAmB,EAAE,IAAI;QACzBC,YAAY,EAAE;MAChB,CAAC,CAAC;IACJ,CAAC;IAED,IAAI1B,WAAW,EAAE;MACfG,iBAAiB,CAAC,CAAC;IACrB,CAAC,MAAM;MACLrB,cAAc,CAAC6C,WAAW,CAAC;QACzBC,KAAK,EAAE,mBAAmB;QAC1BC,OAAO,EAAE,sCAAsC;QAC/CC,WAAW,EAAE,QAAQ;QACrBC,UAAU,EAAE,QAAQ;QACpBC,SAAS,EAAE7B,iBAAiB;QAC5B8B,QAAQ,EAAEA,CAAA,KAAM,CAAC,CAAC;QAClB,GAAG3C;MACL,CAAC,CAAC;IACJ;EACF,CAAC,CAAC,OAAO4C,GAAG,EAAE;IACZC,OAAO,CAACC,IAAI,CAAC,0BAA0B,EAAEF,GAAG,CAAC;EAC/C;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["axios","Platform","ReactNativeBlobUtil","DeviceInfo","hotUpdate","AppAlertDialog","AppLoader","API_URL","checkOTAUpdate","key","iosPackage","androidPackage","loaderOptions","dialogOptions","response","get","currentVersion","getCurrentVersion","data","OS","android","ios","version","forceUpdate","url","bundleId","currentAppVersion","getVersion","bundleAppVersion","appVersion","downloadAndReport","show","downloadBundleUri","updateSuccess","post","status","headers","finally","hide","updateFail","error","JSON","stringify","deviceInfo","model","getModel","brand","getBrand","systemName","getSystemName","systemVersion","getSystemVersion","restartAfterInstall","restartDelay","showMessage","title","message","confirmText","cancelText","onConfirm","onCancel","err","console","warn"],"sourceRoot":"../../src","sources":["checkOTAUpdate.ts"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,QAAQ,cAAc;AACvC,OAAOC,mBAAmB,MAAM,wBAAwB;AACxD,OAAOC,UAAU,MAAM,0BAA0B;AACjD,OAAOC,SAAS,MAAM,6BAA6B;AACnD,SAASC,cAAc,QAA4B,qBAAkB;AACrE,SAASC,SAAS,QAA4B,gBAAa;AAE3D,MAAMC,OAAO,GAAG,+CAA+C;AAU/D,OAAO,MAAMC,cAAc,GAAG,MAAAA,CAAO;EACnCC,GAAG;EACHC,UAAU;EACVC,cAAc;EACdC,aAAa;EACbC;AACc,CAAC,KAAK;EACpB,IAAI;IACF,MAAMC,QAAQ,GAAG,MAAMd,KAAK,CAACe,GAAG,CAC9B,GAAGR,OAAO,2BAA2BE,GAAG,eAAeC,UAAU,mBAAmBC,cAAc,EACpG,CAAC;IAED,MAAMK,cAAc,GAAG,MAAMZ,SAAS,CAACa,iBAAiB,CAAC,CAAC;IAC1D,MAAMC,IAAI,GACRjB,QAAQ,CAACkB,EAAE,KAAK,SAAS,GAAGL,QAAQ,EAAEI,IAAI,EAAEE,OAAO,GAAGN,QAAQ,EAAEI,IAAI,EAAEG,GAAG;IAC3E,MAAMC,OAAO,GAAGJ,IAAI,EAAEI,OAAO,IAAI,CAAC;IAClC,MAAMC,WAAW,GAAGL,IAAI,EAAEK,WAAW,IAAI,KAAK;IAC9C,MAAMC,GAAG,GAAGN,IAAI,EAAEM,GAAG,IAAI,EAAE;IAC3B,MAAMC,QAAQ,GAAGP,IAAI,EAAEO,QAAQ,IAAI,EAAE;IACrC,MAAMC,iBAAiB,GA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AAmB,EAAE,IAAI;QACzBC,YAAY,EAAE;MAChB,CAAC,CAAC;IACJ,CAAC;IAED,IAAI9B,WAAW,EAAE;MACfO,iBAAiB,CAAC,CAAC;IACrB,CAAC,MAAM;MACLzB,cAAc,CAACiD,WAAW,CAAC;QACzBC,KAAK,EAAE,mBAAmB;QAC1BC,OAAO,EAAE,sCAAsC;QAC/CC,WAAW,EAAE,QAAQ;QACrBC,UAAU,EAAE,QAAQ;QACpBC,SAAS,EAAE7B,iBAAiB;QAC5B8B,QAAQ,EAAEA,CAAA,KAAM,CAAC,CAAC;QAClB,GAAG/C;MACL,CAAC,CAAC;IACJ;EACF,CAAC,CAAC,OAAOgD,GAAG,EAAE;IACZC,OAAO,CAACC,IAAI,CAAC,0BAA0B,EAAEF,GAAG,CAAC;EAC/C;AACF,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"checkOTAUpdate.d.ts","sourceRoot":"","sources":["../../../src/checkOTAUpdate.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5D,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,aAAa,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC;CAC/D,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,oEAMlC,cAAc,kBAmEhB,CAAC"}
1
+ {"version":3,"file":"checkOTAUpdate.d.ts","sourceRoot":"","sources":["../../../src/checkOTAUpdate.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5D,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,aAAa,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC;CAC/D,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,oEAMlC,cAAc,kBAuEhB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-3rddigital-appupdate",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A React Native library for seamless over-the-air (OTA) updates with version checks, automatic bundle download, and customizable user prompts for iOS and Android.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
package/scripts/bundle.js CHANGED
@@ -8,6 +8,9 @@ const { input, select, confirm } = require('@inquirer/prompts');
8
8
 
9
9
  const API_BASE_URL = 'https://dev.3rddigital.com/appupdate-api/api/';
10
10
 
11
+ /**
12
+ * Run a shell command synchronously.
13
+ */
11
14
  function run(command) {
12
15
  try {
13
16
  console.log(`\n➡️ Running: ${command}\n`);
@@ -19,6 +22,9 @@ function run(command) {
19
22
  }
20
23
  }
21
24
 
25
+ /**
26
+ * Upload bundle file to server.
27
+ */
22
28
  async function uploadBundle({ filePath, platform, config }) {
23
29
  console.log(`📤 Uploading ${platform} bundle to server...`);
24
30
 
@@ -59,6 +65,9 @@ async function uploadBundle({ filePath, platform, config }) {
59
65
  }
60
66
  }
61
67
 
68
+ /**
69
+ * Build Android JS bundle and zip it.
70
+ */
62
71
  function buildAndroid() {
63
72
  console.log('📦 Building Android bundle...');
64
73
  const outputPath = path.join('android', 'index.android.bundle.zip');
@@ -74,6 +83,9 @@ function buildAndroid() {
74
83
  return outputPath;
75
84
  }
76
85
 
86
+ /**
87
+ * Build iOS JS bundle and zip it.
88
+ */
77
89
  function buildIOS() {
78
90
  console.log('📦 Building iOS bundle...');
79
91
  const outputPath = path.join('ios', 'main.jsbundle.zip');
@@ -89,6 +101,84 @@ function buildIOS() {
89
101
  return outputPath;
90
102
  }
91
103
 
104
+ /**
105
+ * Automatically detect app version from native files.
106
+ */
107
+ function getAppVersion(platform) {
108
+ try {
109
+ // Find the actual React Native project root (two levels up from node_modules)
110
+ let projectRoot = path.resolve(__dirname);
111
+ while (
112
+ projectRoot.includes('node_modules') &&
113
+ !fs.existsSync(path.join(projectRoot, 'package.json'))
114
+ ) {
115
+ projectRoot = path.resolve(projectRoot, '..');
116
+ }
117
+
118
+ // Once we exit node_modules, ensure we’re at the React Native app root
119
+ if (projectRoot.includes('node_modules')) {
120
+ projectRoot = path.resolve(projectRoot, '../../');
121
+ }
122
+
123
+ if (platform === 'android') {
124
+ const gradlePath = path.join(
125
+ projectRoot,
126
+ 'android',
127
+ 'app',
128
+ 'build.gradle'
129
+ );
130
+ if (!fs.existsSync(gradlePath)) {
131
+ console.warn(`⚠️ Android build.gradle not found at ${gradlePath}`);
132
+ return null;
133
+ }
134
+ const gradleContent = fs.readFileSync(gradlePath, 'utf8');
135
+ const match = gradleContent.match(/versionName\s+"([\d.]+)"/);
136
+ if (match && match[1]) {
137
+ return match[1];
138
+ } else {
139
+ console.warn('⚠️ Could not find versionName in build.gradle.');
140
+ }
141
+ } else if (platform === 'ios') {
142
+ const iosDir = path.join(projectRoot, 'ios');
143
+ if (!fs.existsSync(iosDir)) {
144
+ console.warn(`⚠️ iOS folder not found at ${iosDir}`);
145
+ return null;
146
+ }
147
+
148
+ const projectDir = fs
149
+ .readdirSync(iosDir)
150
+ .find((d) => d.endsWith('.xcodeproj'));
151
+
152
+ if (!projectDir) {
153
+ console.warn('⚠️ .xcodeproj not found inside ios directory.');
154
+ return null;
155
+ }
156
+
157
+ const pbxprojPath = path.join(iosDir, projectDir, 'project.pbxproj');
158
+ if (!fs.existsSync(pbxprojPath)) {
159
+ console.warn('⚠️ project.pbxproj not found.');
160
+ return null;
161
+ }
162
+
163
+ const pbxprojContent = fs.readFileSync(pbxprojPath, 'utf8');
164
+ const match = pbxprojContent.match(/MARKETING_VERSION\s*=\s*([\d.]+);/);
165
+
166
+ if (match && match[1]) {
167
+ return match[1];
168
+ } else {
169
+ console.warn('⚠️ Could not find MARKETING_VERSION in project.pbxproj.');
170
+ }
171
+ }
172
+ } catch (err) {
173
+ console.warn(`⚠️ Failed to read ${platform} version:`, err.message);
174
+ }
175
+
176
+ return null;
177
+ }
178
+
179
+ /**
180
+ * Get common configuration (API token, project ID, env).
181
+ */
92
182
  async function getCommonConfig() {
93
183
  console.log(`\n⚙️ Enter common configuration (applies to both platforms)\n`);
94
184
 
@@ -113,22 +203,34 @@ async function getCommonConfig() {
113
203
  return { API_TOKEN, PROJECT_ID, ENVIRONMENT };
114
204
  }
115
205
 
206
+ /**
207
+ * Get platform-specific configuration with version auto-detection.
208
+ */
116
209
  async function getPlatformSpecificConfig(platform) {
117
- console.log(`\n🔧 Enter ${platform.toUpperCase()} specific configuration\n`);
210
+ console.log(`\n🔧 Configuring ${platform.toUpperCase()}...\n`);
118
211
 
119
- const VERSION = await input({
120
- message: `(${platform}) Enter App Version (e.g. 1.0.0):`,
121
- validate: (val) => (val.trim() ? true : 'Version is required'),
122
- });
212
+ let detectedVersion = getAppVersion(platform);
213
+ if (detectedVersion) {
214
+ console.log(`📱 Detected ${platform} version: ${detectedVersion}`);
215
+ } else {
216
+ console.warn(`⚠️ Could not detect ${platform} version automatically.`);
217
+ detectedVersion = await input({
218
+ message: `(${platform}) Enter App Version (e.g. 1.0.0):`,
219
+ validate: (val) => (val.trim() ? true : 'Version is required'),
220
+ });
221
+ }
123
222
 
124
223
  const FORCE_UPDATE = await confirm({
125
224
  message: `(${platform}) Force Update?`,
126
225
  default: false,
127
226
  });
128
227
 
129
- return { VERSION, FORCE_UPDATE };
228
+ return { VERSION: detectedVersion, FORCE_UPDATE };
130
229
  }
131
230
 
231
+ /**
232
+ * Entry point
233
+ */
132
234
  (async () => {
133
235
  try {
134
236
  const platform = process.argv[2];
@@ -35,8 +35,12 @@ export const checkOTAUpdate = async ({
35
35
  const forceUpdate = data?.forceUpdate ?? false;
36
36
  const url = data?.url ?? '';
37
37
  const bundleId = data?.bundleId ?? '';
38
+ const currentAppVersion = DeviceInfo.getVersion();
39
+ const bundleAppVersion = data?.appVersion ?? currentAppVersion;
38
40
 
39
- if (version <= currentVersion) return;
41
+ if (version <= currentVersion || currentAppVersion != bundleAppVersion) {
42
+ return;
43
+ }
40
44
 
41
45
  const downloadAndReport = () => {
42
46
  AppLoader.show(loaderOptions);