@zeppos/zeus-cli 1.1.2 → 1.1.5

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/README.md CHANGED
@@ -15,4 +15,4 @@ The Zeus CLI can help you install the development application to your device, wh
15
15
 
16
16
  ### Help
17
17
 
18
- For more help, please visit [Zepp Open Platform](https://dev.huami.com/) or [ZeppOS Docs](https://docs.zepp.com/)
18
+ For more help, please visit [Zepp Developer](https://developer.zepp.com/) or [Zepp OS Docs](https://docs.zepp.com/)
package/api/index.js CHANGED
@@ -173,7 +173,9 @@ var uploadPackage = function (form, length) { return __awaiter(void 0, void 0, v
173
173
  case 1:
174
174
  _c.trys.push([1, 3, , 4]);
175
175
  return [4, axios_1["default"].post("https://".concat(_subRegionalHost, "/custom/tools/app-dial/upload?userid=").concat(_loginUserId), form, {
176
- headers: __assign(__assign({}, form.getHeaders()), { 'content-length': "".concat(length), apptoken: _loginAppToken })
176
+ headers: __assign(__assign({}, form.getHeaders()), { 'content-length': "".concat(length), apptoken: _loginAppToken }),
177
+ maxContentLength: Infinity,
178
+ maxBodyLength: Infinity
177
179
  })];
178
180
  case 2:
179
181
  packageInfo = _c.sent();
package/config/device.js CHANGED
@@ -7,6 +7,7 @@ var DeviceTarget;
7
7
  DeviceTarget["MADRID"] = "madrid";
8
8
  DeviceTarget["VERONA"] = "verona";
9
9
  DeviceTarget["ZURICH"] = "zurich";
10
+ DeviceTarget["TEIDE"] = "teide";
10
11
  })(DeviceTarget = exports.DeviceTarget || (exports.DeviceTarget = {}));
11
12
  var DevicePlatformName;
12
13
  (function (DevicePlatformName) {
@@ -16,6 +17,8 @@ var DevicePlatformName;
16
17
  DevicePlatformName["VERONAW"] = "gtr3-w";
17
18
  DevicePlatformName["ZURICH"] = "gts3";
18
19
  DevicePlatformName["ZURICHW"] = "gts3-w";
20
+ DevicePlatformName["TEIDE"] = "t-rex2";
21
+ DevicePlatformName["TEIDEW"] = "t-rex2-w";
19
22
  })(DevicePlatformName = exports.DevicePlatformName || (exports.DevicePlatformName = {}));
20
23
  var DeviceSource;
21
24
  (function (DeviceSource) {
@@ -25,6 +28,8 @@ var DeviceSource;
25
28
  DeviceSource[DeviceSource["VERONAW"] = 227] = "VERONAW";
26
29
  DeviceSource[DeviceSource["ZURICH"] = 224] = "ZURICH";
27
30
  DeviceSource[DeviceSource["ZURICHW"] = 225] = "ZURICHW";
31
+ DeviceSource[DeviceSource["TEIDE"] = 418] = "TEIDE";
32
+ DeviceSource[DeviceSource["TEIDEW"] = 419] = "TEIDEW";
28
33
  })(DeviceSource = exports.DeviceSource || (exports.DeviceSource = {}));
29
34
  var DeviceScreenType;
30
35
  (function (DeviceScreenType) {
@@ -86,6 +91,24 @@ exports.deviceTargets = (_a = {},
86
91
  height: 450
87
92
  }
88
93
  },
94
+ _a[DeviceTarget.TEIDE] = {
95
+ deviceName: 'T-Rex2',
96
+ platforms: [
97
+ {
98
+ name: DevicePlatformName.TEIDE,
99
+ deviceSource: DeviceSource.TEIDE
100
+ },
101
+ {
102
+ name: DevicePlatformName.TEIDEW,
103
+ deviceSource: DeviceSource.TEIDEW
104
+ }
105
+ ],
106
+ screen: {
107
+ type: DeviceScreenType.R,
108
+ width: 454,
109
+ height: 454
110
+ }
111
+ },
89
112
  _a);
90
113
  exports.deviceInternalCodeName = (_b = {},
91
114
  _b[DeviceSource.MADRID] = DeviceTarget.MADRID,
@@ -94,4 +117,6 @@ exports.deviceInternalCodeName = (_b = {},
94
117
  _b[DeviceSource.VERONAW] = DeviceTarget.VERONA,
95
118
  _b[DeviceSource.ZURICH] = DeviceTarget.ZURICH,
96
119
  _b[DeviceSource.ZURICHW] = DeviceTarget.ZURICH,
120
+ _b[DeviceSource.TEIDE] = DeviceTarget.TEIDE,
121
+ _b[DeviceSource.TEIDEW] = DeviceTarget.TEIDE,
97
122
  _b);
package/modules/bridge.js CHANGED
@@ -105,14 +105,14 @@ var connectDevice = function (vorpal) { return __awaiter(void 0, void 0, void 0,
105
105
  _a.label = 3;
106
106
  case 3:
107
107
  project_1.____inner_global_variable.bridgeChoiredDevice = choiredDevice;
108
- client.sendMessage({ clientId: clientId_1 }, 'connectClient');
108
+ client.sendMessage({ clientId: clientId_1 }, { method: 'connectClient' });
109
109
  hasConnectDevice = true;
110
110
  _a.label = 4;
111
111
  case 4: return [2];
112
112
  }
113
113
  });
114
114
  }); };
