react-native-update-cli 1.30.3 → 1.31.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.
package/lib/app.js CHANGED
@@ -1,128 +1,150 @@
1
- 'use strict';
2
-
1
+ "use strict";
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.commands = undefined;
7
- exports.checkPlatform = checkPlatform;
8
- exports.getSelectedApp = getSelectedApp;
9
- exports.listApp = listApp;
10
- exports.chooseApp = chooseApp;
11
-
12
- var _utils = require('./utils');
13
-
14
- var _fs = require('fs');
15
-
16
- var _fs2 = _interopRequireDefault(_fs);
17
-
18
- var _ttyTable = require('tty-table');
19
-
20
- var _ttyTable2 = _interopRequireDefault(_ttyTable);
21
-
22
- var _api = require('./api');
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ checkPlatform: function() {
13
+ return checkPlatform;
14
+ },
15
+ chooseApp: function() {
16
+ return chooseApp;
17
+ },
18
+ commands: function() {
19
+ return commands;
20
+ },
21
+ getSelectedApp: function() {
22
+ return getSelectedApp;
23
+ },
24
+ listApp: function() {
25
+ return listApp;
26
+ }
27
+ });
28
+ const _utils = require("./utils");
29
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
30
+ const _ttytable = /*#__PURE__*/ _interop_require_default(require("tty-table"));
31
+ const _api = require("./api");
32
+ function _interop_require_default(obj) {
33
+ return obj && obj.__esModule ? obj : {
34
+ default: obj
35
+ };
36
+ }
26
37
  const validPlatforms = {
27
- ios: 1,
28
- android: 1
38
+ ios: 1,
39
+ android: 1
29
40
  };
30
-
31
41
  function checkPlatform(platform) {
32
- if (!validPlatforms[platform]) {
33
- throw new Error(`无法识别的平台 '${platform}'`);
34
- }
35
- return platform;
42
+ if (!validPlatforms[platform]) {
43
+ throw new Error(`无法识别的平台 '${platform}'`);
44
+ }
45
+ return platform;
36
46
  }
37
-
38
47
  function getSelectedApp(platform) {
39
- checkPlatform(platform);
40
-
41
- if (!_fs2.default.existsSync('update.json')) {
42
- throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
43
- }
44
- const updateInfo = JSON.parse(_fs2.default.readFileSync('update.json', 'utf8'));
45
- if (!updateInfo[platform]) {
46
- throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
47
- }
48
- return updateInfo[platform];
48
+ checkPlatform(platform);
49
+ if (!_fs.default.existsSync('update.json')) {
50
+ throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
51
+ }
52
+ const updateInfo = JSON.parse(_fs.default.readFileSync('update.json', 'utf8'));
53
+ if (!updateInfo[platform]) {
54
+ throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
55
+ }
56
+ return updateInfo[platform];
49
57
  }
50
-
51
58
  async function listApp(platform) {
52
- const { data } = await (0, _api.get)('/app/list');
53
- const list = platform ? data.filter(v => v.platform === platform) : data;
54
-
55
- const header = [{ value: '应用 id' }, { value: '应用名称' }, { value: '平台' }];
56
- const rows = [];
57
- for (const app of list) {
58
- rows.push([app.id, app.name, app.platform]);
59
- }
60
-
61
- console.log((0, _ttyTable2.default)(header, rows).render());
62
-
63
- if (platform) {
64
- console.log(`\共 ${list.length} ${platform} 个应用`);
65
- } else {
66
- console.log(`\共 ${list.length} 个应用`);
67
- }
68
- return list;
59
+ const { data } = await (0, _api.get)('/app/list');
60
+ const list = platform ? data.filter((v)=>v.platform === platform) : data;
61
+ const header = [
62
+ {
63
+ value: '应用 id'
64
+ },
65
+ {
66
+ value: '应用名称'
67
+ },
68
+ {
69
+ value: '平台'
70
+ }
71
+ ];
72
+ const rows = [];
73
+ for (const app of list){
74
+ rows.push([
75
+ app.id,
76
+ app.name,
77
+ app.platform
78
+ ]);
79
+ }
80
+ console.log((0, _ttytable.default)(header, rows).render());
81
+ if (platform) {
82
+ console.log(`\共 ${list.length} ${platform} 个应用`);
83
+ } else {
84
+ console.log(`\共 ${list.length} 个应用`);
85
+ }
86
+ return list;
69
87
  }
