react-native-update-cli 2.17.0 → 2.19.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 (57) hide show
  1. package/lib/api.d.ts +1 -1
  2. package/lib/api.js +140 -134
  3. package/lib/app.d.ts +2 -2
  4. package/lib/app.js +60 -107
  5. package/lib/bin.js +38 -35
  6. package/lib/bundle-pack.js +57 -77
  7. package/lib/bundle-runner.js +249 -312
  8. package/lib/bundle.js +71 -89
  9. package/lib/diff.js +224 -198
  10. package/lib/exports.js +14 -37
  11. package/lib/index.js +16 -17
  12. package/lib/install.js +24 -37
  13. package/lib/locales/en.d.ts +1 -0
  14. package/lib/locales/en.js +4 -11
  15. package/lib/locales/zh.d.ts +1 -0
  16. package/lib/locales/zh.js +4 -11
  17. package/lib/package.js +164 -218
  18. package/lib/provider.js +85 -107
  19. package/lib/types.js +1 -3
  20. package/lib/user.d.ts +1 -1
  21. package/lib/user.js +26 -39
  22. package/lib/utils/add-gitignore.js +16 -29
  23. package/lib/utils/app-info-parser/aab.js +133 -157
  24. package/lib/utils/app-info-parser/apk.js +42 -39
  25. package/lib/utils/app-info-parser/app.js +5 -11
  26. package/lib/utils/app-info-parser/index.js +21 -31
  27. package/lib/utils/app-info-parser/ipa.js +35 -35
  28. package/lib/utils/app-info-parser/resource-finder.js +84 -71
  29. package/lib/utils/app-info-parser/utils.js +52 -77
  30. package/lib/utils/app-info-parser/xml-parser/binary.js +82 -90
  31. package/lib/utils/app-info-parser/xml-parser/manifest.js +88 -98
  32. package/lib/utils/app-info-parser/zip.js +43 -51
  33. package/lib/utils/check-lockfile.js +28 -37
  34. package/lib/utils/check-plugin.js +16 -32
  35. package/lib/utils/command-result.js +7 -20
  36. package/lib/utils/constants.js +23 -63
  37. package/lib/utils/dep-versions.js +21 -27
  38. package/lib/utils/git.js +20 -64
  39. package/lib/utils/hbcTransform.js +133 -246
  40. package/lib/utils/http-helper.js +33 -44
  41. package/lib/utils/i18n.js +17 -26
  42. package/lib/utils/index.js +137 -179
  43. package/lib/utils/latest-version/index.js +128 -137
  44. package/lib/utils/options.js +13 -34
  45. package/lib/utils/plugin-config.js +43 -56
  46. package/lib/utils/runtime.js +50 -108
  47. package/lib/utils/zip-entries.js +70 -97
  48. package/lib/utils/zip-options.js +80 -181
  49. package/lib/versions.js +231 -265
  50. package/package.json +19 -20
  51. package/src/api.ts +44 -3
  52. package/src/diff.ts +129 -2
  53. package/src/locales/en.ts +2 -0
  54. package/src/locales/zh.ts +2 -0
  55. package/src/package.ts +1 -1
  56. package/src/user.ts +1 -1
  57. package/src/versions.ts +1 -1
@@ -1,31 +1,23 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "IpaParser", {
6
- enumerable: true,
7
- get: function() {
8
- return IpaParser;
9
- }
10
- });
11
- const _utils = require("./utils");
12
- const _zip = require("./zip");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IpaParser = void 0;
13
4
  const parseBplist = require('bplist-parser').parseBuffer;
14
5
  const cgbiToPng = require('cgbi-to-png');
6
+ const utils_1 = require("./utils");
7
+ const zip_1 = require("./zip");
15
8
  const PlistName = /payload\/[^/]+?.app\/info.plist$/i;
16
9
  const ProvisionName = /payload\/.+?\.app\/embedded.mobileprovision/;
17
10
  let parsePlistPromise;
