react-native-update-cli 2.24.2 → 2.26.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 (98) hide show
  1. package/README.md +12 -5
  2. package/README.zh-CN.md +12 -5
  3. package/cli.json +7 -1
  4. package/lib/api.d.ts +2 -0
  5. package/lib/api.js +63 -18
  6. package/lib/app.js +25 -3
  7. package/lib/bin.js +39 -45
  8. package/lib/bundle-runner.d.ts +45 -1
  9. package/lib/bundle-runner.js +303 -34
  10. package/lib/bundle.d.ts +1 -1
  11. package/lib/bundle.js +23 -7
  12. package/lib/commands.d.ts +6 -0
  13. package/lib/commands.js +65 -0
  14. package/lib/locales/en.d.ts +7 -14
  15. package/lib/locales/en.js +10 -17
  16. package/lib/locales/zh.d.ts +7 -13
  17. package/lib/locales/zh.js +10 -16
  18. package/lib/package.js +4 -0
  19. package/lib/provider.d.ts +1 -1
  20. package/lib/provider.js +3 -1
  21. package/lib/symbolicate.js +7 -2
  22. package/lib/types.d.ts +1 -0
  23. package/lib/user.js +6 -0
  24. package/lib/utils/add-gitignore.js +7 -1
  25. package/lib/utils/dep-versions.d.ts +7 -0
  26. package/lib/utils/dep-versions.js +78 -26
  27. package/lib/utils/git.js +9 -6
  28. package/lib/utils/hbcTransform.d.ts +15 -0
  29. package/lib/utils/hbcTransform.js +22 -0
  30. package/lib/utils/hermes-base.d.ts +61 -6
  31. package/lib/utils/hermes-base.js +328 -46
  32. package/lib/utils/hermes-literals.d.ts +51 -0
  33. package/lib/utils/hermes-literals.js +210 -0
  34. package/lib/utils/i18n.d.ts +5 -0
  35. package/lib/utils/i18n.js +14 -1
  36. package/lib/utils/index.d.ts +2 -1
  37. package/lib/utils/index.js +9 -4
  38. package/lib/utils/latest-version/index.js +8 -0
  39. package/lib/utils/runtime.d.ts +21 -0
  40. package/lib/utils/runtime.js +138 -5
  41. package/lib/utils/zip-range.js +3 -2
  42. package/lib/versions.js +14 -4
  43. package/package.json +6 -3
  44. package/lib/index.d.ts +0 -1
  45. package/lib/index.js +0 -17
  46. package/src/api.ts +0 -470
  47. package/src/app.ts +0 -241
  48. package/src/auto-update.ts +0 -647
  49. package/src/bin-cresc.ts +0 -8
  50. package/src/bin.ts +0 -115
  51. package/src/bundle-pack.ts +0 -61
  52. package/src/bundle-runner.ts +0 -1430
  53. package/src/bundle.ts +0 -371
  54. package/src/cache.ts +0 -20
  55. package/src/diff.ts +0 -1010
  56. package/src/exports.ts +0 -17
  57. package/src/index.ts +0 -1
  58. package/src/install.ts +0 -50
  59. package/src/locales/en.ts +0 -257
  60. package/src/locales/zh.ts +0 -234
  61. package/src/native-package.ts +0 -338
  62. package/src/package.ts +0 -482
  63. package/src/provider.ts +0 -294
  64. package/src/symbolicate.ts +0 -164
  65. package/src/types.ts +0 -150
  66. package/src/user.ts +0 -39
  67. package/src/utils/add-gitignore.ts +0 -35
  68. package/src/utils/app-info-parser/aab.ts +0 -241
  69. package/src/utils/app-info-parser/apk.ts +0 -92
  70. package/src/utils/app-info-parser/app.ts +0 -7
  71. package/src/utils/app-info-parser/index.ts +0 -54
  72. package/src/utils/app-info-parser/ipa.ts +0 -109
  73. package/src/utils/app-info-parser/resource-finder.ts +0 -508
  74. package/src/utils/app-info-parser/utils.ts +0 -161
  75. package/src/utils/app-info-parser/xml-parser/binary.ts +0 -693
  76. package/src/utils/app-info-parser/xml-parser/manifest.ts +0 -228
  77. package/src/utils/app-info-parser/zip.ts +0 -108
  78. package/src/utils/check-lockfile.ts +0 -93
  79. package/src/utils/check-plugin.ts +0 -38
  80. package/src/utils/command-result.ts +0 -24
  81. package/src/utils/constants.ts +0 -25
  82. package/src/utils/dep-versions.ts +0 -83
  83. package/src/utils/git.ts +0 -71
  84. package/src/utils/hbcTransform.ts +0 -649
  85. package/src/utils/hermes-base.ts +0 -1137
  86. package/src/utils/http-helper.ts +0 -152
  87. package/src/utils/i18n.ts +0 -39
  88. package/src/utils/index.ts +0 -698
  89. package/src/utils/latest-version/index.ts +0 -573
  90. package/src/utils/options.ts +0 -78
  91. package/src/utils/plugin-config.ts +0 -32
  92. package/src/utils/runtime.ts +0 -187
  93. package/src/utils/slim-sourcemap.ts +0 -105
  94. package/src/utils/zip-entries.ts +0 -209
  95. package/src/utils/zip-options.ts +0 -178
  96. package/src/utils/zip-range.ts +0 -727
  97. package/src/utils/zip-raw-writer.ts +0 -247
  98. package/src/versions.ts +0 -892