70
-
71
88
  async function chooseApp(platform) {
72
- const list = await listApp(platform);
73
-
74
- while (true) {
75
- const id = await (0, _utils.question)('输入应用 id:');
76
- const app = list.find(v => v.id === (id | 0));
77
- if (app) {
78
- return app;
89
+ const list = await listApp(platform);
90
+ while(true){
91
+ const id = await (0, _utils.question)('输入应用 id:');
92
+ const app = list.find((v)=>v.id === (id | 0));
93
+ if (app) {
94
+ return app;
95
+ }
79
96
  }
80
- }
81
97
  }
82
-
83
- const commands = exports.commands = {
84
- createApp: async function ({ options }) {
85
- const name = options.name || (await (0, _utils.question)('应用名称:'));
86
- const { downloadUrl } = options;
87
- const platform = checkPlatform(options.platform || (await (0, _utils.question)('平台(ios/android):')));
88
- const { id } = await (0, _api.post)('/app/create', { name, platform });
89
- console.log(`已成功创建应用(id: ${id})`);
90
- await this.selectApp({
91
- args: [id],
92
- options: { platform, downloadUrl }
93
- });
94
- },
95
- deleteApp: async function ({ args, options }) {
96
- const { platform } = options;
97
- const id = args[0] || chooseApp(platform);
98
- if (!id) {
99
- console.log('已取消');
98
+ const commands = {
99
+ createApp: async function({ options }) {
100
+ const name = options.name || await (0, _utils.question)('应用名称:');
101
+ const { downloadUrl } = options;
102
+ const platform = checkPlatform(options.platform || await (0, _utils.question)('平台(ios/android):'));
103
+ const { id } = await (0, _api.post)('/app/create', {
104
+ name,
105
+ platform
106
+ });
107
+ console.log(`已成功创建应用(id: ${id})`);
108
+ await this.selectApp({
109
+ args: [
110
+ id
111
+ ],
112
+ options: {
113
+ platform,
114
+ downloadUrl
115
+ }
116
+ });
117
+ },
118
+ deleteApp: async function({ args, options }) {
119
+ const { platform } = options;
120
+ const id = args[0] || chooseApp(platform);
121
+ if (!id) {
122
+ console.log('已取消');
123
+ }
124
+ await (0, _api.doDelete)(`/app/${id}`);
125
+ console.log('操作成功');
126
+ },
127
+ apps: async function({ options }) {
128
+ const { platform } = options;
129
+ listApp(platform);
130
+ },
131
+ selectApp: async function({ args, options }) {
132
+ const platform = checkPlatform(options.platform || await (0, _utils.question)('平台(ios/android):'));
133
+ const id = args[0] ? parseInt(args[0]) : (await chooseApp(platform)).id;
134
+ let updateInfo = {};
135
+ if (_fs.default.existsSync('update.json')) {
136
+ try {
137
+ updateInfo = JSON.parse(_fs.default.readFileSync('update.json', 'utf8'));
138
+ } catch (e) {
139
+ console.error('Failed to parse file `update.json`. Try to remove it manually.');
140
+ throw e;
141
+ }
142
+ }
143
+ const { appKey } = await (0, _api.get)(`/app/${id}`);
144
+ updateInfo[platform] = {
145
+ appId: id,
146
+ appKey
147
+ };
148
+ _fs.default.writeFileSync('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
100
149
  }
101
- await (0, _api.doDelete)(`/app/${id}`);
102
- console.log('操作成功');
103
- },
104
- apps: async function ({ options }) {
105
- const { platform } = options;
106
- listApp(platform);
107
- },
108
- selectApp: async function ({ args, options }) {
109
- const platform = checkPlatform(options.platform || (await (0, _utils.question)('平台(ios/android):')));
110
- const id = args[0] ? parseInt(args[0]) : (await chooseApp(platform)).id;
111
-
112
- let updateInfo = {};
113
- if (_fs2.default.existsSync('update.json')) {
114
- try {
115
- updateInfo = JSON.parse(_fs2.default.readFileSync('update.json', 'utf8'));
116
- } catch (e) {
117
- console.error('Failed to parse file `update.json`. Try to remove it manually.');
118
- throw e;
119
- }
120
- }
121
- const { appKey } = await (0, _api.get)(`/app/${id}`);
122
- updateInfo[platform] = {
123
- appId: id,
124
- appKey
125
- };
126
- _fs2.default.writeFileSync('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
127
- }
128
- };
150
+ };