18
11
  function loadParsePlist() {
19
12
  if (!parsePlistPromise) {
20
- parsePlistPromise = Promise.resolve().then(async ()=>{
13
+ parsePlistPromise = Promise.resolve().then(async () => {
21
14
  try {
22
15
  return require('plist').parse;
23
- } catch (requireError) {
24
- var _plistModule_parse;
25
- var _plistModule_default;
16
+ }
17
+ catch (requireError) {
26
18
  const importModule = new Function('specifier', 'return import(specifier)');
27
19
  const plistModule = await importModule('plist');
28
- const parsePlist = (_plistModule_parse = plistModule.parse) != null ? _plistModule_parse : (_plistModule_default = plistModule.default) == null ? void 0 : _plistModule_default.parse;
20
+ const parsePlist = plistModule.parse ?? plistModule.default?.parse;
29
21
  if (!parsePlist) {
30
22
  throw requireError;
31
23
  }
@@ -35,27 +27,30 @@ function loadParsePlist() {
35
27
  }
36
28
  return parsePlistPromise;
37
29
  }
38
- class IpaParser extends _zip.Zip {
30
+ class IpaParser extends zip_1.Zip {
39
31
  async parse() {
40
32
  const parsePlist = await loadParsePlist();
41
- const buffers = await this.getEntries([
42
- PlistName,
43
- ProvisionName
44
- ]);
33
+ const buffers = await this.getEntries([PlistName, ProvisionName]);
45
34
  if (!buffers[PlistName]) {
46
35
  throw new Error("Info.plist can't be found.");
47
36
  }
48
37
  const plistInfo = this._parsePlist(buffers[PlistName], parsePlist);
49
38
  const provisionInfo = this._parseProvision(buffers[ProvisionName], parsePlist);
50
39
  plistInfo.mobileProvision = provisionInfo;
51
- const iconRegex = new RegExp((0, _utils.findIpaIconPath)(plistInfo).toLowerCase());
40
+ const iconRegex = new RegExp((0, utils_1.findIpaIconPath)(plistInfo).toLowerCase());
52
41
  const iconBuffer = await this.getEntry(iconRegex);
53
42
  try {
54
- plistInfo.icon = iconBuffer ? (0, _utils.getBase64FromBuffer)(cgbiToPng.revert(iconBuffer)) : null;
55
- } catch (err) {
56
- if ((0, _utils.isBrowser)()) {
57
- plistInfo.icon = iconBuffer ? (0, _utils.getBase64FromBuffer)(window.btoa(String.fromCharCode(...iconBuffer))) : null;
58
- } else {
43
+ plistInfo.icon = iconBuffer
44
+ ? (0, utils_1.getBase64FromBuffer)(cgbiToPng.revert(iconBuffer))
45
+ : null;
46
+ }
47
+ catch (err) {
48
+ if ((0, utils_1.isBrowser)()) {
49
+ plistInfo.icon = iconBuffer
50
+ ? (0, utils_1.getBase64FromBuffer)(window.btoa(String.fromCharCode(...iconBuffer)))
51
+ : null;
52
+ }
53
+ else {
59
54
  plistInfo.icon = null;
60
55
  console.warn('[Warning] failed to parse icon: ', err);
61
56
  }
@@ -63,24 +58,28 @@ class IpaParser extends _zip.Zip {
63
58
  return plistInfo;
64
59
  }
65
60
  /**
66
- * Parse plist
67
- * @param {Buffer} buffer // plist file's buffer
68
- */ _parsePlist(buffer, parsePlist) {
61
+ * Parse plist
62
+ * @param {Buffer} buffer // plist file's buffer
63
+ */
64
+ _parsePlist(buffer, parsePlist) {
69
65
  let result;
70
66
  const bufferType = buffer[0];
71
67
  if (bufferType === 60 || bufferType === 239) {
72
68
  result = parsePlist(buffer.toString());
73
- } else if (bufferType === 98) {
69
+ }
70
+ else if (bufferType === 98) {
74
71
  result = parseBplist(buffer)[0];
75
- } else {
72
+ }
73
+ else {
76
74
  throw new Error('Unknown plist buffer type.');
77
75
  }
78
76
  return result;
79
77
  }
80
78
  /**
81
- * parse provision
82
- * @param {Buffer} buffer // provision file's buffer
83
- */ _parseProvision(buffer, parsePlist) {
79
+ * parse provision
80
+ * @param {Buffer} buffer // provision file's buffer
81
+ */
82
+ _parseProvision(buffer, parsePlist) {
84
83
  let info = {};
85
84
  if (buffer) {
86
85
  let content = buffer.toString('utf-8');
@@ -94,3 +93,4 @@ class IpaParser extends _zip.Zip {
94
93
  return info;
95
94
  }
96
95
  }
96
+ exports.IpaParser = IpaParser;
@@ -1,18 +1,12 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "ResourceFinder", {
6
- enumerable: true,
7
- get: function() {
8
- return ResourceFinder;
9
- }
10
- });
11
2
  /**
12
3
  * Code translated from a C# project https://github.com/hylander0/Iteedee.ApkReader/blob/master/Iteedee.ApkReader/ApkResourceFinder.cs
13
4
  *
14
5
  * Decode binary file `resources.arsc` from a .apk file to a JavaScript Object.
15
- */ const ByteBuffer = require('bytebuffer');
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ResourceFinder = void 0;
9
+ const ByteBuffer = require('bytebuffer');
16
10
  const DEBUG = false;
17
11
  const RES_STRING_POOL_TYPE = 0x0001;
18
12
  const RES_TABLE_TYPE = 0x0002;
@@ -22,24 +16,32 @@ const RES_TABLE_TYPE_SPEC_TYPE = 0x0202;
22
16
  const TYPE_REFERENCE = 0x01;
23
17
  const TYPE_STRING = 0x03;
24
18
  class ResourceFinder {
19
+ valueStringPool = null;
20
+ typeStringPool = null;
21
+ keyStringPool = null;
22
+ packageId = 0;
23
+ responseMap = {};
24
+ entryMap = {};
25
25
  /**
26
- * Same to C# BinaryReader.readBytes
27
- *
28
- * @param bb ByteBuffer
29
- * @param len length
30
- * @returns {Buffer}
31
- */ static readBytes(bb, len) {
26
+ * Same to C# BinaryReader.readBytes
27
+ *
28
+ * @param bb ByteBuffer
29
+ * @param len length
30
+ * @returns {Buffer}
31
+ */
32
+ static readBytes(bb, len) {
32
33
  const uint8Array = new Uint8Array(len);
33
- for(let i = 0; i < len; i++){
34
+ for (let i = 0; i < len; i++) {
34
35
  uint8Array[i] = bb.readUint8();
35
36
  }
36
37
  return ByteBuffer.wrap(uint8Array, 'binary', true);
37
38
  }
38
39
  /**
39
- *
40
- * @param {ByteBuffer} bb
41
- * @return {Map<String, Set<String>>}
42
- */ processResourceTable(resourceBuffer) {
40
+ *
41
+ * @param {ByteBuffer} bb
42
+ * @return {Map<String, Set<String>>}
43
+ */
44
+ processResourceTable(resourceBuffer) {
43
45
  const bb = ByteBuffer.wrap(resourceBuffer, 'binary', true);
44
46
  const type = bb.readShort();
45
47
  const headerSize = bb.readShort();
@@ -56,7 +58,7 @@ class ResourceFinder {
56
58
  bb.offset = headerSize;
57
59
  let realStringPoolCount = 0;
58
60
  let realPackageCount = 0;
59
- while(true){
61
+ while (true) {
60
62
  let pos = 0;
61
63
  let t = 0;
62
64
  let _hs = 0;
@@ -66,7 +68,8 @@ class ResourceFinder {
66
68
  t = bb.readShort();
67
69
  _hs = bb.readShort();
68
70
  s = bb.readInt();
69
- } catch (_e) {
71
+ }
72
+ catch (_e) {
70
73
  break;
71
74
  }
72
75
  if (t === RES_STRING_POOL_TYPE) {
@@ -82,7 +85,8 @@ class ResourceFinder {
82
85
  this.valueStringPool = this.processStringPool(bb2);
83
86
  }
84
87
  realStringPoolCount++;
85
- } else if (t === RES_TABLE_PACKAGE_TYPE) {
88
+ }
89
+ else if (t === RES_TABLE_PACKAGE_TYPE) {
86
90
  if (DEBUG) {
87
91
  console.log(`Processing the package ${realPackageCount} ...`);
88
92
  }
@@ -93,11 +97,13 @@ class ResourceFinder {
93
97
  bb2.LE();
94
98
  this.processPackage(bb2);
95
99
  realPackageCount++;
96
- } else {
100
+ }
101
+ else {
97
102
  throw new Error('Unsupported type');
98
103
  }
99
104
  bb.offset = pos + s;
100
- if (!bb.remaining()) break;
105
+ if (!bb.remaining())
106
+ break;
101
107
  }
102
108
  if (realStringPoolCount !== 1) {
103
109
  throw new Error('More than 1 string pool found!');
@@ -108,9 +114,10 @@ class ResourceFinder {
108
114
  return this.responseMap;
109
115
  }
110
116
  /**
111
- *
112
- * @param {ByteBuffer} bb
113
- */ processPackage(bb) {
117
+ *
118
+ * @param {ByteBuffer} bb
119
+ */
120
+ processPackage(bb) {
114
121
  const type = bb.readShort();
115
122
  const headerSize = bb.readShort();
116
123
  const size = bb.readInt();
@@ -118,7 +125,7 @@ class ResourceFinder {
118
125
  void type;
119
126
  void size;
120
127
  this.packageId = id;
121
- for(let i = 0; i < 256; ++i){
128
+ for (let i = 0; i < 256; ++i) {
122
129
  bb.readUint8();
123
130
  }
124
131
  const typeStrings = bb.readInt();
@@ -156,7 +163,7 @@ class ResourceFinder {
156
163
  let typeCount = 0;
157
164
  bb.offset = keyStrings + keySize;
158
165
  let bb2;
159
- while(true){
166
+ while (true) {
160
167
  const pos = bb.offset;
161
168
  try {
162
169
  const t = bb.readShort();
@@ -168,7 +175,8 @@ class ResourceFinder {
168
175
  bb2 = ResourceFinder.readBytes(bb, s);
169
176
  this.processTypeSpec(bb2);
170
177
  typeSpecCount++;
171
- } else if (t === RES_TABLE_TYPE_TYPE) {
178
+ }
179
+ else if (t === RES_TABLE_TYPE_TYPE) {
172
180
  bb.offset = pos;
173
181
  bb2 = ResourceFinder.readBytes(bb, s);
174
182
  this.processType(bb2);
@@ -181,7 +189,8 @@ class ResourceFinder {
181
189
  if (!bb.remaining()) {
182
190
  break;
183
191
  }
184
- } catch (_e) {
192
+ }
193
+ catch (_e) {
185
194
  break;
186
195
  }
187
196
  }
@@ -189,9 +198,10 @@ class ResourceFinder {
189
198
  void typeCount;
190
199
  }
191
200
  /**
192
- *
193
- * @param {ByteBuffer} bb
194
- */ processType(bb) {
201
+ *
202
+ * @param {ByteBuffer} bb
203
+ */
204
+ processType(bb) {
195
205
  const type = bb.readShort();
196
206
  const headerSize = bb.readShort();
197
207
  const size = bb.readInt();
@@ -212,12 +222,13 @@ class ResourceFinder {
212
222
  throw new Error('HeaderSize, entryCount and entriesStart are not valid.');
213
223
  }
214
224
  const entryIndices = new Array(entryCount);
215
- for(let i = 0; i < entryCount; ++i){
225
+ for (let i = 0; i < entryCount; ++i) {
216
226
  entryIndices[i] = bb.readInt();
217
227
  }
218
- for(let i = 0; i < entryCount; ++i){
219
- if (entryIndices[i] === -1) continue;
220
- const resourceId = this.packageId << 24 | id << 16 | i;
228
+ for (let i = 0; i < entryCount; ++i) {
229
+ if (entryIndices[i] === -1)
230
+ continue;
231
+ const resourceId = (this.packageId << 24) | (id << 16) | i;
221
232
  let entrySize = 0;
222
233
  let entryFlag = 0;
223
234
  let entryKey = 0;
@@ -225,13 +236,13 @@ class ResourceFinder {
225
236
  entrySize = bb.readShort();
226
237
  entryFlag = bb.readShort();
227
238
  entryKey = bb.readInt();
228
- } catch (_e) {
239
+ }
240
+ catch (_e) {
229
241
  break;
230
242
  }
231
243
  void entrySize;
232
244
  const FLAG_COMPLEX = 0x0001;
233
245
  if ((entryFlag & FLAG_COMPLEX) === 0) {
234
- var _this_entryMap_key;
235
246
  const valueSize = bb.readShort();
236
247
  const valueRes0 = bb.readByte();
237
248
  const valueDataType = bb.readByte();
@@ -245,7 +256,7 @@ class ResourceFinder {
245
256
  console.log(`Entry 0x${idStr}, key: ${keyStr}, simple value type: `);
246
257
  }
247
258
  const key = Number.parseInt(idStr, 16);
248
- const entryArr = (_this_entryMap_key = this.entryMap[key]) != null ? _this_entryMap_key : [];
259
+ const entryArr = this.entryMap[key] ?? [];
249
260
  entryArr.push(keyStr);
250
261
  this.entryMap[key] = entryArr;
251
262
  if (valueDataType === TYPE_STRING) {
@@ -253,20 +264,23 @@ class ResourceFinder {
253
264
  if (DEBUG && this.valueStringPool) {
254
265
  console.log(`, data: ${this.valueStringPool[valueData]}`);
255
266
  }
256
- } else if (valueDataType === TYPE_REFERENCE) {
267
+ }
268
+ else if (valueDataType === TYPE_REFERENCE) {
257
269
  refKeys[idStr] = valueData;
258
- } else {
270
+ }
271
+ else {
259
272
  data = `${valueData}`;
260
273
  if (DEBUG) {
261
274
  console.log(`, data: ${valueData}`);
262
275
  }
263
276
  }
264
277
  this.putIntoMap(`@${idStr}`, data);
265
- } else {
278
+ }
279
+ else {
266
280
  const entryParent = bb.readInt();
267
281
  const entryCountValue = bb.readInt();
268
282
  void entryParent;
269
- for(let j = 0; j < entryCountValue; ++j){
283
+ for (let j = 0; j < entryCountValue; ++j) {
270
284
  const refName = bb.readInt();
271
285
  const valueSize = bb.readShort();
272
286
  const valueRes0 = bb.readByte();
@@ -284,20 +298,21 @@ class ResourceFinder {
284
298
  }
285
299
  }
286
300
  }
287
- for(const refKey in refKeys){
301
+ for (const refKey in refKeys) {
288
302
  const values = this.responseMap[`@${Number(refKeys[refKey]).toString(16).toUpperCase()}`];
289
303
  if (values != null && Object.keys(values).length < 1000) {
290
- for (const value of values){
304
+ for (const value of values) {
291
305
  this.putIntoMap(`@${refKey}`, value);
292
306
  }
293
307
  }
294
308
  }
295
309
  }
296
310
  /**
297
- *
298
- * @param {ByteBuffer} bb
299
- * @return {Array}
300
- */ processStringPool(bb) {
311
+ *
312
+ * @param {ByteBuffer} bb
313
+ * @return {Array}
314
+ */
315
+ processStringPool(bb) {
301
316
  const type = bb.readShort();
302
317
  const headerSize = bb.readShort();
303
318
  const size = bb.readInt();
@@ -313,11 +328,11 @@ class ResourceFinder {
313
328
  void stylesStart;
314
329
  const isUtf8 = (flags & 256) !== 0;
315
330
  const offsets = new Array(stringCount);
316
- for(let i = 0; i < stringCount; ++i){
331
+ for (let i = 0; i < stringCount; ++i) {
317
332
  offsets[i] = bb.readInt();
318
333
  }
319
334
  const strings = new Array(stringCount);
320
- for(let i = 0; i < stringCount; ++i){
335
+ for (let i = 0; i < stringCount; ++i) {
321
336
  const pos = stringsStart + offsets[i];
322
337
  bb.offset = pos;
323
338
  strings[i] = '';
@@ -334,16 +349,19 @@ class ResourceFinder {
334
349
  const buffer = ResourceFinder.readBytes(bb, u8len);
335
350
  try {
336
351
  strings[i] = ByteBuffer.wrap(buffer, 'utf8', true).toString('utf8');
337
- } catch (e) {
352
+ }
353
+ catch (e) {
338
354
  if (DEBUG) {
339
355
  console.error(e);
340
356
  console.log('Error when turning buffer to utf-8 string.');
341
357
  }
342
358
  }
343
- } else {
359
+ }
360
+ else {
344
361
  strings[i] = '';
345
362
  }
346
- } else {
363
+ }
364
+ else {
347
365
  let u16len = bb.readUint16();
348
366
  if ((u16len & 0x8000) !== 0) {
349
367
  u16len = ((u16len & 0x7fff) << 16) + bb.readUint16();
@@ -353,7 +371,8 @@ class ResourceFinder {
353
371
  const buffer = ResourceFinder.readBytes(bb, len);
354
372
  try {
355
373
  strings[i] = ByteBuffer.wrap(buffer, 'utf8', true).toString('utf8');
356
- } catch (e) {
374
+ }
375
+ catch (e) {
357
376
  if (DEBUG) {
358
377
  console.error(e);
359
378
  console.log('Error when turning buffer to utf-8 string.');
@@ -368,9 +387,10 @@ class ResourceFinder {
368
387
  return strings;
369
388
  }
370
389
  /**
371
- *
372
- * @param {ByteBuffer} bb
373
- */ processTypeSpec(bb) {
390
+ *
391
+ * @param {ByteBuffer} bb
392
+ */
393
+ processTypeSpec(bb) {
374
394
  const type = bb.readShort();
375
395
  const headerSize = bb.readShort();
376
396
  const size = bb.readInt();
@@ -387,7 +407,7 @@ class ResourceFinder {
387
407
  console.log(`Processing type spec ${this.typeStringPool[id - 1]}...`);
388
408
  }
389
409
  const flags = new Array(entryCount);
390
- for(let i = 0; i < entryCount; ++i){
410
+ for (let i = 0; i < entryCount; ++i) {
391
411
  flags[i] = bb.readInt();
392
412
  }
393
413
  }
@@ -400,12 +420,5 @@ class ResourceFinder {
400
420
  this.responseMap[key].push(value);
401
421
  }
402
422
  }
403
- constructor(){
404
- this.valueStringPool = null;
405
- this.typeStringPool = null;
406
- this.keyStringPool = null;
407
- this.packageId = 0;
408
- this.responseMap = {};
409
- this.entryMap = {};
410
- }
411
423
  }
424
+ exports.ResourceFinder = ResourceFinder;
@@ -1,99 +1,70 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get decodeNullUnicode () {
13
- return decodeNullUnicode;
14
- },
15
- get findApkIconPath () {
16
- return findApkIconPath;
17
- },
18
- get findIpaIconPath () {
19
- return findIpaIconPath;
20
- },
21
- get getBase64FromBuffer () {
22
- return getBase64FromBuffer;
23
- },
24
- get isArray () {
25
- return isArray;
26
- },
27
- get isBrowser () {
28
- return isBrowser;
29
- },
30
- get isObject () {
31
- return isObject;
32
- },
33
- get isPrimitive () {
34
- return isPrimitive;
35
- },
36
- get mapInfoResource () {
37
- return mapInfoResource;
38
- }
39
- });
40
- const objectType = (value)=>Object.prototype.toString.call(value).slice(8, -1).toLowerCase();
41
- const isArray = (value)=>objectType(value) === 'array';
42
- const isObject = (value)=>objectType(value) === 'object';
43
- const isPrimitive = (value)=>value === null || [
44
- 'boolean',
45
- 'number',
46
- 'string',
47
- 'undefined'
48
- ].includes(objectType(value));
49
- const isBrowser = ()=>typeof window !== 'undefined' && typeof window.document !== 'undefined';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapInfoResource = exports.isPrimitive = exports.isObject = exports.isBrowser = exports.isArray = exports.getBase64FromBuffer = exports.findIpaIconPath = exports.findApkIconPath = exports.decodeNullUnicode = void 0;
4
+ const objectType = (value) => Object.prototype.toString.call(value).slice(8, -1).toLowerCase();
5
+ const isArray = (value) => objectType(value) === 'array';
6
+ exports.isArray = isArray;
7
+ const isObject = (value) => objectType(value) === 'object';
8
+ exports.isObject = isObject;
9
+ const isPrimitive = (value) => value === null ||
10
+ ['boolean', 'number', 'string', 'undefined'].includes(objectType(value));
11
+ exports.isPrimitive = isPrimitive;
12
+ const isBrowser = () => typeof window !== 'undefined' && typeof window.document !== 'undefined';
13
+ exports.isBrowser = isBrowser;
50
14
  /**
51
15
  * map file place with resourceMap
52
16
  * @param {Object} apkInfo // json info parsed from .apk file
53
17
  * @param {Object} resourceMap // resourceMap
54
- */ const mapInfoResource = (apkInfo, resourceMap)=>{
55
- const iteratorObj = (obj)=>{
56
- for(const i in obj){
18
+ */
19
+ const mapInfoResource = (apkInfo, resourceMap) => {
20
+ const iteratorObj = (obj) => {
21
+ for (const i in obj) {
57
22
  if (isArray(obj[i])) {
58
23
  iteratorArray(obj[i]);
59
- } else if (isObject(obj[i])) {
24
+ }
25
+ else if (isObject(obj[i])) {
60
26
  iteratorObj(obj[i]);
61
- } else if (isPrimitive(obj[i])) {
27
+ }
28
+ else if (isPrimitive(obj[i])) {
62
29
  if (isResources(obj[i])) {
63
30
  obj[i] = resourceMap[transKeyToMatchResourceMap(obj[i])];
64
31
  }
65
32
  }
66
33
  }
67
34
  };
68
- const iteratorArray = (array)=>{
35
+ const iteratorArray = (array) => {
69
36
  const l = array.length;
70
- for(let i = 0; i < l; i++){
37
+ for (let i = 0; i < l; i++) {
71
38
  if (isArray(array[i])) {
72
39
  iteratorArray(array[i]);
73
- } else if (isObject(array[i])) {
40
+ }
41
+ else if (isObject(array[i])) {
74
42
  iteratorObj(array[i]);
75
- } else if (isPrimitive(array[i])) {
43
+ }
44
+ else if (isPrimitive(array[i])) {
76
45
  if (isResources(array[i])) {
77
46
  array[i] = resourceMap[transKeyToMatchResourceMap(array[i])];
78
47
  }
79
48
  }
80
49
  }
81
50
  };
82
- const isResources = (attrValue)=>{
83
- if (!attrValue) return false;
51
+ const isResources = (attrValue) => {
52
+ if (!attrValue)
53
+ return false;
84
54
  const value = typeof attrValue === 'string' ? attrValue : attrValue.toString();
85
55
  return value.indexOf('resourceId:') === 0;
86
56
  };
87
- const transKeyToMatchResourceMap = (resourceId)=>`@${resourceId.replace('resourceId:0x', '').toUpperCase()}`;
57
+ const transKeyToMatchResourceMap = (resourceId) => `@${resourceId.replace('resourceId:0x', '').toUpperCase()}`;
88
58
  iteratorObj(apkInfo);
89
59
  return apkInfo;
90
60
  };
61
+ exports.mapInfoResource = mapInfoResource;
91
62
  /**
92
63
  * find .apk file's icon path from json info
93
64
  * @param info // json info parsed from .apk file
94
- */ const findApkIconPath = (info)=>{
95
- var _info_application_icon;
96
- if (!((_info_application_icon = info.application.icon) == null ? void 0 : _info_application_icon.splice)) {
65
+ */
66
+ const findApkIconPath = (info) => {
67
+ if (!info.application.icon?.splice) {
97
68
  return '';
98
69
  }
99
70
  const rulesMap = {
@@ -101,22 +72,20 @@ const isBrowser = ()=>typeof window !== 'undefined' && typeof window.document !=
101
72
  hdpi: 72,
102
73
  xhdpi: 96,
103
74
  xxdpi: 144,
104
- xxxhdpi: 192
75
+ xxxhdpi: 192,
105
76
  };
106
77
  const resultMap = {};
107
- const maxDpiIcon = {
108
- dpi: 120,
109
- icon: ''
110
- };
111
- for(const i in rulesMap){
112
- info.application.icon.some((icon)=>{
78
+ const maxDpiIcon = { dpi: 120, icon: '' };
79
+ for (const i in rulesMap) {
80
+ info.application.icon.some((icon) => {
113
81
  if (icon && icon.indexOf(i) !== -1) {
114
82
  resultMap[`application-icon-${rulesMap[i]}`] = icon;
115
83
  return true;
116
84
  }
117
85
  return false;
118
86
  });
119
- if (resultMap[`application-icon-${rulesMap[i]}`] && rulesMap[i] >= maxDpiIcon.dpi) {
87
+ if (resultMap[`application-icon-${rulesMap[i]}`] &&
88
+ rulesMap[i] >= maxDpiIcon.dpi) {
120
89
  maxDpiIcon.dpi = rulesMap[i];
121
90
  maxDpiIcon.icon = resultMap[`application-icon-${rulesMap[i]}`];
122
91
  }
@@ -128,33 +97,39 @@ const isBrowser = ()=>typeof window !== 'undefined' && typeof window.document !=
128
97
  }
129
98
  return maxDpiIcon.icon;
130
99
  };
100
+ exports.findApkIconPath = findApkIconPath;
131
101
  /**
132
102
  * find .ipa file's icon path from json info
133
103
  * @param info // json info parsed from .ipa file
134
- */ const findIpaIconPath = (info)=>{
135
- var _info_CFBundleIcons_CFBundlePrimaryIcon_CFBundleIconFiles, _info_CFBundleIcons_CFBundlePrimaryIcon, _info_CFBundleIcons, _info_CFBundleIconFiles;
136
- if ((_info_CFBundleIcons = info.CFBundleIcons) == null ? void 0 : (_info_CFBundleIcons_CFBundlePrimaryIcon = _info_CFBundleIcons.CFBundlePrimaryIcon) == null ? void 0 : (_info_CFBundleIcons_CFBundlePrimaryIcon_CFBundleIconFiles = _info_CFBundleIcons_CFBundlePrimaryIcon.CFBundleIconFiles) == null ? void 0 : _info_CFBundleIcons_CFBundlePrimaryIcon_CFBundleIconFiles.length) {
104
+ */
105
+ const findIpaIconPath = (info) => {
106
+ if (info.CFBundleIcons?.CFBundlePrimaryIcon?.CFBundleIconFiles?.length) {
137
107
  return info.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles[info.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles.length - 1];
138
108
  }
139
- if ((_info_CFBundleIconFiles = info.CFBundleIconFiles) == null ? void 0 : _info_CFBundleIconFiles.length) {
109
+ if (info.CFBundleIconFiles?.length) {
140
110
  return info.CFBundleIconFiles[info.CFBundleIconFiles.length - 1];
141
111
  }
142
112
  return '.app/Icon.png';
143
113
  };
114
+ exports.findIpaIconPath = findIpaIconPath;
144
115
  /**
145
116
  * transform buffer to base64
146
117
  * @param {Buffer} buffer
147
- */ const getBase64FromBuffer = (buffer)=>{
118
+ */
119
+ const getBase64FromBuffer = (buffer) => {
148
120
  const base64 = typeof buffer === 'string' ? buffer : buffer.toString('base64');
149
121
  return `data:image/png;base64,${base64}`;
150
122
  };
123
+ exports.getBase64FromBuffer = getBase64FromBuffer;
151
124
  /**
152
125
  * 去除unicode空字符
153
126
  * @param {String} str
154
- */ const decodeNullUnicode = (value)=>{
127
+ */
128
+ const decodeNullUnicode = (value) => {
155
129
  if (typeof value === 'string') {
156
130
  // biome-ignore lint/suspicious/noControlCharactersInRegex: strips null unicode padding from decoded strings
157
131
  return value.replace(/\u0000/g, '');
158
132
  }
159
133
  return value;
160
134
  };
135
+ exports.decodeNullUnicode = decodeNullUnicode;