react-native-update-cli 2.4.2 → 2.6.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 (49) hide show
  1. package/README.md +2 -0
  2. package/README.zh-CN.md +2 -0
  3. package/cli.json +40 -0
  4. package/lib/api.js +1 -1
  5. package/lib/locales/en.js +16 -1
  6. package/lib/locales/zh.js +16 -1
  7. package/lib/package.js +60 -6
  8. package/lib/provider.js +3 -0
  9. package/lib/utils/app-info-parser/aab.js +230 -0
  10. package/lib/utils/app-info-parser/apk.js +25 -27
  11. package/lib/utils/app-info-parser/app.js +10 -11
  12. package/lib/utils/app-info-parser/index.js +13 -8
  13. package/lib/utils/app-info-parser/ipa.js +16 -21
  14. package/lib/utils/app-info-parser/resource-finder.js +365 -305
  15. package/lib/utils/app-info-parser/utils.js +78 -63
  16. package/lib/utils/app-info-parser/xml-parser/binary.js +57 -51
  17. package/lib/utils/app-info-parser/xml-parser/manifest.js +47 -39
  18. package/lib/utils/app-info-parser/zip.js +21 -11
  19. package/lib/utils/http-helper.js +1 -1
  20. package/lib/utils/index.js +137 -0
  21. package/lib/versions.js +22 -0
  22. package/package.json +3 -2
  23. package/proto/Configuration.proto +183 -0
  24. package/proto/Resources.proto +569 -0
  25. package/src/api.ts +2 -6
  26. package/src/locales/en.ts +20 -0
  27. package/src/locales/zh.ts +18 -0
  28. package/src/modules/version-module.ts +1 -1
  29. package/src/package.ts +112 -12
  30. package/src/provider.ts +3 -0
  31. package/src/utils/app-info-parser/aab.ts +240 -0
  32. package/src/utils/app-info-parser/{apk.js → apk.ts} +30 -41
  33. package/src/utils/app-info-parser/app.ts +3 -0
  34. package/src/utils/app-info-parser/index.ts +9 -5
  35. package/src/utils/app-info-parser/{ipa.js → ipa.ts} +17 -31
  36. package/src/utils/app-info-parser/resource-finder.ts +508 -0
  37. package/src/utils/app-info-parser/utils.ts +162 -0
  38. package/src/utils/app-info-parser/xml-parser/{binary.js → binary.ts} +69 -61
  39. package/src/utils/app-info-parser/xml-parser/{manifest.js → manifest.ts} +50 -51
  40. package/src/utils/app-info-parser/zip.ts +86 -0
  41. package/src/utils/dep-versions.ts +7 -4
  42. package/src/utils/http-helper.ts +1 -1
  43. package/src/utils/index.ts +154 -0
  44. package/src/utils/latest-version/index.ts +2 -1
  45. package/src/versions.ts +27 -2
  46. package/src/utils/app-info-parser/app.js +0 -16
  47. package/src/utils/app-info-parser/resource-finder.js +0 -495
  48. package/src/utils/app-info-parser/utils.js +0 -172
  49. package/src/utils/app-info-parser/zip.js +0 -66
@@ -1,16 +1,25 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "Zip", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Zip;
9
+ }
10
+ });
11
+ const _utils = require("./utils");
2
12
  const Unzip = require('isomorphic-unzip');
