react-native-3rddigital-appupdate 1.0.4 → 1.0.5
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
|
-
|
|
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,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;
|
|
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,QAA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BC,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,
|
|
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.
|
|
3
|
+
"version": "1.0.5",
|
|
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,62 @@ 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
|
+
if (platform === 'android') {
|
|
110
|
+
// Read Android versionName from build.gradle
|
|
111
|
+
const gradlePath = path.join(__dirname, 'android', 'app', 'build.gradle');
|
|
112
|
+
if (!fs.existsSync(gradlePath)) {
|
|
113
|
+
console.warn('⚠️ Android build.gradle not found.');
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const gradleContent = fs.readFileSync(gradlePath, 'utf8');
|
|
117
|
+
const match = gradleContent.match(/versionName\s+"([\d.]+)"/);
|
|
118
|
+
if (match && match[1]) {
|
|
119
|
+
return match[1];
|
|
120
|
+
} else {
|
|
121
|
+
console.warn('⚠️ Could not find versionName in build.gradle.');
|
|
122
|
+
}
|
|
123
|
+
} else if (platform === 'ios') {
|
|
124
|
+
// Read MARKETING_VERSION directly from project.pbxproj
|
|
125
|
+
const iosDir = path.join(__dirname, 'ios');
|
|
126
|
+
const projectDir = fs
|
|
127
|
+
.readdirSync(iosDir)
|
|
128
|
+
.find((d) => d.endsWith('.xcodeproj'));
|
|
129
|
+
|
|
130
|
+
if (!projectDir) {
|
|
131
|
+
console.warn('⚠️ .xcodeproj not found inside ios directory.');
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const pbxprojPath = path.join(iosDir, projectDir, 'project.pbxproj');
|
|
136
|
+
if (!fs.existsSync(pbxprojPath)) {
|
|
137
|
+
console.warn('⚠️ project.pbxproj not found.');
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const pbxprojContent = fs.readFileSync(pbxprojPath, 'utf8');
|
|
142
|
+
const match = pbxprojContent.match(/MARKETING_VERSION\s*=\s*([\d.]+);/);
|
|
143
|
+
|
|
144
|
+
if (match && match[1]) {
|
|
145
|
+
return match[1];
|
|
146
|
+
} else {
|
|
147
|
+
console.warn('⚠️ Could not find MARKETING_VERSION in project.pbxproj.');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} catch (err) {
|
|
151
|
+
console.warn(`⚠️ Failed to read ${platform} version:`, err.message);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Get common configuration (API token, project ID, env).
|
|
159
|
+
*/
|
|
92
160
|
async function getCommonConfig() {
|
|
93
161
|
console.log(`\n⚙️ Enter common configuration (applies to both platforms)\n`);
|
|
94
162
|
|
|
@@ -113,22 +181,34 @@ async function getCommonConfig() {
|
|
|
113
181
|
return { API_TOKEN, PROJECT_ID, ENVIRONMENT };
|
|
114
182
|
}
|
|
115
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Get platform-specific configuration with version auto-detection.
|
|
186
|
+
*/
|
|
116
187
|
async function getPlatformSpecificConfig(platform) {
|
|
117
|
-
console.log(`\n🔧
|
|
188
|
+
console.log(`\n🔧 Configuring ${platform.toUpperCase()}...\n`);
|
|
118
189
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
190
|
+
let detectedVersion = getAppVersion(platform);
|
|
191
|
+
if (detectedVersion) {
|
|
192
|
+
console.log(`📱 Detected ${platform} version: ${detectedVersion}`);
|
|
193
|
+
} else {
|
|
194
|
+
console.warn(`⚠️ Could not detect ${platform} version automatically.`);
|
|
195
|
+
detectedVersion = await input({
|
|
196
|
+
message: `(${platform}) Enter App Version (e.g. 1.0.0):`,
|
|
197
|
+
validate: (val) => (val.trim() ? true : 'Version is required'),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
123
200
|
|
|
124
201
|
const FORCE_UPDATE = await confirm({
|
|
125
202
|
message: `(${platform}) Force Update?`,
|
|
126
203
|
default: false,
|
|
127
204
|
});
|
|
128
205
|
|
|
129
|
-
return { VERSION, FORCE_UPDATE };
|
|
206
|
+
return { VERSION: detectedVersion, FORCE_UPDATE };
|
|
130
207
|
}
|
|
131
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Entry point
|
|
211
|
+
*/
|
|
132
212
|
(async () => {
|
|
133
213
|
try {
|
|
134
214
|
const platform = process.argv[2];
|
package/src/checkOTAUpdate.ts
CHANGED
|
@@ -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)
|
|
41
|
+
if (version <= currentVersion || currentAppVersion != bundleAppVersion) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
40
44
|
|
|
41
45
|
const downloadAndReport = () => {
|
|
42
46
|
AppLoader.show(loaderOptions);
|