115
- var connectBridgeWSCallback = function () {
115
+ var connectWSCB = function () {
116
116
  var vorpal = require('vorpal')();
117
117
  vorpal.find('help').hidden();
118
118
  vorpal.find('exit').remove();
@@ -146,7 +146,7 @@ var connectBridgeWSCallback = function () {
146
146
  case 0:
147
147
  if (!hasConnectDevice) return [3, 2];
148
148
  return [4, (0, build_1.buildPreview)({ _: ['install', "".concat(choiredDevice.toLowerCase())], '$0': 'zeus' }, function (params) {
149
- client.sendMessage(params, 'packagePush');
149
+ client.sendMessage(params, { method: 'packagePush' });
150
150
  })];
151
151
  case 1:
152
152
  _a.sent();
@@ -170,14 +170,14 @@ var connectBridgeWSCallback = function () {
170
170
  vorpal.log("".concat(chalk_1["default"].red('error'), " If the [appid] is blank, this command needs to be executed in the root of the project."));
171
171
  }
172
172
  else {
173
- vorpal.log(chalk_1["default"].blue('Uninstalling'));
173
+ vorpal.log(chalk_1["default"].blue('Uninstalling...'));
174
174
  _a = (0, common_1.getDeviceInfoFromAppJson)(), appid = _a.appId, appName = _a.appName, appType = _a.appType;
175
- client.sendMessage({ type: 'delete', appid: appid, appName: appName, appType: appType }, 'sysSettingPush');
175
+ client.sendMessage({ type: 'delete', appid: appid, appName: appName, appType: appType }, { method: 'sysSettingPush' });
176
176
  }
177
177
  }
178
178
  else if (args.appid && typeof args.appid === 'number') {
179
- vorpal.log(chalk_1["default"].blue('Uninstalling'));
180
- client.sendMessage({ type: 'delete', appid: args.appid }, 'sysSettingPush');
179
+ vorpal.log(chalk_1["default"].blue('Uninstalling...'));
180
+ client.sendMessage({ type: 'delete', appid: args.appid }, { method: 'sysSettingPush' });
181
181
  }
182
182
  else if (args.appid) {
183
183
  vorpal.log("".concat(chalk_1["default"].red('error'), " invalid '").concat(args.appid, "', the 'uninstall' command should be followed by appid or blank."));
@@ -186,8 +186,28 @@ var connectBridgeWSCallback = function () {
186
186
  return [2];
187
187
  });
188
188
  }); });
189
+ vorpal
190
+ .command('screenshot', 'Screenshot of the current watch device.').hidden()
191
+ .action(function (args, cb) { return __awaiter(void 0, void 0, void 0, function () {
192
+ return __generator(this, function (_a) {
193
+ if (hasConnectDevice) {
194
+ if (choiredDevice.indexOf('app') > -1) {
195
+ vorpal.log(chalk_1["default"].blue('Waiting...'));
196
+ client.sendMessage({ type: 'screenshot' }, { method: 'sysSettingPush' });
197
+ }
198
+ else {
199
+ vorpal.log(chalk_1["default"].yellow("Only the connected device is an app that can use the screenshot command."));
200
+ }
201
+ }
202
+ else {
203
+ vorpal.log(chalk_1["default"].yellow("No device is connected, please connect the device with the command width 'connect' first."));
204
+ }
205
+ cb();
206
+ return [2];
207
+ });
208
+ }); });
189
209
  };