@@ -1,508 +0,0 @@
1
- /**
2
- * Code translated from a C# project https://github.com/hylander0/Iteedee.ApkReader/blob/master/Iteedee.ApkReader/ApkResourceFinder.cs
3
- *
4
- * Decode binary file `resources.arsc` from a .apk file to a JavaScript Object.
5
- */
6
-
7
- const ByteBuffer = require('bytebuffer');
8
-
9
- const DEBUG = false;
10
-
11
- const RES_STRING_POOL_TYPE = 0x0001;
12
- const RES_TABLE_TYPE = 0x0002;
13
- const RES_TABLE_PACKAGE_TYPE = 0x0200;
14
- const RES_TABLE_TYPE_TYPE = 0x0201;
15
- const RES_TABLE_TYPE_SPEC_TYPE = 0x0202;
16
-
17
- const TYPE_REFERENCE = 0x01;
18
- const TYPE_STRING = 0x03;
19
-
20
- export class ResourceFinder {
21
- private valueStringPool: string[] | null = null;
22
- private typeStringPool: string[] | null = null;
23
- private keyStringPool: string[] | null = null;
24
-
25
- private packageId = 0;
26
-
27
- private responseMap: Record<string, any[]> = {};
28
- private entryMap: Record<number, string[]> = {};
29
-
30
- /**
31
- * Same to C# BinaryReader.readBytes
32
- *
33
- * @param bb ByteBuffer
34
- * @param len length
35
- * @returns {Buffer}
36
- */
37
- static readBytes(bb: any, len: number) {
38
- const uint8Array = new Uint8Array(len);
39
- for (let i = 0; i < len; i++) {
40
- uint8Array[i] = bb.readUint8();
41
- }
42
-
43
- return ByteBuffer.wrap(uint8Array, 'binary', true);
44
- }
45
-
46
- /**
47
- *
48
- * @param {ByteBuffer} bb
49
- * @return {Map<String, Set<String>>}
50
- */
51
- processResourceTable(resourceBuffer: Buffer) {
52
- const bb = ByteBuffer.wrap(resourceBuffer, 'binary', true);
53
-
54
- const type = bb.readShort();
55
- const headerSize = bb.readShort();
56
- const size = bb.readInt();
57
- const packageCount = bb.readInt();
58
- let buffer: any;
59
- let bb2: any;
60
-
61
- if (type !== RES_TABLE_TYPE) {
62
- throw new Error('No RES_TABLE_TYPE found!');
63
- }
64
- if (size !== bb.limit) {
65
- throw new Error(
66
- 'The buffer size not matches to the resource table size.',
67
- );
68
- }
69
- bb.offset = headerSize;
70
-
71
- let realStringPoolCount = 0;
72
- let realPackageCount = 0;
73
-
74
- while (true) {
75
- let pos = 0;
76
- let t = 0;
77
- let _hs = 0;
78
- let s = 0;
79
- try {
80
- pos = bb.offset;
81
- t = bb.readShort();
82
- _hs = bb.readShort();
83
- s = bb.readInt();
84
- } catch (_e) {
85
- break;
86
- }
87
- if (t === RES_STRING_POOL_TYPE) {
88
- if (realStringPoolCount === 0) {
89
- if (DEBUG) {
90
- console.log('Processing the string pool ...');
91
- }
92
-
93
- buffer = new ByteBuffer(s);
94
- bb.offset = pos;
95
- bb.prependTo(buffer);
96
-
97
- bb2 = ByteBuffer.wrap(buffer, 'binary', true);
98
-
99
- bb2.LE();
100
- this.valueStringPool = this.processStringPool(bb2);
101
- }
102
- realStringPoolCount++;
103
- } else if (t === RES_TABLE_PACKAGE_TYPE) {
104
- if (DEBUG) {
105
- console.log(`Processing the package ${realPackageCount} ...`);
106
- }
107
-
108
- buffer = new ByteBuffer(s);
109
- bb.offset = pos;
110
- bb.prependTo(buffer);
111
-
112
- bb2 = ByteBuffer.wrap(buffer, 'binary', true);
113
- bb2.LE();
114
- this.processPackage(bb2);
115
-
116
- realPackageCount++;
117
- } else {
118
- throw new Error('Unsupported type');
119
- }
120
- bb.offset = pos + s;
121
- if (!bb.remaining()) break;
122
- }
123
-
124
- if (realStringPoolCount !== 1) {
125
- throw new Error('More than 1 string pool found!');
126
- }
127
- if (realPackageCount !== packageCount) {
128
- throw new Error('Real package count not equals the declared count.');
129
- }
130
-
131
- return this.responseMap;
132
- }
133
-
134
- /**
135
- *
136
- * @param {ByteBuffer} bb
137
- */
138
- private processPackage(bb: any) {
139
- const type = bb.readShort();
140
- const headerSize = bb.readShort();
141
- const size = bb.readInt();
142
- const id = bb.readInt();
143
-
144
- void type;
145
- void size;
146
-
147
- this.packageId = id;
148
-
149
- for (let i = 0; i < 256; ++i) {
150
- bb.readUint8();
151
- }
152
-
153
- const typeStrings = bb.readInt();
154
- const lastPublicType = bb.readInt();
155
- const keyStrings = bb.readInt();
156
- const lastPublicKey = bb.readInt();
157
-
158
- void lastPublicType;
159
- void lastPublicKey;
160
-
161
- if (typeStrings !== headerSize) {
162
- throw new Error(
163
- 'TypeStrings must immediately following the package structure header.',
164
- );
165
- }
166
-
167
- if (DEBUG) {
168
- console.log('Type strings:');
169
- }
170
-
171
- let lastPosition = bb.offset;
172
- bb.offset = typeStrings;
173
- const bbTypeStrings = ResourceFinder.readBytes(bb, bb.limit - bb.offset);
174
- bb.offset = lastPosition;
175
- this.typeStringPool = this.processStringPool(bbTypeStrings);
176
-
177
- if (DEBUG) {
178
- console.log('Key strings:');
179
- }
180
-
181
- bb.offset = keyStrings;
182
- const keyType = bb.readShort();
183
- const keyHeaderSize = bb.readShort();
184
- const keySize = bb.readInt();
185
-
186
- void keyType;
187
- void keyHeaderSize;
188
-
189
- lastPosition = bb.offset;
190
- bb.offset = keyStrings;
191
- const bbKeyStrings = ResourceFinder.readBytes(bb, bb.limit - bb.offset);
192
- bb.offset = lastPosition;
193
- this.keyStringPool = this.processStringPool(bbKeyStrings);
194
-
195
- let typeSpecCount = 0;
196
- let typeCount = 0;
197
-
198
- bb.offset = keyStrings + keySize;
199
-
200
- let bb2: any;
201
-
202
- while (true) {
203
- const pos = bb.offset;
204
- try {
205
- const t = bb.readShort();
206
- const hs = bb.readShort();
207
- const s = bb.readInt();
208
-
209
- void hs;
210
-
211
- if (t === RES_TABLE_TYPE_SPEC_TYPE) {
212
- bb.offset = pos;
213
- bb2 = ResourceFinder.readBytes(bb, s);
214
- this.processTypeSpec(bb2);
215
-
216
- typeSpecCount++;
217
- } else if (t === RES_TABLE_TYPE_TYPE) {
218
- bb.offset = pos;
219
- bb2 = ResourceFinder.readBytes(bb, s);
220
- this.processType(bb2);
221
-
222
- typeCount++;
223
- }
224
-
225
- if (s === 0) {
226
- break;
227
- }
228
-
229
- bb.offset = pos + s;
230
-
231
- if (!bb.remaining()) {
232
- break;
233
- }
234
- } catch (_e) {
235
- break;
236
- }
237
- }
238
-
239
- void typeSpecCount;
240
- void typeCount;
241
- }
242
-
243
- /**
244
- *
245
- * @param {ByteBuffer} bb
246
- */
247
- private processType(bb: any) {
248
- const type = bb.readShort();
249
- const headerSize = bb.readShort();
250
- const size = bb.readInt();
251
- const id = bb.readByte();
252
- const res0 = bb.readByte();
253
- const res1 = bb.readShort();
254
- const entryCount = bb.readInt();
255
- const entriesStart = bb.readInt();
256
-
257
- void type;
258
- void size;
259
- void res0;
260
- void res1;
261
-
262
- const refKeys: Record<string, number> = {};
263
-
264
- const configSize = bb.readInt();
265
-
266
- void configSize;
267
-
268
- bb.offset = headerSize;
269
-
270
- if (headerSize + entryCount * 4 !== entriesStart) {
271
- throw new Error('HeaderSize, entryCount and entriesStart are not valid.');
272
- }
273
-
274
- const entryIndices = new Array<number>(entryCount);
275
- for (let i = 0; i < entryCount; ++i) {
276
- entryIndices[i] = bb.readInt();
277
- }
278
-
279
- for (let i = 0; i < entryCount; ++i) {
280
- if (entryIndices[i] === -1) continue;
281
-
282
- const resourceId = (this.packageId << 24) | (id << 16) | i;
283
-
284
- let entrySize = 0;
285
- let entryFlag = 0;
286
- let entryKey = 0;
287
- try {
288
- entrySize = bb.readShort();
289
- entryFlag = bb.readShort();
290
- entryKey = bb.readInt();
291
- } catch (_e) {
292
- break;
293
- }
294
-
295
- void entrySize;
296
-
297
- const FLAG_COMPLEX = 0x0001;
298
- if ((entryFlag & FLAG_COMPLEX) === 0) {
299
- const valueSize = bb.readShort();
300
- const valueRes0 = bb.readByte();
301
- const valueDataType = bb.readByte();
302
- const valueData = bb.readInt();
303
-
304
- void valueSize;
305
- void valueRes0;
306
-
307
- const idStr = Number(resourceId).toString(16);
308
- const keyStr = this.keyStringPool ? this.keyStringPool[entryKey] : '';
309
-
310
- let data: string | null = null;
311
-
312
- if (DEBUG) {
313
- console.log(`Entry 0x${idStr}, key: ${keyStr}, simple value type: `);
314
- }
315
-
316
- const key = Number.parseInt(idStr, 16);
317
-
318
- const entryArr = this.entryMap[key] ?? [];
319
- entryArr.push(keyStr);
320
- this.entryMap[key] = entryArr;
321
-
322
- if (valueDataType === TYPE_STRING) {
323
- data = this.valueStringPool ? this.valueStringPool[valueData] : null;
324
-
325
- if (DEBUG && this.valueStringPool) {
326
- console.log(`, data: ${this.valueStringPool[valueData]}`);
327
- }
328
- } else if (valueDataType === TYPE_REFERENCE) {
329
- refKeys[idStr] = valueData;
330
- } else {
331
- data = `${valueData}`;
332
- if (DEBUG) {
333
- console.log(`, data: ${valueData}`);
334
- }
335
- }
336
-
337
- this.putIntoMap(`@${idStr}`, data);
338
- } else {
339
- const entryParent = bb.readInt();
340
- const entryCountValue = bb.readInt();
341
-
342
- void entryParent;
343
-
344
- for (let j = 0; j < entryCountValue; ++j) {
345
- const refName = bb.readInt();
346
- const valueSize = bb.readShort();
347
- const valueRes0 = bb.readByte();
348
- const valueDataType = bb.readByte();
349
- const valueData = bb.readInt();
350
-
351
- void refName;
352
- void valueSize;
353
- void valueRes0;
354
- void valueDataType;
355
- void valueData;
356
- }
357
-
358
- if (DEBUG) {
359
- const keyStr = this.keyStringPool ? this.keyStringPool[entryKey] : '';
360
- console.log(
361
- `Entry 0x${Number(resourceId).toString(16)}, key: ${keyStr}, complex value, not printed.`,
362
- );
363
- }
364
- }
365
- }
366
-
367
- for (const refKey in refKeys) {
368
- const values =
369
- this.responseMap[
370
- `@${Number(refKeys[refKey]).toString(16).toUpperCase()}`
371
- ];
372
- if (values != null && Object.keys(values).length < 1000) {
373
- for (const value of values) {
374
- this.putIntoMap(`@${refKey}`, value);
375
- }
376
- }
377
- }
378
- }
379
-
380
- /**
381
- *
382
- * @param {ByteBuffer} bb
383
- * @return {Array}
384
- */
385
- private processStringPool(bb: any) {
386
- const type = bb.readShort();
387
- const headerSize = bb.readShort();
388
- const size = bb.readInt();
389
- const stringCount = bb.readInt();
390
- const styleCount = bb.readInt();
391
- const flags = bb.readInt();
392
- const stringsStart = bb.readInt();
393
- const stylesStart = bb.readInt();
394
-
395
- void type;
396
- void headerSize;
397
- void size;
398
- void styleCount;
399
- void stylesStart;
400
-
401
- const isUtf8 = (flags & 256) !== 0;
402
-
403
- const offsets = new Array<number>(stringCount);
404
- for (let i = 0; i < stringCount; ++i) {
405
- offsets[i] = bb.readInt();
406
- }
407
-
408
- const strings = new Array<string>(stringCount);
409
-
410
- for (let i = 0; i < stringCount; ++i) {
411
- const pos = stringsStart + offsets[i];
412
- bb.offset = pos;
413
-
414
- strings[i] = '';
415
-
416
- if (isUtf8) {
417
- let u16len = bb.readUint8();
418
-
419
- if ((u16len & 0x80) !== 0) {
420
- u16len = ((u16len & 0x7f) << 8) + bb.readUint8();
421
- }
422
-
423
- let u8len = bb.readUint8();
424
- if ((u8len & 0x80) !== 0) {
425
- u8len = ((u8len & 0x7f) << 8) + bb.readUint8();
426
- }
427
-
428
- if (u8len > 0) {
429
- const buffer = ResourceFinder.readBytes(bb, u8len);
430
- try {
431
- strings[i] = ByteBuffer.wrap(buffer, 'utf8', true).toString('utf8');
432
- } catch (e) {
433
- if (DEBUG) {
434
- console.error(e);
435
- console.log('Error when turning buffer to utf-8 string.');
436
- }
437
- }
438
- } else {
439
- strings[i] = '';
440
- }
441
- } else {
442
- let u16len = bb.readUint16();
443
- if ((u16len & 0x8000) !== 0) {
444
- u16len = ((u16len & 0x7fff) << 16) + bb.readUint16();
445
- }
446
-
447
- if (u16len > 0) {
448
- const len = u16len * 2;
449
- const buffer = ResourceFinder.readBytes(bb, len);
450
- try {
451
- strings[i] = ByteBuffer.wrap(buffer, 'utf8', true).toString('utf8');
452
- } catch (e) {
453
- if (DEBUG) {
454
- console.error(e);
455
- console.log('Error when turning buffer to utf-8 string.');
456
- }
457
- }
458
- }
459
- }
460
-
461
- if (DEBUG) {
462
- console.log('Parsed value: {0}', strings[i]);
463
- }
464
- }
465
-
466
- return strings;
467
- }
468
-
469
- /**
470
- *
471
- * @param {ByteBuffer} bb
472
- */
473
- private processTypeSpec(bb: any) {
474
- const type = bb.readShort();
475
- const headerSize = bb.readShort();
476
- const size = bb.readInt();
477
- const id = bb.readByte();
478
- const res0 = bb.readByte();
479
- const res1 = bb.readShort();
480
- const entryCount = bb.readInt();
481
-
482
- void type;
483
- void headerSize;
484
- void size;
485
- void res0;
486
- void res1;
487
-
488
- if (DEBUG && this.typeStringPool) {
489
- console.log(`Processing type spec ${this.typeStringPool[id - 1]}...`);
490
- }
491
-
492
- const flags = new Array<number>(entryCount);
493
-
494
- for (let i = 0; i < entryCount; ++i) {
495
- flags[i] = bb.readInt();
496
- }
497
- }
498
-
499
- private putIntoMap(resId: string, value: any) {
500
- const key = resId.toUpperCase();
501
- if (this.responseMap[key] == null) {
502
- this.responseMap[key] = [];
503
- }
504
- if (value) {
505
- this.responseMap[key].push(value);
506
- }
507
- }
508
- }
@@ -1,161 +0,0 @@
1
- const objectType = (value: unknown): string =>
2
- Object.prototype.toString.call(value).slice(8, -1).toLowerCase();
3
-
4
- const isArray = (value: unknown): value is unknown[] =>
5
- objectType(value) === 'array';
6
-
7
- const isObject = (value: unknown): value is Record<string, unknown> =>
8
- objectType(value) === 'object';
9
-
10
- const isPrimitive = (value: unknown): boolean =>
11
- value === null ||
12
- ['boolean', 'number', 'string', 'undefined'].includes(objectType(value));
13
-
14
- const isBrowser = (): boolean =>
15
- typeof window !== 'undefined' && typeof window.document !== 'undefined';
16
-
17
- /**
18
- * map file place with resourceMap
19
- * @param {Object} apkInfo // json info parsed from .apk file
20
- * @param {Object} resourceMap // resourceMap
21
- */
22
- const mapInfoResource = (
23
- apkInfo: Record<string, any>,
24
- resourceMap: Record<string, any>,
25
- ) => {
26
- const iteratorObj = (obj: Record<string, any>) => {
27
- for (const i in obj) {
28
- if (isArray(obj[i])) {
29
- iteratorArray(obj[i] as any[]);
30
- } else if (isObject(obj[i])) {
31
- iteratorObj(obj[i] as Record<string, any>);
32
- } else if (isPrimitive(obj[i])) {
33
- if (isResources(obj[i])) {
34
- obj[i] = resourceMap[transKeyToMatchResourceMap(obj[i])];
35
- }
36
- }
37
- }
38
- };
39
-
40
- const iteratorArray = (array: any[]) => {
41
- const l = array.length;
42
- for (let i = 0; i < l; i++) {
43
- if (isArray(array[i])) {
44
- iteratorArray(array[i] as any[]);
45
- } else if (isObject(array[i])) {
46
- iteratorObj(array[i] as Record<string, any>);
47
- } else if (isPrimitive(array[i])) {
48
- if (isResources(array[i])) {
49
- array[i] = resourceMap[transKeyToMatchResourceMap(array[i])];
50
- }
51
- }
52
- }
53
- };
54
-
55
- const isResources = (attrValue: unknown) => {
56
- if (!attrValue) return false;
57
- const value =
58
- typeof attrValue === 'string' ? attrValue : attrValue.toString();
59
- return value.indexOf('resourceId:') === 0;
60
- };
61
-
62
- const transKeyToMatchResourceMap = (resourceId: string) =>
63
- `@${resourceId.replace('resourceId:0x', '').toUpperCase()}`;
64
-
65
- iteratorObj(apkInfo);
66
- return apkInfo;
67
- };
68
-
69
- /**
70
- * find .apk file's icon path from json info
71
- * @param info // json info parsed from .apk file
72
- */
73
- const findApkIconPath = (info: any) => {
74
- if (!info.application.icon?.splice) {
75
- return '';
76
- }
77
- const rulesMap: Record<string, number> = {
78
- mdpi: 48,
79
- hdpi: 72,
80
- xhdpi: 96,
81
- xxdpi: 144,
82
- xxxhdpi: 192,
83
- };
84
- const resultMap: Record<string, string> = {};
85
- const maxDpiIcon = { dpi: 120, icon: '' };
86
-
87
- for (const i in rulesMap) {
88
- info.application.icon.some((icon: string) => {
89
- if (icon && icon.indexOf(i) !== -1) {
90
- resultMap[`application-icon-${rulesMap[i]}`] = icon;
91
- return true;
92
- }
93
- return false;
94
- });
95
-
96
- if (
97
- resultMap[`application-icon-${rulesMap[i]}`] &&
98
- rulesMap[i] >= maxDpiIcon.dpi
99
- ) {
100
- maxDpiIcon.dpi = rulesMap[i];
101
- maxDpiIcon.icon = resultMap[`application-icon-${rulesMap[i]}`];
102
- }
103
- }
104
-
105
- if (Object.keys(resultMap).length === 0 || !maxDpiIcon.icon) {
106
- maxDpiIcon.dpi = 120;
107
- maxDpiIcon.icon = info.application.icon[0] || '';
108
- resultMap['applicataion-icon-120'] = maxDpiIcon.icon;
109
- }
110
- return maxDpiIcon.icon;
111
- };
112
-
113
- /**
114
- * find .ipa file's icon path from json info
115
- * @param info // json info parsed from .ipa file
116
- */
117
- const findIpaIconPath = (info: any) => {
118
- if (info.CFBundleIcons?.CFBundlePrimaryIcon?.CFBundleIconFiles?.length) {
119
- return info.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles[
120
- info.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles.length - 1
121
- ];
122
- }
123
- if (info.CFBundleIconFiles?.length) {
124
- return info.CFBundleIconFiles[info.CFBundleIconFiles.length - 1];
125
- }
126
- return '.app/Icon.png';
127
- };
128
-
129
- /**
130
- * transform buffer to base64
131
- * @param {Buffer} buffer
132
- */
133
- const getBase64FromBuffer = (buffer: Buffer | string) => {
134
- const base64 =
135
- typeof buffer === 'string' ? buffer : buffer.toString('base64');
136
- return `data:image/png;base64,${base64}`;
137
- };
138
-
139
- /**
140
- * 去除unicode空字符
141
- * @param {String} str
142
- */
143
- const decodeNullUnicode = (value: string | RegExp) => {
144
- if (typeof value === 'string') {
145
- // biome-ignore lint/suspicious/noControlCharactersInRegex: strips null unicode padding from decoded strings
146
- return value.replace(/\u0000/g, '');
147
- }
148
- return value;
149
- };
150
-
151
- export {
152
- decodeNullUnicode,
153
- findApkIconPath,
154
- findIpaIconPath,
155
- getBase64FromBuffer,
156
- isArray,
157
- isBrowser,
158
- isObject,
159
- isPrimitive,
160
- mapInfoResource,
161
- };