@zeppos/zeus-cli 1.1.3 → 1.1.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/api/index.js CHANGED
@@ -153,8 +153,8 @@ var getConnectDevServerWebSocketCode = function () { return __awaiter(void 0, vo
153
153
  throw new Error('401');
154
154
  }
155
155
  else {
156
- project_1.____inner_global_variable.bridgeOptionalDevice = '';
157
- project_1.____inner_global_variable.bridgeChoiredDevice = '';
156
+ process.env._bridgeOptionalDevice = '';
157
+ process.env._bridgeChoiredDevice = '';
158
158
  throw new Error("GetConnectDevServerWebSocketCode error");
159
159
  }
160
160
  return [3, 4];
@@ -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/config/project.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  exports.__esModule = true;
6
- exports.simulatorStorageKey = exports.buildStorageKey = exports.____inner_global_variable = exports.analyticsKey = exports.loginStorageKey = exports.loginConfig = exports.analyticsHost = exports.gitignoreDefaultItem = exports.ACCOUNT_ENV_KEY = exports.TemplateCopyType = exports.AppSourceType = exports.AppType = void 0;
6
+ exports.simulatorStorageKey = exports.analyticsKey = exports.loginStorageKey = exports.loginConfig = exports.analyticsHost = exports.gitignoreDefaultItem = exports.ACCOUNT_ENV_KEY = exports.TemplateCopyType = exports.AppSourceType = exports.AppType = void 0;
7
7
  var lodash_1 = __importDefault(require("lodash"));
8
8
  var AppType;
9
9
  (function (AppType) {
@@ -41,13 +41,6 @@ exports.loginStorageKey = {
41
41
  exports.analyticsKey = {
42
42
  id: "".concat(accountPrefix, "analyticsId")
43
43
  };
44
- exports.____inner_global_variable = {
45
- bridgeOptionalDevice: '',
46
- bridgeChoiredDevice: ''
47
- };
48
- exports.buildStorageKey = {
49
- targetDeviceToBuild: "".concat(accountPrefix, "targetDeviceToBuild")
50
- };
51
44
  exports.simulatorStorageKey = {
52
45
  simulatorHost: 'simulator_host',
53
46
  simulatorPort: 'simulator_port',
package/modules/bridge.js CHANGED
@@ -66,7 +66,6 @@ exports.bridge = void 0;
66
66
  var chalk_1 = __importDefault(require("chalk"));
67
67
  var fs_1 = require("fs");
68
68
  var logger = __importStar(require("../utils/logger"));
69
- var project_1 = require("../config/project");
70
69
  var index_1 = require("../api/index");
71
70
  var websocket_1 = __importDefault(require("./websocket"));
72
71
  var build_1 = require("./build");
@@ -80,7 +79,7 @@ var connectDevice = function (vorpal) { return __awaiter(void 0, void 0, void 0,
80
79
  return __generator(this, function (_a) {
81
80
  switch (_a.label) {
82
81
  case 0:
83
- debugConnectedDevice = JSON.parse(project_1.____inner_global_variable.bridgeOptionalDevice);
82
+ debugConnectedDevice = JSON.parse(process.env._bridgeOptionalDevice);
84
83
  optionalDeviceArr = Object.keys(debugConnectedDevice);
85
84
  len = optionalDeviceArr.length;
86
85
  if (!(len === 0)) return [3, 1];
@@ -104,15 +103,15 @@ var connectDevice = function (vorpal) { return __awaiter(void 0, void 0, void 0,
104
103
  _a.sent();
105
104
  _a.label = 3;
106
105
  case 3:
107
- project_1.____inner_global_variable.bridgeChoiredDevice = choiredDevice;
108
- client.sendMessage({ clientId: clientId_1 }, 'connectClient');
106
+ process.env._bridgeChoiredDevice = choiredDevice;
107
+ client.sendMessage({ clientId: clientId_1 }, { method: 'connectClient' });
109
108
  hasConnectDevice = true;
110
109
  _a.label = 4;
111
110
  case 4: return [2];
112
111
  }
113
112
  });
114
113
  }); };
115
- var connectBridgeWSCallback = function () {
114
+ var connectWSCB = function () {
116
115
  var vorpal = require('vorpal')();
117
116
  vorpal.find('help').hidden();
118
117
  vorpal.find('exit').remove();
@@ -146,7 +145,7 @@ var connectBridgeWSCallback = function () {
146
145
  case 0:
147
146
  if (!hasConnectDevice) return [3, 2];
148
147
  return [4, (0, build_1.buildPreview)({ _: ['install', "".concat(choiredDevice.toLowerCase())], '$0': 'zeus' }, function (params) {
149
- client.sendMessage(params, 'packagePush');
148
+ client.sendMessage(params, { method: 'packagePush' });
150
149
  })];
151
150
  case 1:
152
151
  _a.sent();
@@ -170,14 +169,14 @@ var connectBridgeWSCallback = function () {
170
169
  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
170
  }
172
171
  else {
173
- vorpal.log(chalk_1["default"].blue('Uninstalling'));
172
+ vorpal.log(chalk_1["default"].blue('Uninstalling...'));
174
173
  _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');
174
+ client.sendMessage({ type: 'delete', appid: appid, appName: appName, appType: appType }, { method: 'sysSettingPush' });
176
175
  }
177
176
  }
178
177
  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');
178
+ vorpal.log(chalk_1["default"].blue('Uninstalling...'));
179
+ client.sendMessage({ type: 'delete', appid: args.appid }, { method: 'sysSettingPush' });
181
180
  }
182
181
  else if (args.appid) {
183
182
  vorpal.log("".concat(chalk_1["default"].red('error'), " invalid '").concat(args.appid, "', the 'uninstall' command should be followed by appid or blank."));
@@ -186,8 +185,28 @@ var connectBridgeWSCallback = function () {
186
185
  return [2];
187
186
  });
188
187
  }); });
188
+ vorpal
189
+ .command('screenshot', 'Screenshot of the current watch device.').hidden()
190
+ .action(function (args, cb) { return __awaiter(void 0, void 0, void 0, function () {
191
+ return __generator(this, function (_a) {
192
+ if (hasConnectDevice) {
193
+ if (choiredDevice.indexOf('app') > -1) {
194
+ vorpal.log(chalk_1["default"].blue('Waiting...'));
195
+ client.sendMessage({ type: 'screenshot' }, { method: 'sysSettingPush' });
196
+ }
197
+ else {
198
+ vorpal.log(chalk_1["default"].yellow("Only the connected device is an app that can use the screenshot command."));
199
+ }
200
+ }
201
+ else {
202
+ vorpal.log(chalk_1["default"].yellow("No device is connected, please connect the device with the command width 'connect' first."));
203
+ }
204
+ cb();
205
+ return [2];
206
+ });
207
+ }); });
189
208
  };
190
- var disConnectBridgeWSCallback = function () {
209
+ var disConnectWSCB = function () {
191
210
  hasConnectDevice = false;
192
211
  logger.log('Disconnected');
193
212
  process.exit(1);
@@ -203,8 +222,8 @@ var bridge = function (args) { return __awaiter(void 0, void 0, void 0, function
203
222
  bridgeWebSocketURL = _a.sent();
204
223
  client = new websocket_1["default"]({
205
224
  url: "".concat(bridgeWebSocketURL, "?type=development&name=CLI"),
206
- connectCb: connectBridgeWSCallback,
207
- disconnectCb: disConnectBridgeWSCallback
225
+ connectWSCB: connectWSCB,
226
+ disConnectWSCB: disConnectWSCB
208
227
  });
209
228
  logger.log(" - Enter 'help' to view the command.");
210
229
  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"));
@@ -100,65 +100,75 @@ function handleExecCommandInErrorDir(mode) {
100
100
  function chooseBuildPackages(mode) {
101
101
  if (mode === void 0) { mode = 'development'; }
102
102
  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) {
103
+ var targets, _a, promptTarget_1, answers;
104
+ return __generator(this, function (_b) {
105
+ switch (_b.label) {
107
106
  case 0:
108
107
  if (!appJsonContent) {
109
108
  handleExecCommandInErrorDir(mode);
110
109
  }
111
- targets = Object.keys(lodash_1["default"].get(appJsonContent, 'targets', {}));
110
+ targets = Object.keys((0, lodash_1.get)(appJsonContent, 'targets', {}));
112
111
  if (!!targets.length) return [3, 1];
113
112
  logger.error('Please set at least one package.');
114
113
  process.exit(1);
115
114
  return [3, 4];
116
115
  case 1:
117
116
  if (!(targets.length === 1)) return [3, 2];
118
- storage_1.globalStorage.set((_a = {}, _a[project_1.buildStorageKey.targetDeviceToBuild] = targets[0], _a));
119
117
  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
- ])];
118
+ case 2:
119
+ _a = process.env._targetDeviceToBuild, promptTarget_1 = _a === void 0 ? '' : _a;
120
+ return [4, inquirer_1["default"].prompt([
121
+ {
122
+ name: 'target',
123
+ type: 'list',
124
+ when: function (args) {
125
+ var bool = targets.includes(promptTarget_1);
126
+ if (bool) {
127
+ args.target = promptTarget_1;
128
+ }
129
+ return mode !== BuildMode.PROD && !bool;
130
+ },
131
+ message: 'Which target would you like to preview?',
132
+ choices: targets
133
+ },
134
+ {
135
+ name: 'target',
136
+ type: 'checkbox',
137
+ when: function (args) {
138
+ var arr = typeof promptTarget_1 === 'string' ? (0, lodash_1.intersection)(targets, promptTarget_1.split(',')) : [];
139
+ var bool = !!arr.length;
140
+ if (bool) {
141
+ args.target = arr;
142
+ }
143
+ return mode === BuildMode.PROD && !bool;
144
+ },
145
+ choices: targets.map(function (item) { return ({
146
+ name: item,
147
+ value: item,
148
+ checked: true
149
+ }); }),
150
+ message: 'Which targets would you like to build?'
151
+ }
152
+ ])];
140
153
  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];
154
+ answers = _b.sent();
155
+ return [2, typeof answers.target === 'string' ? [answers.target] : answers.target];
146
156
  case 4: return [2];
147
157
  }
148
158
  });
149
159
  });
150
160
  }
151
161
  exports.chooseBuildPackages = chooseBuildPackages;
152
- var build = function (mode, packages, buildConfigOption) {
162
+ var build = function (mode, buildConfigOption) {
153
163
  if (mode === void 0) { mode = BuildMode.PROD; }
154
- if (packages === void 0) { packages = []; }
155
164
  return __awaiter(void 0, void 0, void 0, function () {
156
- var workspace, choosePackages, buildOptions, _a, js2c, js2bin, png2vg, prune, curJscMode, curTarget, buildInfo_1, DistDir_1, error_1;
165
+ var workspace, packages, choosePackages, buildOptions, _a, js2c, js2bin, png2vg, prune, curJscMode, curOpt, productName_1, DistDir_1, appId, name_1, newName_1, error_1;
157
166
  return __generator(this, function (_b) {
158
167
  switch (_b.label) {
159
168
  case 0:
160
169
  workspace = path.resolve('./');
161
- if (!!packages.length) return [3, 2];
170
+ process.env._targetDeviceToBuild = (buildConfigOption === null || buildConfigOption === void 0 ? void 0 : buildConfigOption.target) || '';
171
+ packages = [];
162
172
  return [4, chooseBuildPackages(mode)];
163
173
  case 1:
164
174
  choosePackages = _b.sent();
@@ -167,8 +177,9 @@ var build = function (mode, packages, buildConfigOption) {
167
177
  return [2];
168
178
  }
169
179
  packages.push.apply(packages, choosePackages);
170
- _b.label = 2;
171
- case 2:
180
+ if (!process.env._targetDeviceToBuild) {
181
+ process.env._targetDeviceToBuild = packages[0];
182
+ }
172
183
  buildOptions = {
173
184
  path: workspace,
174
185
  targets: packages,
@@ -194,50 +205,58 @@ var build = function (mode, packages, buildConfigOption) {
194
205
  jsc: curJscMode
195
206
  });
196
207
  }
197
- _b.label = 3;
198
- case 3:
199
- _b.trys.push([3, 8, , 9]);
200
- curTarget = (buildConfigOption ? buildConfigOption._ : [''])[0];
201
- if (!(mode !== BuildMode.DEV || (mode === BuildMode.DEV && curTarget === 'install'))) return [3, 5];
208
+ _b.label = 2;
209
+ case 2:
210
+ _b.trys.push([2, 7, , 8]);
211
+ curOpt = (buildConfigOption ? buildConfigOption._ : [''])[0];
212
+ if (!(mode !== BuildMode.DEV || (mode === BuildMode.DEV && curOpt === 'install'))) return [3, 4];
202
213
  return [4, (0, node_js_1.start)(buildOptions)];
203
- case 4:
204
- buildInfo_1 = _b.sent();
205
- if (buildInfo_1) {
214
+ case 3:
215
+ productName_1 = _b.sent();
216
+ if (productName_1) {
206
217
  DistDir_1 = path.join(workspace, 'dist');
218
+ appId = (0, lodash_1.get)(appJsonContent, 'app.appId');
219
+ name_1 = productName_1.replace(/[\s]/g, '_').split('.zab');
220
+ newName_1 = "".concat(appId, "-").concat(name_1[0], ".zab");
207
221
  rd.eachFileSync(DistDir_1, function (file) {
208
- if (file !== path.join(DistDir_1, buildInfo_1)) {
222
+ var oldName = path.join(DistDir_1, productName_1);
223
+ if (file !== oldName) {
209
224
  fs_extra_1["default"].removeSync(file);
210
225
  }
226
+ else {
227
+ fs_1["default"].renameSync(oldName, path.join(DistDir_1, newName_1));
228
+ }
211
229
  });
230
+ productName_1 = newName_1;
212
231
  }
213
- return [2, buildInfo_1];
214
- case 5:
215
- if (!(mode === BuildMode.DEV)) return [3, 7];
232
+ return [2, productName_1];
233
+ case 4:
234
+ if (!(mode === BuildMode.DEV)) return [3, 6];
216
235
  return [4, (0, node_js_1.startWithoutDist)(buildOptions)];
217
- case 6:
236
+ case 5:
218
237
  _b.sent();
219
238
  return [2, (0, node_js_1.getZpkBuf)(packages[0])];
220
- case 7: return [3, 9];
221
- case 8:
239
+ case 6: return [3, 8];
240
+ case 7:
222
241
  error_1 = _b.sent();
223
242
  logger.error(error_1);
224
- return [3, 9];
225
- case 9: return [2];
243
+ return [3, 8];
244
+ case 8: return [2];
226
245
  }
227
246
  });
228
247
  });
229
248
  };
230
249
  exports.build = build;
231
- var buildDev = function (packages) {
250
+ var buildDev = function (args) {
232
251
  (0, hm_analytics_1.HM_Analytics)('ZEPP_CLI_DEV_C');
233
- return (0, exports.build)(BuildMode.DEV, packages);
252
+ return (0, exports.build)(BuildMode.DEV, args);
234
253
  };
235
254
  exports.buildDev = buildDev;
236
255
  var buildProd = function (args) { return __awaiter(void 0, void 0, void 0, function () {
237
256
  var buildInfo;
238
257
  return __generator(this, function (_a) {
239
258
  switch (_a.label) {
240
- case 0: return [4, (0, exports.build)(BuildMode.PROD, [], args)];
259
+ case 0: return [4, (0, exports.build)(BuildMode.PROD, args)];
241
260
  case 1:
242
261
  buildInfo = _a.sent();
243
262
  if (buildInfo) {
@@ -259,38 +278,38 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
259
278
  _a = args._, curCommand = _a[0], curBridgeTarget = _a[1];
260
279
  buildMode = (curBridgeTarget && curBridgeTarget === 'simulator') ? BuildMode.DEV : BuildMode.PREVIEW;
261
280
  logger.info('building...');
262
- return [4, (0, exports.build)(buildMode, [], args)];
281
+ return [4, (0, exports.build)(buildMode, args)];
263
282
  case 1:
264
283
  buildInfo = _b.sent();
265
- appType = lodash_1["default"].get(appJsonContent, 'app.appType');
284
+ appType = (0, lodash_1.get)(appJsonContent, 'app.appType');
266
285
  isWatchFaceProject = appType === project_1.AppType.WATCHFACE;
267
286
  logger.info('getting package...');
268
287
  form = new form_data_1["default"]();
269
288
  form.append('file', fs_1["default"].createReadStream("./dist/".concat(buildInfo)));
270
289
  form.append('app_type', isWatchFaceProject ? '1' : '2');
271
290
  form.getLength(function (err, length) { return __awaiter(void 0, void 0, void 0, function () {
272
- var _a, _subRegionalHost, _accountEnv, protocol, code, res, error_2, url, _b, deviceSource, appId, appName, appType_1, deviceSourceArr, targetDeviceInternalName, packageInfo, url, preview, downloadPackageReturn;
273
- return __generator(this, function (_c) {
274
- switch (_c.label) {
291
+ var _subRegionalHost, protocol, code, res, error_2, url, _a, deviceSource, appId, appName, appType_1, deviceSourceArr, targetDeviceInternalName, packageInfo, url, preview, downloadPackageReturn;
292
+ return __generator(this, function (_b) {
293
+ switch (_b.label) {
275
294
  case 0:
276
295
  if (err) {
277
296
  logger.error('getting package failed.');
278
297
  return [2];
279
298
  }
280
- _a = process.env, _subRegionalHost = _a._subRegionalHost, _accountEnv = _a._accountEnv;
299
+ _subRegionalHost = process.env._subRegionalHost;
281
300
  protocol = '';
282
301
  code = '';
283
- _c.label = 1;
302
+ _b.label = 1;
284
303
  case 1:
285
- _c.trys.push([1, 3, , 7]);
304
+ _b.trys.push([1, 3, , 7]);
286
305
  return [4, (0, api_1.uploadPackage)(form, length)];
287
306
  case 2:
288
- res = _c.sent();
307
+ res = _b.sent();
289
308
  protocol = res.protocol;
290
309
  code = res.code;
291
310
  return [3, 7];
292
311
  case 3:
293
- error_2 = _c.sent();
312
+ error_2 = _b.sent();
294
313
  if (!((error_2 === null || error_2 === void 0 ? void 0 : error_2.message) === '401')) return [3, 5];
295
314
  logger.warn("Login information is invalid. Please login again, or end this service and login again with the command 'zeus login'.");
296
315
  return [4, (0, login_1.login)().then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
@@ -301,7 +320,7 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
301
320
  });
302
321
  }); })];
303
322
  case 4:
304
- _c.sent();
323
+ _b.sent();
305
324
  return [3, 6];
306
325
  case 5:
307
326
  logger.error(error_2 === null || error_2 === void 0 ? void 0 : error_2.message);
@@ -312,8 +331,9 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
312
331
  url = "".concat(protocol, "://").concat(_subRegionalHost, "/custom/tools/app-dial/download/").concat(code);
313
332
  if (protocol && code) {
314
333
  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.');
334
+ logger.success("Please use Zepp APP to scan the following qrcode to preview your ".concat(isWatchFaceProject ? 'WatchFace' : 'application', " within two hours."));
316
335
  qrcode_terminal_1["default"].generate(url, { small: true });
336
+ storage_1.globalStorage.set({ ____preview_url: url });
317
337
  }
318
338
  else {
319
339
  logger.error('Generating preview qrcode failed, please check your network.');
@@ -321,14 +341,14 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
321
341
  return [3, 10];
322
342
  case 8:
323
343
  if (!(curCommand === 'install')) return [3, 10];
324
- _b = (0, common_1.getDeviceInfoFromAppJson)(), deviceSource = _b.deviceSource, appId = _b.appId, appName = _b.appName, appType_1 = _b.appType, deviceSourceArr = _b.deviceSourceArr, targetDeviceInternalName = _b.targetDeviceInternalName;
344
+ _a = (0, common_1.getDeviceInfoFromAppJson)(), deviceSource = _a.deviceSource, appId = _a.appId, appName = _a.appName, appType_1 = _a.appType, deviceSourceArr = _a.deviceSourceArr, targetDeviceInternalName = _a.targetDeviceInternalName;
325
345
  return [4, (0, api_1.downloadPackage)(code, deviceSource, appType_1)];
326
346
  case 9:
327
- packageInfo = _c.sent();
347
+ packageInfo = _b.sent();
328
348
  url = packageInfo;
329
349
  preview = '';
330
350
  if (isWatchFaceProject) {
331
- downloadPackageReturn = lodash_1["default"].get(packageInfo, 'data', {});
351
+ downloadPackageReturn = (0, lodash_1.get)(packageInfo, 'data', {});
332
352
  url = downloadPackageReturn.url;
333
353
  preview = downloadPackageReturn.preview;
334
354
  }
@@ -345,7 +365,7 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
345
365
  target: targetDeviceInternalName
346
366
  });
347
367
  }
348
- _c.label = 10;
368
+ _b.label = 10;
349
369
  case 10: return [2];
350
370
  }
351
371
  });
@@ -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,71 @@ 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, 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();
113
130
  simulatorWebSocketURL = "http://".concat(simulatorHost, ":").concat(simulatorPort);
114
131
  simulator = new simulator_1.Simulator(simulatorWebSocketURL);
115
132
  refreshSimulator = lodash_1["default"].debounce(function () { return __awaiter(void 0, void 0, void 0, function () {
116
- var zpkBuffer, _a, targetDeviceInternalName, appId, projectName;
133
+ var zpkBuffer, _a, targetDeviceInternalName, appId, devices, projectName;
117
134
  return __generator(this, function (_b) {
118
135
  switch (_b.label) {
119
136
  case 0:
120
137
  logger.info('rebuilding...');
121
- return [4, (0, build_1.buildDev)(packages)];
138
+ return [4, (0, build_1.buildDev)(args)];
122
139
  case 1:
123
140
  zpkBuffer = _b.sent();
124
141
  if (zpkBuffer) {
125
142
  logger.info('rebuild done');
126
143
  logger.info('refreshing simulator...');
127
- _a = (0, common_1.getDeviceInfoFromAppJson)(packages[0]), targetDeviceInternalName = _a.targetDeviceInternalName, appId = _a.appId;
144
+ _a = (0, common_1.getDeviceInfoFromAppJson)(), targetDeviceInternalName = _a.targetDeviceInternalName, appId = _a.appId, devices = _a.deviceSourceArr;
128
145
  projectName = path.parse(process.cwd()).base;
129
- simulator.upload(zpkBuffer, projectName, targetDeviceInternalName, appId);
146
+ simulator.upload(zpkBuffer, projectName, targetDeviceInternalName, appId, devices);
130
147
  }
131
148
  else {
132
149
  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
  };
@@ -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.3",
3
+ "version": "1.1.6",
4
4
  "description": "zeus mini-program tools",
5
5
  "main": "index.js",
6
6
  "author": "zepp",
@@ -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,9 +29,8 @@ 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
- var storage_1 = require("../modules/storage");
34
- var project_1 = require("../config/project");
35
34
  var device_1 = require("../config/device");
36
35
  function uint8ToArray(source) {
37
36
  return Array.prototype.slice.call(source);
@@ -57,13 +56,13 @@ function handleListenMsgEvent(msgEventName, data) {
57
56
  }
58
57
  else if (typeof data === 'object' && ((_a = data === null || data === void 0 ? void 0 : data.params) === null || _a === void 0 ? void 0 : _a.clients)) {
59
58
  var connectedDevice = getOptionalConnectDevice(data.params.clients);
60
- project_1.____inner_global_variable.bridgeOptionalDevice = JSON.stringify(connectedDevice);
59
+ process.env._bridgeOptionalDevice = JSON.stringify(connectedDevice);
61
60
  }
62
61
  break;
63
62
  case 'connectClient':
64
63
  var _d = data.result, result = _d === void 0 ? '' : _d, _e = data.error, error = _e === void 0 ? {} : _e;
65
64
  if (result && result === 'success') {
66
- var choiredDevice = project_1.____inner_global_variable.bridgeChoiredDevice;
65
+ var choiredDevice = process.env._bridgeChoiredDevice;
67
66
  logger.info("successfully connected to ".concat(choiredDevice, "."));
68
67
  }
69
68
  if (error && JSON.stringify(error) !== '{}') {
@@ -93,17 +92,30 @@ function handleListenMsgEvent(msgEventName, data) {
93
92
  }
94
93
  else if (typeof data === 'object' && (data === null || data === void 0 ? void 0 : data.params)) {
95
94
  var _j = data.params, level = _j.level, time = _j.time, message = _j.message;
96
- var str = "[".concat(level.toUpperCase() || 'DEBUG', " - ").concat(new Date(time).toLocaleTimeString(), "] ").concat(message);
95
+ var timeString = time.toString();
96
+ var fTime = Number(timeString.length > 13 ? timeString.substr(0, 13) : timeString);
97
+ var str = "[".concat(level.toUpperCase() || 'DEBUG', "-").concat(new Date(fTime).toLocaleTimeString(), ".").concat(new Date(fTime).getMilliseconds(), "] ").concat(message);
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
  }
103
115
  }
104
116
  exports.handleListenMsgEvent = handleListenMsgEvent;
105
- var getDeviceInfoFromAppJson = function (curTarget) {
106
- var _curTarget = curTarget ? curTarget : storage_1.globalStorage.get(project_1.buildStorageKey.targetDeviceToBuild);
117
+ var getDeviceInfoFromAppJson = function () {
118
+ var _curTarget = process.env._targetDeviceToBuild;
107
119
  var appJsonFilePath = path.resolve('./app.json');
108
120
  var appJsonContent = JSON.parse(fs_1["default"].readFileSync(appJsonFilePath, 'utf-8'));
109
121
  var targets = appJsonContent.targets;
@@ -148,6 +148,7 @@ var initVariable = function (args) { return __awaiter(void 0, void 0, void 0, fu
148
148
  _a.label = 2;
149
149
  case 2:
150
150
  __env = {
151
+ _targetDeviceToBuild: '',
151
152
  _loginAppToken: apptoken,
152
153
  _loginUserId: userid,
153
154
  _loginCname: cname,