3
- const { isBrowser, decodeNullUnicode } = require('./utils');
4
- const { enumZipEntries, readEntry } = require('../../bundle');
13
+ let bundleZipUtils;
5
14
  class Zip {
6
15
  /**
7
16
  * get entries by regexps, the return format is: { <filename>: <Buffer|Blob> }
8
17
  * @param {Array} regexps // regexps for matching files
9
18
  * @param {String} type // return type, can be buffer or blob, default buffer
10
19
  */ getEntries(regexps, type = 'buffer') {
11
- regexps = regexps.map((regex)=>decodeNullUnicode(regex));
20
+ const decoded = regexps.map((regex)=>(0, _utils.decodeNullUnicode)(regex));
12
21
  return new Promise((resolve, reject)=>{
13
- this.unzip.getBuffer(regexps, {
22
+ this.unzip.getBuffer(decoded, {
14
23
  type
15
24
  }, (err, buffers)=>{
16
25
  err ? reject(err) : resolve(buffers);
@@ -22,24 +31,26 @@ class Zip {
22
31
  * @param {Regex} regex // regex for matching file
23
32
  * @param {String} type // return type, can be buffer or blob, default buffer
24
33
  */ getEntry(regex, type = 'buffer') {
25
- regex = decodeNullUnicode(regex);
34
+ const decoded = (0, _utils.decodeNullUnicode)(regex);
26
35
  return new Promise((resolve, reject)=>{
27
36
  this.unzip.getBuffer([
28
- regex
37
+ decoded
29
38
  ], {
30
39
  type
31
40
  }, (err, buffers)=>{
32
- // console.log(buffers);
33
- err ? reject(err) : resolve(buffers[regex]);
41
+ err ? reject(err) : resolve(buffers[decoded]);
34
42
  });
35
43
  });
36
44
  }
37
45
  async getEntryFromHarmonyApp(regex) {
38
46
  try {
47
+ const { enumZipEntries, readEntry } = bundleZipUtils != null ? bundleZipUtils : bundleZipUtils = require('../../bundle');
39
48
  let originSource;
40
49
  await enumZipEntries(this.file, (entry, zipFile)=>{
41
50
  if (regex.test(entry.fileName)) {
42
- return readEntry(entry, zipFile).then((v)=>originSource = v);
51
+ return readEntry(entry, zipFile).then((value)=>{
52
+ originSource = value;
53
+ });
43
54
  }
44
55
  });
45
56
  return originSource;
@@ -48,7 +59,7 @@ class Zip {
48
59
  }
49
60
  }
50
61
  constructor(file){
51
- if (isBrowser()) {
62
+ if ((0, _utils.isBrowser)()) {
52
63
  if (!(file instanceof window.Blob || typeof file.size !== 'undefined')) {
53
64
  throw new Error('Param error: [file] must be an instance of Blob or File in browser.');
54
65
  }
@@ -62,4 +73,3 @@ class Zip {
62
73
  this.unzip = new Unzip(this.file);
63
74
  }
64
75
  }
65
- module.exports = Zip;
@@ -22,8 +22,8 @@ _export(exports, {
22
22
  return testUrls;
23
23
  }
24
24
  });
25
- const _constants = require("./constants");
26
25
  const _nodefetch = /*#__PURE__*/ _interop_require_default(require("node-fetch"));
26
+ const _constants = require("./constants");
27
27
  function _interop_require_default(obj) {
28
28
  return obj && obj.__esModule ? obj : {
29
29
  default: obj
@@ -12,6 +12,9 @@ _export(exports, {
12
12
  checkPlugins: function() {
13
13
  return _checkplugin.checkPlugins;
14
14
  },
15
+ getAabInfo: function() {
16
+ return getAabInfo;
17
+ },
15
18
  getApkInfo: function() {
16
19
  return getApkInfo;
17
20
  },
@@ -169,6 +172,140 @@ async function getIpaInfo(fn) {
169
172
  ...appCredential
170
173
  };
171
174
  }
175
+ async function getAabInfo(fn) {
176
+ const protobuf = require('protobufjs');
177
+ const root = await protobuf.load(_path.default.join(__dirname, '../../proto/Resources.proto'));
178
+ const XmlNode = root.lookupType('aapt.pb.XmlNode');
179
+ const buffer = await readZipEntry(fn, 'base/manifest/AndroidManifest.xml');
180
+ const message = XmlNode.decode(buffer);
181
+ const object = XmlNode.toObject(message, {
182
+ enums: String,
183
+ longs: String,
184
+ bytes: String,
185
+ defaults: true,
186
+ arrays: true
187
+ });
188
+ const manifestElement = object.element;
189
+ if (manifestElement.name !== 'manifest') {
190
+ throw new Error('Invalid manifest');
191
+ }
192
+ let versionName = '';
193
+ for (const attr of manifestElement.attribute){
194
+ if (attr.name === 'versionName') {
195
+ versionName = attr.value;
196
+ }
197
+ }
198
+ let buildTime = 0;
199
+ const appCredential = {};
200
+ // Find application node
201
+ const applicationNode = manifestElement.child.find((c)=>c.element && c.element.name === 'application');
202
+ if (applicationNode) {
203
+ const metaDataNodes = applicationNode.element.child.filter((c)=>c.element && c.element.name === 'meta-data');
204
+ for (const meta of metaDataNodes){
205
+ let name = '';
206
+ let value = '';
207
+ let resourceId = 0;
208
+ for (const attr of meta.element.attribute){
209
+ if (attr.name === 'name') {
210
+ name = attr.value;
211
+ }
212
+ if (attr.name === 'value') {
213
+ var _attr_compiledItem_ref, _attr_compiledItem, _attr_compiledItem_prim, _attr_compiledItem1;
214
+ value = attr.value;
215
+ if ((_attr_compiledItem = attr.compiledItem) == null ? void 0 : (_attr_compiledItem_ref = _attr_compiledItem.ref) == null ? void 0 : _attr_compiledItem_ref.id) {
216
+ resourceId = attr.compiledItem.ref.id;
217
+ } else if ((_attr_compiledItem1 = attr.compiledItem) == null ? void 0 : (_attr_compiledItem_prim = _attr_compiledItem1.prim) == null ? void 0 : _attr_compiledItem_prim.intDecimalValue) {
218
+ value = attr.compiledItem.prim.intDecimalValue.toString();
219
+ }
220
+ }
221
+ }
222
+ if (name === 'pushy_build_time') {
223
+ if (resourceId > 0) {
224
+ const resolvedValue = await resolveResource(fn, resourceId, root);
225
+ if (resolvedValue) {
226
+ value = resolvedValue;
227
+ }
228
+ }
229
+ buildTime = Number(value);
230
+ }
231
+ }
232
+ }
233
+ if (buildTime === 0) {
234
+ throw new Error((0, _i18n.t)('buildTimeNotFound'));
235
+ }
236
+ return {
237
+ versionName,
238
+ buildTime,
239
+ ...appCredential
240
+ };
241
+ }
242
+ async function readZipEntry(fn, entryName) {
243
+ const yauzl = require('yauzl');
244
+ return new Promise((resolve, reject)=>{
245
+ yauzl.open(fn, {
246
+ lazyEntries: true
247
+ }, (err, zipfile)=>{
248
+ if (err) return reject(err);
249
+ let found = false;
250
+ zipfile.readEntry();
251
+ zipfile.on('entry', (entry)=>{
252
+ if (entry.fileName === entryName) {
253
+ found = true;
254
+ zipfile.openReadStream(entry, (err, readStream)=>{
255
+ if (err) return reject(err);
256
+ const chunks = [];
257
+ readStream.on('data', (chunk)=>chunks.push(chunk));
258
+ readStream.on('end', ()=>resolve(Buffer.concat(chunks)));
259
+ readStream.on('error', reject);
260
+ });
261
+ } else {
262
+ zipfile.readEntry();
263
+ }
264
+ });
265
+ zipfile.on('end', ()=>{
266
+ if (!found) reject(new Error(`${entryName} not found in AAB`));
267
+ });
268
+ zipfile.on('error', reject);
269
+ });
270
+ });
271
+ }
272
+ async function resolveResource(fn, resourceId, root) {
273
+ const pkgId = resourceId >> 24 & 0xff;
274
+ const typeId = resourceId >> 16 & 0xff;
275
+ const entryId = resourceId & 0xffff;
276
+ try {
277
+ const buffer = await readZipEntry(fn, 'base/resources.pb');
278
+ const ResourceTable = root.lookupType('aapt.pb.ResourceTable');
279
+ const message = ResourceTable.decode(buffer);
280
+ const object = ResourceTable.toObject(message, {
281
+ enums: String,
282
+ longs: String,
283
+ bytes: String,
284
+ defaults: true,
285
+ arrays: true
286
+ });
287
+ // Find package
288
+ const pkg = object.package.find((p)=>p.packageId === pkgId);
289
+ if (!pkg) return null;
290
+ // Find type
291
+ const type = pkg.type.find((t)=>t.typeId === typeId);
292
+ if (!type) return null;
293
+ // Find entry
294
+ const entry = type.entry.find((e)=>e.entryId === entryId);
295
+ if (!entry) return null;
296
+ // Get value from configValue
297
+ if (entry.configValue && entry.configValue.length > 0) {
298
+ var _val_item;
299
+ const val = entry.configValue[0].value;
300
+ if ((_val_item = val.item) == null ? void 0 : _val_item.str) {
301
+ return val.item.str.value;
302
+ }
303
+ }
304
+ } catch (e) {
305
+ console.warn('Failed to resolve resource:', e);
306
+ }
307
+ return null;
308
+ }
172
309
  const localDir = _path.default.resolve(_os.default.homedir(), _constants.tempDir);
173
310
  _fsextra.default.ensureDirSync(localDir);
174
311
  function saveToLocal(originPath, destName) {
package/lib/versions.js CHANGED
@@ -287,5 +287,27 @@ const versionCommands = {
287
287
  if (options.metaInfo) updateParams.metaInfo = options.metaInfo;
288
288
  await (0, _api.put)(`/app/${appId}/version/${versionId}`, updateParams);
289
289
  console.log((0, _i18n.t)('operationSuccess'));
290
+ },
291
+ deleteVersion: async ({ options })=>{
292
+ let appId = options.appId;
293
+ if (!appId) {
294
+ const platform = await (0, _app.getPlatform)(options.platform);
295
+ appId = (await (0, _app.getSelectedApp)(platform)).appId;
296
+ }
297
+ let versionId = options.versionId;
298
+ if (!versionId) {
299
+ versionId = (await chooseVersion(appId)).id;
300
+ }
301
+ try {
302
+ await (0, _api.doDelete)(`/app/${appId}/version/${versionId}`);
303
+ console.log((0, _i18n.t)('deleteVersionSuccess', {
304
+ versionId
305
+ }));
306
+ } catch (error) {
307
+ throw new Error((0, _i18n.t)('deleteVersionError', {
308
+ versionId,
309
+ error: error.message
310
+ }));
311
+ }
290
312
  }
291
313
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.4.2",
3
+ "version": "2.6.0",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "pushy": "lib/index.js",
8
8
  "cresc": "lib/index.js"
9
9
  },
10
- "files": ["lib", "src", "cli.json"],
10
+ "files": ["lib", "src", "proto", "cli.json"],
11
11
  "scripts": {
12
12
  "build": "swc src -d lib --strip-leading-paths",
13
13
  "prepublishOnly": "npm run build && chmod +x lib/index.js",
@@ -45,6 +45,7 @@
45
45
  "plist": "^3.1.0",
46
46
  "progress": "^2.0.3",
47
47
  "properties": "^1.2.1",
48
+ "protobufjs": "^7.5.4",
48
49
  "read": "^4.1.0",
49
50
  "registry-auth-token": "^5.1.0",
50
51
  "semver": "^7.7.2",
@@ -0,0 +1,183 @@
1
+ syntax = "proto3";
2
+
3
+ package aapt.pb;
4
+
5
+ option java_package = "com.android.aapt";
6
+
7
+ message Configuration {
8
+ enum LayoutDirection {
9
+ LAYOUT_DIRECTION_UNSET = 0;
10
+ LAYOUT_DIRECTION_LTR = 1;
11
+ LAYOUT_DIRECTION_RTL = 2;
12
+ }
13
+
14
+ enum ScreenLayoutSize {
15
+ SCREEN_LAYOUT_SIZE_UNSET = 0;
16
+ SCREEN_LAYOUT_SIZE_SMALL = 1;
17
+ SCREEN_LAYOUT_SIZE_NORMAL = 2;
18
+ SCREEN_LAYOUT_SIZE_LARGE = 3;
19
+ SCREEN_LAYOUT_SIZE_XLARGE = 4;
20
+ }
21
+
22
+ enum ScreenLayoutLong {
23
+ SCREEN_LAYOUT_LONG_UNSET = 0;
24
+ SCREEN_LAYOUT_LONG_LONG = 1;
25
+ SCREEN_LAYOUT_LONG_NOTLONG = 2;
26
+ }
27
+
28
+ enum ScreenRound {
29
+ SCREEN_ROUND_UNSET = 0;
30
+ SCREEN_ROUND_ROUND = 1;
31
+ SCREEN_ROUND_NOTROUND = 2;
32
+ }
33
+
34
+ enum WideColorGamut {
35
+ WIDE_COLOR_GAMUT_UNSET = 0;
36
+ WIDE_COLOR_GAMUT_WIDECG = 1;
37
+ WIDE_COLOR_GAMUT_NOWIDECG = 2;
38
+ }
39
+
40
+ enum Hdr {
41
+ HDR_UNSET = 0;
42
+ HDR_HIGHDR = 1;
43
+ HDR_LOWDR = 2;
44
+ }
45
+
46
+ enum Orientation {
47
+ ORIENTATION_UNSET = 0;
48
+ ORIENTATION_PORT = 1;
49
+ ORIENTATION_LAND = 2;
50
+ ORIENTATION_SQUARE = 3;
51
+ }
52
+
53
+ enum UiModeType {
54
+ UI_MODE_TYPE_UNSET = 0;
55
+ UI_MODE_TYPE_NORMAL = 1;
56
+ UI_MODE_TYPE_DESK = 2;
57
+ UI_MODE_TYPE_CAR = 3;
58
+ UI_MODE_TYPE_TELEVISION = 4;
59
+ UI_MODE_TYPE_APPLIANCE = 5;
60
+ UI_MODE_TYPE_WATCH = 6;
61
+ UI_MODE_TYPE_VR_HEADSET = 7;
62
+ }
63
+
64
+ enum UiModeNight {
65
+ UI_MODE_NIGHT_UNSET = 0;
66
+ UI_MODE_NIGHT_NIGHT = 1;
67
+ UI_MODE_NIGHT_NOTNIGHT = 2;
68
+ }
69
+
70
+ enum Touchscreen {
71
+ TOUCHSCREEN_UNSET = 0;
72
+ TOUCHSCREEN_NOTOUCH = 1;
73
+ TOUCHSCREEN_STYLUS = 2;
74
+ TOUCHSCREEN_FINGER = 3;
75
+ }
76
+
77
+ enum KeysHidden {
78
+ KEYS_HIDDEN_UNSET = 0;
79
+ KEYS_HIDDEN_KEYSEXPOSED = 1;
80
+ KEYS_HIDDEN_KEYSHIDDEN = 2;
81
+ KEYS_HIDDEN_KEYSSOFT = 3;
82
+ }
83
+
84
+ enum Keyboard {
85
+ KEYBOARD_UNSET = 0;
86
+ KEYBOARD_NOKEYS = 1;
87
+ KEYBOARD_QWERTY = 2;
88
+ KEYBOARD_12KEY = 3;
89
+ }
90
+
91
+ enum NavHidden {
92
+ NAV_HIDDEN_UNSET = 0;
93
+ NAV_HIDDEN_NAVEXPOSED = 1;
94
+ NAV_HIDDEN_NAVHIDDEN = 2;
95
+ }
96
+
97
+ enum Navigation {
98
+ NAVIGATION_UNSET = 0;
99
+ NAVIGATION_NONAV = 1;
100
+ NAVIGATION_DPAD = 2;
101
+ NAVIGATION_TRACKBALL = 3;
102
+ NAVIGATION_WHEEL = 4;
103
+ }
104
+
105
+ enum GrammaticalGender {
106
+ GRAMMATICAL_GENDER_UNSET = 0;
107
+ GRAMMATICAL_GENDER_NEUTER = 1;
108
+ GRAMMATICAL_GENDER_FEMININE = 2;
109
+ GRAMMATICAL_GENDER_MASCULINE = 3;
110
+ }
111
+
112
+ // Mobile country code.
113
+ uint32 mcc = 1;
114
+
115
+ // Mobile network code.
116
+ uint32 mnc = 2;
117
+
118
+ // Locale.
119
+ string locale = 3;
120
+
121
+ // Layout direction.
122
+ LayoutDirection layout_direction = 4;
123
+
124
+ // Screen width in dp.
125
+ uint32 screen_width = 5;
126
+
127
+ // Screen height in dp.
128
+ uint32 screen_height = 6;
129
+
130
+ // Smallest screen width in dp.
131
+ uint32 smallest_screen_width = 7;
132
+
133
+ // Screen layout size.
134
+ ScreenLayoutSize screen_layout_size = 8;
135
+
136
+ // Screen layout long.
137
+ ScreenLayoutLong screen_layout_long = 9;
138
+
139
+ // Screen round.
140
+ ScreenRound screen_round = 10;
141
+
142
+ // Wide color gamut.
143
+ WideColorGamut wide_color_gamut = 11;
144
+
145
+ // HDR.
146
+ Hdr hdr = 12;
147
+
148
+ // Orientation.
149
+ Orientation orientation = 13;
150
+
151
+ // UI mode type.
152
+ UiModeType ui_mode_type = 14;
153
+
154
+ // UI mode night.
155
+ UiModeNight ui_mode_night = 15;
156
+
157
+ // Density in dpi.
158
+ uint32 density = 16;
159
+
160
+ // Touchscreen.
161
+ Touchscreen touchscreen = 17;
162
+
163
+ // Keys hidden.
164
+ KeysHidden keys_hidden = 18;
165
+
166
+ // Keyboard.
167
+ Keyboard keyboard = 19;
168
+
169
+ // Nav hidden.
170
+ NavHidden nav_hidden = 20;
171
+
172
+ // Navigation.
173
+ Navigation navigation = 21;
174
+
175
+ // SDK version.
176
+ uint32 sdk_version = 22;
177
+
178
+ // Product.
179
+ string product = 23;
180
+
181
+ // Grammatical gender.
182
+ GrammaticalGender grammatical_gender = 24;
183
+ }