react-native-update-cli 1.20.0 → 1.20.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.
- package/lib/utils/app-info-parser/apk.js +86 -0
- package/lib/utils/app-info-parser/index.js +37 -0
- package/lib/utils/app-info-parser/ipa.js +96 -0
- package/lib/utils/app-info-parser/resource-finder.js +486 -0
- package/lib/utils/app-info-parser/utils.js +158 -0
- package/lib/utils/app-info-parser/xml-parser/binary.js +671 -0
- package/lib/utils/app-info-parser/xml-parser/manifest.js +224 -0
- package/lib/utils/app-info-parser/zip.js +50 -0
- package/lib/utils/index.js +1 -1
- package/package.json +1 -7
- package/src/.DS_Store +0 -0
- package/src/utils/.DS_Store +0 -0
- package/src/utils/app-info-parser/apk.js +90 -0
- package/src/utils/app-info-parser/index.js +35 -0
- package/src/utils/app-info-parser/ipa.js +92 -0
- package/src/utils/app-info-parser/resource-finder.js +499 -0
- package/src/utils/app-info-parser/utils.js +167 -0
- package/src/utils/app-info-parser/xml-parser/binary.js +674 -0
- package/src/utils/app-info-parser/xml-parser/manifest.js +216 -0
- package/src/utils/app-info-parser/zip.js +48 -0
- package/src/utils/index.js +1 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function objectType(o) {
|
|
4
|
+
return Object.prototype.toString.call(o).slice(8, -1).toLowerCase();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function isArray(o) {
|
|
8
|
+
return objectType(o) === 'array';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function isObject(o) {
|
|
12
|
+
return objectType(o) === 'object';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isPrimitive(o) {
|
|
16
|
+
return o === null || ['boolean', 'number', 'string', 'undefined'].includes(objectType(o));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isBrowser() {
|
|
20
|
+
return typeof process === 'undefined' || Object.prototype.toString.call(process) !== '[object process]';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* map file place with resourceMap
|
|
25
|
+
* @param {Object} apkInfo // json info parsed from .apk file
|
|
26
|
+
* @param {Object} resourceMap // resourceMap
|
|
27
|
+
*/
|
|
28
|
+
function mapInfoResource(apkInfo, resourceMap) {
|
|
29
|
+
iteratorObj(apkInfo);
|
|
30
|
+
return apkInfo;
|
|
31
|
+
function iteratorObj(obj) {
|
|
32
|
+
for (var i in obj) {
|
|
33
|
+
if (isArray(obj[i])) {
|
|
34
|
+
iteratorArray(obj[i]);
|
|
35
|
+
} else if (isObject(obj[i])) {
|
|
36
|
+
iteratorObj(obj[i]);
|
|
37
|
+
} else if (isPrimitive(obj[i])) {
|
|
38
|
+
if (isResources(obj[i])) {
|
|
39
|
+
obj[i] = resourceMap[transKeyToMatchResourceMap(obj[i])];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function iteratorArray(array) {
|
|
46
|
+
const l = array.length;
|
|
47
|
+
for (let i = 0; i < l; i++) {
|
|
48
|
+
if (isArray(array[i])) {
|
|
49
|
+
iteratorArray(array[i]);
|
|
50
|
+
} else if (isObject(array[i])) {
|
|
51
|
+
iteratorObj(array[i]);
|
|
52
|
+
} else if (isPrimitive(array[i])) {
|
|
53
|
+
if (isResources(array[i])) {
|
|
54
|
+
array[i] = resourceMap[transKeyToMatchResourceMap(array[i])];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isResources(attrValue) {
|
|
61
|
+
if (!attrValue) return false;
|
|
62
|
+
if (typeof attrValue !== 'string') {
|
|
63
|
+
attrValue = attrValue.toString();
|
|
64
|
+
}
|
|
65
|
+
return attrValue.indexOf('resourceId:') === 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function transKeyToMatchResourceMap(resourceId) {
|
|
69
|
+
return '@' + resourceId.replace('resourceId:0x', '').toUpperCase();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* find .apk file's icon path from json info
|
|
75
|
+
* @param info // json info parsed from .apk file
|
|
76
|
+
*/
|
|
77
|
+
function findApkIconPath(info) {
|
|
78
|
+
if (!info.application.icon || !info.application.icon.splice) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
const rulesMap = {
|
|
82
|
+
mdpi: 48,
|
|
83
|
+
hdpi: 72,
|
|
84
|
+
xhdpi: 96,
|
|
85
|
+
xxdpi: 144,
|
|
86
|
+
xxxhdpi: 192
|
|
87
|
+
};
|
|
88
|
+
const resultMap = {};
|
|
89
|
+
const maxDpiIcon = { dpi: 120, icon: '' };
|
|
90
|
+
|
|
91
|
+
for (const i in rulesMap) {
|
|
92
|
+
info.application.icon.some(icon => {
|
|
93
|
+
if (icon && icon.indexOf(i) !== -1) {
|
|
94
|
+
resultMap['application-icon-' + rulesMap[i]] = icon;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// get the maximal size icon
|
|
100
|
+
if (resultMap['application-icon-' + rulesMap[i]] && rulesMap[i] >= maxDpiIcon.dpi) {
|
|
101
|
+
maxDpiIcon.dpi = rulesMap[i];
|
|
102
|
+
maxDpiIcon.icon = resultMap['application-icon-' + rulesMap[i]];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (Object.keys(resultMap).length === 0 || !maxDpiIcon.icon) {
|
|
107
|
+
maxDpiIcon.dpi = 120;
|
|
108
|
+
maxDpiIcon.icon = info.application.icon[0] || '';
|
|
109
|
+
resultMap['applicataion-icon-120'] = maxDpiIcon.icon;
|
|
110
|
+
}
|
|
111
|
+
return maxDpiIcon.icon;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* find .ipa file's icon path from json info
|
|
116
|
+
* @param info // json info parsed from .ipa file
|
|
117
|
+
*/
|
|
118
|
+
function findIpaIconPath(info) {
|
|
119
|
+
if (info.CFBundleIcons && info.CFBundleIcons.CFBundlePrimaryIcon && info.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles && info.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles.length) {
|
|
120
|
+
return info.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles[info.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles.length - 1];
|
|
121
|
+
} else if (info.CFBundleIconFiles && info.CFBundleIconFiles.length) {
|
|
122
|
+
return info.CFBundleIconFiles[info.CFBundleIconFiles.length - 1];
|
|
123
|
+
} else {
|
|
124
|
+
return '.app/Icon.png';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* transform buffer to base64
|
|
130
|
+
* @param {Buffer} buffer
|
|
131
|
+
*/
|
|
132
|
+
function getBase64FromBuffer(buffer) {
|
|
133
|
+
return 'data:image/png;base64,' + buffer.toString('base64');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 去除unicode空字符
|
|
138
|
+
* @param {String} str
|
|
139
|
+
*/
|
|
140
|
+
function decodeNullUnicode(str) {
|
|
141
|
+
if (typeof str === 'string') {
|
|
142
|
+
// eslint-disable-next-line
|
|
143
|
+
str = str.replace(/\u0000/g, '');
|
|
144
|
+
}
|
|
145
|
+
return str;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = {
|
|
149
|
+
isArray,
|
|
150
|
+
isObject,
|
|
151
|
+
isPrimitive,
|
|
152
|
+
isBrowser,
|
|
153
|
+
mapInfoResource,
|
|
154
|
+
findApkIconPath,
|
|
155
|
+
findIpaIconPath,
|
|
156
|
+
getBase64FromBuffer,
|
|
157
|
+
decodeNullUnicode
|
|
158
|
+
};
|