190
- var disConnectBridgeWSCallback = function () {
210
+ var disConnectWSCB = function () {
191
211
  hasConnectDevice = false;
192
212
  logger.log('Disconnected');
193
213
  process.exit(1);
@@ -203,8 +223,8 @@ var bridge = function (args) { return __awaiter(void 0, void 0, void 0, function
203
223
  bridgeWebSocketURL = _a.sent();
204
224
  client = new websocket_1["default"]({
205
225
  url: "".concat(bridgeWebSocketURL, "?type=development&name=CLI"),
206
- connectCb: connectBridgeWSCallback,
207
- disconnectCb: disConnectBridgeWSCallback
226
+ connectWSCB: connectWSCB,
227
+ disConnectWSCB: disConnectWSCB
208
228
  });
209
229
  logger.log(" - Enter 'help' to view the command.");
210
230
  return [3, 6];
package/modules/build.js CHANGED
@@ -67,7 +67,7 @@ var node_js_1 = require("@zeppos/zpm/lib/node.js");
67
67
  var fs_1 = __importDefault(require("fs"));
68
68
  var rd = __importStar(require("rd"));
69
69
  var path = __importStar(require("path"));
70
- var lodash_1 = __importDefault(require("lodash"));
70
+ var lodash_1 = require("lodash");
71
71
  var fs_extra_1 = __importDefault(require("fs-extra"));
72
72
  var form_data_1 = __importDefault(require("form-data"));
73
73
  var qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
@@ -97,52 +97,66 @@ function handleExecCommandInErrorDir(mode) {
97
97
  logger.warn("This command needs to be executed in the root of the project.");
98
98
  process.exit(1);
99
99
  }
100
- function chooseBuildPackages(mode) {
100
+ function chooseBuildPackages(mode, buildConfigOption) {
101
101
  if (mode === void 0) { mode = 'development'; }
102
+ if (buildConfigOption === void 0) { buildConfigOption = {}; }
102
103
  return __awaiter(this, void 0, void 0, function () {
103
- var targets, answers;
104
- var _a, _b;
105
- return __generator(this, function (_c) {
106
- switch (_c.label) {
104
+ var targets, _a, promptTarget_1, answers;
105
+ var _b, _c;
106
+ return __generator(this, function (_d) {
107
+ switch (_d.label) {
107
108
  case 0:
108
109
  if (!appJsonContent) {
109
110
  handleExecCommandInErrorDir(mode);
110
111
  }
111
- targets = Object.keys(lodash_1["default"].get(appJsonContent, 'targets', {}));
112
+ targets = Object.keys((0, lodash_1.get)(appJsonContent, 'targets', {}));
112
113
  if (!!targets.length) return [3, 1];
113
114
  logger.error('Please set at least one package.');
114
115
  process.exit(1);
115
116
  return [3, 4];
116
117
  case 1:
117
118
  if (!(targets.length === 1)) return [3, 2];
118
- storage_1.globalStorage.set((_a = {}, _a[project_1.buildStorageKey.targetDeviceToBuild] = targets[0], _a));
119
+ storage_1.globalStorage.set((_b = {}, _b[project_1.buildStorageKey.targetDeviceToBuild] = targets[0], _b));
119
120
  return [2, [targets[0]]];
120
- case 2: return [4, inquirer_1["default"].prompt([
121
- {
122
- name: 'target',
123
- type: 'list',
124
- when: function () { return mode !== BuildMode.PROD; },
125
- message: 'Which target would you like to preview?',
126
- choices: targets
127
- },
128
- {
129
- name: 'buildTargets',
130
- type: 'checkbox',
131
- when: function () { return mode === BuildMode.PROD; },
132
- choices: targets.map(function (item) { return ({
133
- name: item,
134
- value: item,
135
- checked: true
136
- }); }),
137
- message: 'Which targets would you like to build?'
138
- }
139
- ])];
121
+ case 2:
122
+ _a = buildConfigOption.target, promptTarget_1 = _a === void 0 ? '' : _a;
123
+ return [4, inquirer_1["default"].prompt([
124
+ {
125
+ name: 'target',
126
+ type: 'list',
127
+ when: function (args) {
128
+ var bool = targets.includes(promptTarget_1);
129
+ if (bool) {
130
+ args.target = promptTarget_1;
131
+ }
132
+ return mode !== BuildMode.PROD && !bool;
133
+ },
134
+ message: 'Which target would you like to preview?',
135
+ choices: targets
136
+ },
137
+ {
138
+ name: 'target',
139
+ type: 'checkbox',
140
+ when: function (args) {
141
+ var arr = typeof promptTarget_1 === 'string' ? (0, lodash_1.intersection)(targets, promptTarget_1.split(',')) : [];
142
+ var bool = !!arr.length;
143
+ if (bool) {
144
+ args.target = arr;
145
+ }
146
+ return mode === BuildMode.PROD && !bool;
147
+ },
148
+ choices: targets.map(function (item) { return ({
149
+ name: item,
150
+ value: item,
151
+ checked: true
152
+ }); }),
153
+ message: 'Which targets would you like to build?'
154
+ }
155
+ ])];
140
156
  case 3:
141
- answers = _c.sent();
142
- if (BuildMode.PROD) {
143
- storage_1.globalStorage.set((_b = {}, _b[project_1.buildStorageKey.targetDeviceToBuild] = answers.target, _b));
144
- }
145
- return [2, mode !== BuildMode.PROD ? [answers.target] : answers.buildTargets];
157
+ answers = _d.sent();
158
+ storage_1.globalStorage.set((_c = {}, _c[project_1.buildStorageKey.targetDeviceToBuild] = answers.target, _c));
159
+ return [2, typeof answers.target === 'string' ? [answers.target] : answers.target];
146
160
  case 4: return [2];
147
161
  }
148
162
  });
@@ -159,7 +173,7 @@ var build = function (mode, packages, buildConfigOption) {
159
173
  case 0:
160
174
  workspace = path.resolve('./');
161
175
  if (!!packages.length) return [3, 2];
162
- return [4, chooseBuildPackages(mode)];
176
+ return [4, chooseBuildPackages(mode, buildConfigOption)];
163
177
  case 1:
164
178
  choosePackages = _b.sent();
165
179
  if (!choosePackages || !choosePackages.length) {
@@ -228,9 +242,9 @@ var build = function (mode, packages, buildConfigOption) {
228
242
  });
229
243
  };
230
244
  exports.build = build;
231
- var buildDev = function (packages) {
245
+ var buildDev = function (args, packages) {
232
246
  (0, hm_analytics_1.HM_Analytics)('ZEPP_CLI_DEV_C');
233
- return (0, exports.build)(BuildMode.DEV, packages);
247
+ return (0, exports.build)(BuildMode.DEV, packages, args);
234
248
  };
235
249
  exports.buildDev = buildDev;
236
250
  var buildProd = function (args) { return __awaiter(void 0, void 0, void 0, function () {
@@ -262,7 +276,7 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
262
276
  return [4, (0, exports.build)(buildMode, [], args)];
263
277
  case 1:
264
278
  buildInfo = _b.sent();
265
- appType = lodash_1["default"].get(appJsonContent, 'app.appType');
279
+ appType = (0, lodash_1.get)(appJsonContent, 'app.appType');
266
280
  isWatchFaceProject = appType === project_1.AppType.WATCHFACE;
267
281
  logger.info('getting package...');
268
282
  form = new form_data_1["default"]();
@@ -312,8 +326,9 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
312
326
  url = "".concat(protocol, "://").concat(_subRegionalHost, "/custom/tools/app-dial/download/").concat(code);
313
327
  if (protocol && code) {
314
328
  logger.info('Generating preview qrcode...');
315
- logger.success('Below within two hours,please use Zepp APP to scan the qrcode below to preview your app.');
329
+ logger.success('Please use Zepp APP to scan the following qrcode to preview your application within two hours.');
316
330
  qrcode_terminal_1["default"].generate(url, { small: true });
331
+ storage_1.globalStorage.set({ ____preview_url: url });
317
332
  }
318
333
  else {
319
334
  logger.error('Generating preview qrcode failed, please check your network.');
@@ -328,7 +343,7 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
328
343
  url = packageInfo;
329
344
  preview = '';
330
345
  if (isWatchFaceProject) {
331
- downloadPackageReturn = lodash_1["default"].get(packageInfo, 'data', {});
346
+ downloadPackageReturn = (0, lodash_1.get)(packageInfo, 'data', {});
332
347
  url = downloadPackageReturn.url;
333
348
  preview = downloadPackageReturn.preview;
334
349
  }
@@ -83,7 +83,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
83
83
  };
84
84
  exports.__esModule = true;
85
85
  exports.create = void 0;
86
- var lodash_1 = __importDefault(require("lodash"));
86
+ var lodash_1 = require("lodash");
87
87
  var chalk_1 = __importDefault(require("chalk"));
88
88
  var inquirer_1 = __importDefault(require("inquirer"));
89
89
  var rd = __importStar(require("rd"));
@@ -102,11 +102,11 @@ var sleep_1 = require("../../utils/sleep");
102
102
  var hm_analytics_1 = require("../../utils/hm-analytics");
103
103
  var TEMPLATE_DIR = (0, path_1.resolve)(__dirname, '../../public/template');
104
104
  var create = function (args) { return __awaiter(void 0, void 0, void 0, function () {
105
- var cmd, _a, projectName, cwdPath, beforeFiles, workDir, localTemplates, localChoices, watchfaceTemplateChoices, appTemplateChoices, env, generatorMate, generatorMateKeys, answer, choosePkg;
106
- return __generator(this, function (_b) {
107
- switch (_b.label) {
105
+ var cmd, _a, projectName, _b, promptAppType, _c, promptTemplate, _d, promptWithAppSide, _e, promptWithSettings, _f, promptBuildTargets, cwdPath, beforeFiles, workDir, localTemplates, localChoices, watchfaceTemplateChoices, appTemplateChoices, env, generatorMate, generatorMateKeys, answer, choosePkg;
106
+ return __generator(this, function (_g) {
107
+ switch (_g.label) {
108
108
  case 0:
109
- cmd = args._[0], _a = args.projectName, projectName = _a === void 0 ? '' : _a;
109
+ cmd = args._[0], _a = args.projectName, projectName = _a === void 0 ? '' : _a, _b = args.appType, promptAppType = _b === void 0 ? '' : _b, _c = args.template, promptTemplate = _c === void 0 ? '' : _c, _d = args.withAppSide, promptWithAppSide = _d === void 0 ? false : _d, _e = args.withSettings, promptWithSettings = _e === void 0 ? false : _e, _f = args.buildTargets, promptBuildTargets = _f === void 0 ? [] : _f;
110
110
  cwdPath = (0, path_1.resolve)('./');
111
111
  beforeFiles = [];
112
112
  workDir = cwdPath;
@@ -136,13 +136,13 @@ var create = function (args) { return __awaiter(void 0, void 0, void 0, function
136
136
  localChoices = [];
137
137
  watchfaceTemplateChoices = [];
138
138
  appTemplateChoices = [];
139
- if (!lodash_1["default"].isEmpty(localTemplates)) {
139
+ if (!(0, lodash_1.isEmpty)(localTemplates)) {
140
140
  localTemplates.forEach(function (dirName) {
141
141
  var dirPath = "".concat(TEMPLATE_DIR, "/").concat(dirName);
142
142
  var dirStat = (0, fs_1.lstatSync)(dirPath);
143
143
  if (dirStat.isDirectory()) {
144
144
  var chooseItem = {
145
- name: lodash_1["default"].startCase(dirName),
145
+ name: (0, lodash_1.startCase)(dirName),
146
146
  path: dirPath,
147
147
  type: project_1.AppSourceType.LOCAL
148
148
  };
@@ -207,45 +207,92 @@ var create = function (args) { return __awaiter(void 0, void 0, void 0, function
207
207
  {
208
208
  name: 'appType',
209
209
  type: 'list',
210
+ when: function (args) {
211
+ var bool = !promptAppType || !Object.values(project_1.AppType).includes(promptAppType);
212
+ if (!bool) {
213
+ args.appType = promptAppType.toUpperCase();
214
+ }
215
+ return bool;
216
+ },
210
217
  message: 'What type of application do you want to create?',
211
218
  choices: Object.keys(project_1.AppType)
212
219
  },
213
220
  {
214
221
  name: 'template',
215
222
  type: 'list',
216
- when: function (args) { return args.appType.toLowerCase() === project_1.AppType.APP; },
217
- message: 'Which template do you want to use?',
223
+ when: function (args) {
224
+ var isApp = args.appType.toLowerCase() === project_1.AppType.APP;
225
+ var objMap = appTemplateChoices.find(function (val) {
226
+ var name = val.name === 'Hello World' ? 'Hello_World' : val.name;
227
+ return name === promptTemplate;
228
+ });
229
+ if (isApp && objMap) {
230
+ args.template = objMap.value;
231
+ }
232
+ return isApp && !objMap;
233
+ },
234
+ message: 'Which app template do you want to use?',
218
235
  choices: __spreadArray([
219
236
  new inquirer_1["default"].Separator(),
220
- new inquirer_1["default"].Separator('Choose a template')
237
+ new inquirer_1["default"].Separator('Choose a app template')
221
238
  ], appTemplateChoices, true)
222
239
  },
223
240
  {
224
241
  name: 'template',
225
242
  type: 'list',
226
- when: function (args) { return args.appType.toLowerCase() === project_1.AppType.WATCHFACE; },
227
- message: 'Which template do you want to use?',
243
+ when: function (args) {
244
+ var isWatchFace = args.appType.toLowerCase() === project_1.AppType.WATCHFACE;
245
+ var objMap = watchfaceTemplateChoices.find(function (val) { return val.name === promptTemplate; });
246
+ if (isWatchFace && objMap) {
247
+ args.template = objMap.value;
248
+ }
249
+ return isWatchFace && !objMap;
250
+ },
251
+ message: 'Which watchface template do you want to use?',
228
252
  choices: __spreadArray([
229
253
  new inquirer_1["default"].Separator(),
230
- new inquirer_1["default"].Separator('Choose a template')
254
+ new inquirer_1["default"].Separator('Choose a watchface template')
231
255
  ], watchfaceTemplateChoices, true)
232
256
  },
233
257
  {
234
258
  name: 'withAppSide',
235
259
  type: 'confirm',
236
- when: function (args) { return args.template === 0 && args.appType.toLowerCase() === project_1.AppType.APP; },
260
+ when: function (args) {
261
+ var isApp = args.appType.toLowerCase() === project_1.AppType.APP;
262
+ var isEmpty = args.template === 0;
263
+ if (isApp && isEmpty && promptWithAppSide) {
264
+ args.withAppSide = promptWithAppSide === 'no' ? false : true;
265
+ return false;
266
+ }
267
+ return isApp && isEmpty;
268
+ },
237
269
  message: 'Should this application contain a app-side component?'
238
270
  },
239
271
  {
240
272
  name: 'withSettings',
241
273
  type: 'confirm',
242
- when: function (args) { return args.withAppSide; },
274
+ when: function (args) {
275
+ var withAppSide = args.withAppSide;
276
+ if (withAppSide && promptWithSettings) {
277
+ args.withSettings = promptWithSettings === 'no' ? false : true;
278
+ return false;
279
+ }
280
+ return withAppSide;
281
+ },
243
282
  message: 'Should this application contain a settings component?'
244
283
  },
245
284
  {
246
285
  name: 'buildTargets',
247
286
  type: 'checkbox',
248
- when: function (args) { return args.template === 0; },
287
+ when: function (args) {
288
+ var bool = args.template === 0;
289
+ var tarArr = typeof promptBuildTargets === 'string' ? (0, lodash_1.intersection)(Object.keys(device_1.deviceTargets), promptBuildTargets.split(',')) : [];
290
+ if (bool && tarArr.length) {
291
+ args.buildTargets = tarArr;
292
+ return false;
293
+ }
294
+ return bool;
295
+ },
249
296
  choices: Object.keys(device_1.deviceTargets).map(function (platform) { return ({
250
297
  name: device_1.deviceTargets[platform].deviceName,
251
298
  value: platform,
@@ -256,28 +303,28 @@ var create = function (args) { return __awaiter(void 0, void 0, void 0, function
256
303
  },
257
304
  ])];
258
305
  case 1:
259
- answer = _b.sent();
306
+ answer = _g.sent();
260
307
  answer.appType = answer.appType || project_1.AppType.APP;
261
308
  answer.workDir = workDir;
262
309
  choosePkg = answer.appType.toLowerCase() === project_1.AppType.APP ? appTemplateChoices[answer.template] : watchfaceTemplateChoices[answer.template];
263
310
  logger.info('fetching template...');
264
311
  return [4, (0, sleep_1.sleep)(100)];
265
312
  case 2:
266
- _b.sent();
313
+ _g.sent();
267
314
  if (choosePkg.type === project_1.AppSourceType.YEOMAN) {
268
- logger.info("".concat(lodash_1["default"].upperFirst(cmd), " application using yeoman template \"").concat(choosePkg.name, "\"."));
315
+ logger.info("".concat((0, lodash_1.upperFirst)(cmd), " application using yeoman template \"").concat(choosePkg.name, "\"."));
269
316
  (0, yeoman_app_1.createYeomanApp)(__assign(__assign({}, answer), { env: env, templateInfo: generatorMate[choosePkg.name] }));
270
317
  }
271
318
  else {
272
- logger.info("".concat(lodash_1["default"].upperFirst(cmd), " application using local template \"").concat(choosePkg.name, "\"."));
319
+ logger.info("".concat((0, lodash_1.upperFirst)(cmd), " application using local template \"").concat(choosePkg.name, "\"."));
273
320
  (0, local_app_1.createLocalApp)(__assign(__assign({}, answer), { templateInfo: choosePkg }));
274
321
  }
275
322
  logger.log('\n');
276
323
  return [4, (0, sleep_1.sleep)(50)];
277
324
  case 3:
278
- _b.sent();
325
+ _g.sent();
279
326
  rd.eachFileSync(workDir, function (file) {
280
- if (lodash_1["default"].endsWith(file, '.DS_Store')) {
327
+ if ((0, lodash_1.endsWith)(file, '.DS_Store')) {
281
328
  fs_extra_1["default"].remove(file);
282
329
  }
283
330
  else {
@@ -298,11 +345,11 @@ var create = function (args) { return __awaiter(void 0, void 0, void 0, function
298
345
  shell.exec('npm install');
299
346
  return [4, (0, sleep_1.sleep)(300)];
300
347
  case 4:
301
- _b.sent();
348
+ _g.sent();
302
349
  logger.log(chalk_1["default"].hex('#DB8C41')(font_icon_1["default"]));
303
350
  return [4, (0, sleep_1.sleep)(800)];
304
351
  case 5:
305
- _b.sent();
352
+ _g.sent();
306
353
  logger.log('I\'m all done. Now you can start your application.');
307
354
  return [2];
308
355
  }
package/modules/run.js CHANGED
@@ -79,54 +79,74 @@ var project_1 = require("../config/project");
79
79
  exports.DEFAULT_HOST = '127.0.0.1';
80
80
  exports.DEFAULT_PORT = '7650';
81
81
  var run = function (args) { return __awaiter(void 0, void 0, void 0, function () {
82
- var _a, _b, simulatorHost, _c, _d, simulatorPort, answer, hasStarted, packages, simulatorWebSocketURL, simulator, refreshSimulator, gitignorePath, gitignore, ignored;
83
- var _e;
84
- return __generator(this, function (_f) {
85
- switch (_f.label) {
82
+ var simulatorHost, simulatorPort, _a, promptSimulatorHost, _b, promptSimulatorPort, answer, hasStarted, packages, simulatorWebSocketURL, simulator, refreshSimulator, gitignorePath, gitignore, ignored;
83
+ var _c;
84
+ return __generator(this, function (_d) {
85
+ switch (_d.label) {
86
86
  case 0:
87
- _a = storage_1.instanceStorage.getStorage(), _b = project_1.simulatorStorageKey.simulatorHost, simulatorHost = _a[_b], _c = project_1.simulatorStorageKey.simulatorPort, _d = _a[_c], simulatorPort = _d === void 0 ? exports.DEFAULT_PORT : _d;
88
- if (!!simulatorHost) return [3, 2];
87
+ fs_extra_1["default"].readJSONSync(path.resolve('./app.json'), { throws: false });
88
+ simulatorHost = '';
89
+ simulatorPort = '';
90
+ _a = args.simulatorHost, promptSimulatorHost = _a === void 0 ? '' : _a, _b = args.simulatorPort, promptSimulatorPort = _b === void 0 ? exports.DEFAULT_PORT : _b;
91
+ if (!promptSimulatorHost) {
92
+ simulatorHost = storage_1.instanceStorage.getStorage()[project_1.simulatorStorageKey.simulatorHost];
93
+ simulatorPort = storage_1.instanceStorage.getStorage()[project_1.simulatorStorageKey.simulatorPort] || exports.DEFAULT_PORT;
94
+ }
89
95
  return [4, inquirer_1["default"].prompt([
90
96
  {
91
97
  name: 'host',
92
98
  type: 'input',
99
+ when: function (args) {
100
+ if (promptSimulatorHost) {
101
+ args.host = promptSimulatorHost;
102
+ }
103
+ return !promptSimulatorHost && !simulatorHost;
104
+ },
105
+ "default": exports.DEFAULT_HOST,
93
106
  message: "simulator host (".concat(exports.DEFAULT_HOST, "):")
94
107
  },
95
108
  {
96
109
  name: 'port',
97
110
  type: 'input',
111
+ when: function (args) {
112
+ if (promptSimulatorPort) {
113
+ args.port = promptSimulatorPort;
114
+ }
115
+ return !promptSimulatorPort && !simulatorPort;
116
+ },
117
+ "default": exports.DEFAULT_PORT,
98
118
  message: "simulator port (".concat(exports.DEFAULT_PORT, "):")
99
119
  }
100
120
  ])];
101
121
  case 1:
102
- answer = _f.sent();
103
- storage_1.globalStorage.set((_e = {},
104
- _e[project_1.simulatorStorageKey.simulatorHost] = answer.host || exports.DEFAULT_HOST,
105
- _e[project_1.simulatorStorageKey.simulatorPort] = answer.port || exports.DEFAULT_PORT,
106
- _e));
107
- _f.label = 2;
108
- case 2:
122
+ answer = _d.sent();
123
+ if (!simulatorHost) {
124
+ storage_1.globalStorage.set((_c = {},
125
+ _c[project_1.simulatorStorageKey.simulatorHost] = answer.host || exports.DEFAULT_HOST,
126
+ _c[project_1.simulatorStorageKey.simulatorPort] = answer.port || exports.DEFAULT_PORT,
127
+ _c));
128
+ }
109
129
  hasStarted = false;
110
- return [4, (0, build_1.chooseBuildPackages)()];
111
- case 3:
112
- packages = _f.sent();
130
+ return [4, (0, build_1.chooseBuildPackages)('development', args)];
131
+ case 2:
132
+ packages = _d.sent();
113
133
  simulatorWebSocketURL = "http://".concat(simulatorHost, ":").concat(simulatorPort);
114
134
  simulator = new simulator_1.Simulator(simulatorWebSocketURL);
115
135
  refreshSimulator = lodash_1["default"].debounce(function () { return __awaiter(void 0, void 0, void 0, function () {
116
- var zpkBuffer, _a, targetDeviceInternalName, appId, projectName;
136
+ var zpkBuffer, _a, targetDeviceInternalName, appId, devices, projectName;
117
137
  return __generator(this, function (_b) {
118
138
  switch (_b.label) {
119
139
  case 0:
120
140
  logger.info('rebuilding...');
121
- return [4, (0, build_1.buildDev)(packages)];
141
+ return [4, (0, build_1.buildDev)(args, packages)];
122
142
  case 1:
123
143
  zpkBuffer = _b.sent();
124
144
  if (zpkBuffer) {
125
145
  logger.info('rebuild done');
126
146
  logger.info('refreshing simulator...');
127
- _a = (0, common_1.getDeviceInfoFromAppJson)(packages[0]), targetDeviceInternalName = _a.targetDeviceInternalName, appId = _a.appId;
147
+ _a = (0, common_1.getDeviceInfoFromAppJson)(packages[0]), targetDeviceInternalName = _a.targetDeviceInternalName, appId = _a.appId, devices = _a.deviceSourceArr;
128
148
  projectName = path.parse(process.cwd()).base;
129
- simulator.upload(zpkBuffer, projectName, targetDeviceInternalName, appId);
149
+ simulator.upload(zpkBuffer, projectName, targetDeviceInternalName, appId, devices);
130
150
  }
131
151
  else {
132
152
  logger.error('build error');
@@ -51,14 +51,15 @@ var Simulator = (function () {
51
51
  Simulator.prototype.emit = function (space, jsonData) {
52
52
  this.socket.emit(space, jsonData);
53
53
  };
54
- Simulator.prototype.upload = function (data, projectName, target, appid) {
54
+ Simulator.prototype.upload = function (data, projectName, target, appid, devices) {
55
55
  var dataArr = this.uint8ToArray(new Uint8Array(data));
56
56
  var message = this.encodeMessage({
57
57
  target: target,
58
58
  projectName: projectName,
59
59
  appid: appid,
60
60
  size: data.byteLength,
61
- data: dataArr
61
+ data: dataArr,
62
+ devices: devices
62
63
  });
63
64
  this.sendMessage(message);
64
65
  };
package/modules/status.js CHANGED
@@ -71,39 +71,38 @@ var storage_1 = require("./storage");
71
71
  var project_1 = require("../config/project");
72
72
  var run_1 = require("./run");
73
73
  var hm_analytics_1 = require("../utils/hm-analytics");
74
- var login_1 = require("./login");
75
74
  var status = function (args) { return __awaiter(void 0, void 0, void 0, function () {
76
- var _a, _b, _c, apptoken, _d, _e, userid, _f, _g, cname, _h, _j, simulatorHost, _k, _l, simulatorPort, _m, simulatorConnectStatus, loginStatus, userInfoHost, userInfoURL, nickName, res, error_1, res;
75
+ var _a, _b, _c, apptoken, _d, _e, userid, _f, _g, cname, _h, _j, simulatorHost, _k, _l, simulatorPort, _m, simulatorConnectStatus, loginStatus, userInfoHost, userInfoURL, nickName, res, error_1;
77
76
  return __generator(this, function (_o) {
78
77
  switch (_o.label) {
79
78
  case 0:
80
79
  _a = storage_1.instanceStorage.getStorage(), _b = project_1.loginStorageKey.accountToken, _c = _a[_b], apptoken = _c === void 0 ? '' : _c, _d = project_1.loginStorageKey.userid, _e = _a[_d], userid = _e === void 0 ? '' : _e, _f = project_1.loginStorageKey.cname, _g = _a[_f], cname = _g === void 0 ? '' : _g, _h = project_1.simulatorStorageKey.simulatorHost, _j = _a[_h], simulatorHost = _j === void 0 ? run_1.DEFAULT_HOST : _j, _k = project_1.simulatorStorageKey.simulatorPort, _l = _a[_k], simulatorPort = _l === void 0 ? run_1.DEFAULT_PORT : _l, _m = project_1.simulatorStorageKey.simulatorConnectStatus, simulatorConnectStatus = _a[_m];
81
80
  loginStatus = !!(apptoken && userid && cname);
82
- if (!loginStatus) return [3, 6];
81
+ if (!loginStatus) return [3, 5];
83
82
  userInfoHost = lodash_1["default"].split(lodash_1["default"].toString(cname), ',').filter(function (h) { return h.indexOf('auth-') > -1; })[0];
84
83
  userInfoURL = "https://".concat(userInfoHost, "/v2/developer/account/center");
85
84
  nickName = '';
86
85
  _o.label = 1;
87
86
  case 1:
88
- _o.trys.push([1, 3, , 5]);
87
+ _o.trys.push([1, 3, , 4]);
89
88
  return [4, (0, index_1.getUserInfo)(userInfoURL, apptoken)];
90
89
  case 2:
91
90
  res = _o.sent();
92
91
  nickName = res.userName;
93
- logger.log('login status:', chalk_1["default"].yellow(loginStatus ? 'logged' : 'no login'));
94
- return [3, 5];
92
+ logger.log('login status:', chalk_1["default"].yellow('logged'));
93
+ return [3, 4];
95
94
  case 3:
96
95
  error_1 = _o.sent();
97
- logger.log('login status:', chalk_1["default"].yellow('no login - invalid token'));
98
- return [4, (0, login_1.login)()];
96
+ logger.log('login status:', chalk_1["default"].keyword('orange')('no login - invalid token, you can login again with the command `zeus login`'));
97
+ args._loginAppToken = '';
98
+ process.env._loginAppToken = '';
99
+ return [3, 4];
99
100
  case 4:
100
- res = _o.sent();
101
- args._loginAppToken = res.appToken;
102
- process.env._loginAppToken = res.appToken;
103
- return [2, (0, exports.status)(args)];
104
- case 5:
105
101
  logger.log('nickName:', chalk_1["default"].yellow(nickName || '-'));
106
102
  logger.log('userID:', chalk_1["default"].yellow(userid));
103
+ return [3, 6];
104
+ case 5:
105
+ logger.log('login status:', chalk_1["default"].yellow('no login'));
107
106
  _o.label = 6;
108
107
  case 6:
109
108
  logger.log('simulator connect status:', chalk_1["default"].yellow(simulatorConnectStatus ? simulatorConnectStatus : 'disconnected'));
@@ -31,7 +31,7 @@ var ws_1 = __importDefault(require("ws"));
31
31
  var common_1 = require("../utils/common");
32
32
  var WebSocketClass = (function () {
33
33
  function WebSocketClass(_a) {
34
- var url = _a.url, connectCb = _a.connectCb, disconnectCb = _a.disconnectCb;
34
+ var url = _a.url, connectWSCB = _a.connectWSCB, disConnectWSCB = _a.disConnectWSCB;
35
35
  var _this = this;
36
36
  this.msgEventIDs = {};
37
37
  this.handleListenMsgEventReturn = function (data) {
@@ -60,11 +60,11 @@ var WebSocketClass = (function () {
60
60
  };
61
61
  this.socket = new ws_1["default"](url);
62
62
  this.socket.on('open', function () {
63
- connectCb();
63
+ connectWSCB();
64
64
  _this.listenEvent();
65
65
  });
66
66
  this.socket.on('close', function () {
67
- disconnectCb();
67
+ disConnectWSCB();
68
68
  });
69
69
  this.socket.on('error', function (error) {
70
70
  logger.error(error);
@@ -79,23 +79,32 @@ var WebSocketClass = (function () {
79
79
  WebSocketClass.prototype.uint8ToArray = function (source) {
80
80
  return Array.prototype.slice.call(source);
81
81
  };
82
- WebSocketClass.prototype.sendMessage = function (params, method) {
82
+ WebSocketClass.prototype.sendMessage = function (params, options) {
83
+ if (options === void 0) { options = {}; }
83
84
  var msgParams;
84
85
  var msg = params;
86
+ var _a = options.method, method = _a === void 0 ? '' : _a;
85
87
  if (method) {
86
88
  msgParams = {
87
89
  method: method,
88
90
  params: params,
89
91
  jsonrpc: '2.0',
90
- id: this.createMsgEventID(method)
92
+ id: this.createMsgEventID(method, params === null || params === void 0 ? void 0 : params.type)
91
93
  };
92
94
  msg = JSON.stringify(msgParams);
93
95
  }
94
96
  this.socket.send(msg, { binary: false });
95
97
  };
96
- WebSocketClass.prototype.createMsgEventID = function (method) {
97
- var id = Math.round(Math.random() * 100);
98
- this.msgEventIDs[method] = id;
98
+ WebSocketClass.prototype.createMsgEventID = function (method, type) {
99
+ var id = parseInt('' + Math.random() * 10000);
100
+ var prop = method;
101
+ var typeMap = {
102
+ 'screenshot': 'screenShot'
103
+ };
104
+ if (type && typeMap[type]) {
105
+ prop = typeMap[type];
106
+ }
107
+ this.msgEventIDs[prop] = id;
99
108
  return id;
100
109
  };
101
110
  return WebSocketClass;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeppos/zeus-cli",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
4
  "description": "zeus mini-program tools",
5
5
  "main": "index.js",
6
6
  "author": "zepp",
@@ -41,7 +41,7 @@
41
41
  "webpack": "^5.52.0"
42
42
  },
43
43
  "dependencies": {
44
- "@zeppos/zpm": "^2.3.9",
44
+ "@zeppos/zpm": "^2.3.10",
45
45
  "axios": "^0.23.0",
46
46
  "chalk": "^4.1.2",
47
47
  "chokidar": "^3.5.2",
@@ -84,6 +84,14 @@
84
84
  {
85
85
  "name": "gtr3-w",
86
86
  "deviceSource": 227
87
+ },
88
+ {
89
+ "name": "t-rex2",
90
+ "deviceSource": 418
91
+ },
92
+ {
93
+ "name": "t-rex2-w",
94
+ "deviceSource": 419
87
95
  }
88
96
  ],
89
97
  "designWidth": 454
@@ -120,6 +128,39 @@
120
128
  }
121
129
  ],
122
130
  "designWidth": 390
131
+ },
132
+ "teide": {
133
+ "module": {
134
+ "page": {
135
+ "pages": [
136
+ "page/t-rex2/home/index.page"
137
+ ],
138
+ "window": {
139
+ "navigationBarBackgroundColor": "#ffffff",
140
+ "navigationBarTextStyle": "black",
141
+ "navigationBarTitleText": "Hello World",
142
+ "backgroundColor": "#eeeeee",
143
+ "backgroundTextStyle": "light"
144
+ }
145
+ },
146
+ "app-side": {
147
+ "path": "app-side/index"
148
+ },
149
+ "setting": {
150
+ "path": "setting/index"
151
+ }
152
+ },
153
+ "platforms": [
154
+ {
155
+ "name": "t-rex2",
156
+ "deviceSource": 418
157
+ },
158
+ {
159
+ "name": "t-rex2-w",
160
+ "deviceSource": 419
161
+ }
162
+ ],
163
+ "designWidth": 454
123
164
  }
124
165
  },
125
166
  "i18n": {
package/utils/common.js CHANGED
@@ -29,6 +29,7 @@ exports.__esModule = true;
29
29
  exports.getDeviceInfoFromAppJson = exports.handleListenMsgEvent = exports.getOptionalConnectDevice = exports.uint8ToArray = void 0;
30
30
  var path = __importStar(require("path"));
31
31
  var fs_1 = __importDefault(require("fs"));
32
+ var os_1 = __importDefault(require("os"));
32
33
  var logger = __importStar(require("./logger"));
33
34
  var storage_1 = require("../modules/storage");
34
35
  var project_1 = require("../config/project");
@@ -97,6 +98,17 @@ function handleListenMsgEvent(msgEventName, data) {
97
98
  logger.info(str);
98
99
  }
99
100
  break;
101
+ case 'screenShot':
102
+ var path_1 = "".concat(os_1["default"].homedir(), "/desktop/screenShot.png");
103
+ fs_1["default"].writeFile(path_1, Buffer.from(data.result, 'hex'), function (err) {
104
+ if (err) {
105
+ logger.log('screenShot error', err);
106
+ }
107
+ else {
108
+ logger.success("screenShot path:".concat(path_1));
109
+ }
110
+ });
111
+ break;
100
112
  default:
101
113
  break;
102
114
  }
@@ -45,7 +45,8 @@ var HM_Analytics = function (event_id, options) {
45
45
  var eventPackageStr = Buffer.from(JSON.stringify(eventPackage)).toString('base64');
46
46
  axios_1["default"].post("".concat(project_1.analyticsHost, "/api/v5/server/collect"), eventPackageStr, {
47
47
  headers: {
48
- appid: analytics_app_id
48
+ appid: analytics_app_id,
49
+ 'content-type': 'text/plain'
49
50
  },
50
51
  timeout: 300
51
52
  })["catch"](function (_error) {