@zeppos/zeus-cli 1.1.5 → 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];
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,7 +103,7 @@ 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;
106
+ process.env._bridgeChoiredDevice = choiredDevice;
108
107
  client.sendMessage({ clientId: clientId_1 }, { method: 'connectClient' });
109
108
  hasConnectDevice = true;
110
109
  _a.label = 4;
package/modules/build.js CHANGED
@@ -97,14 +97,12 @@ 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, buildConfigOption) {
100
+ function chooseBuildPackages(mode) {
101
101
  if (mode === void 0) { mode = 'development'; }
102
- if (buildConfigOption === void 0) { buildConfigOption = {}; }
103
102
  return __awaiter(this, void 0, void 0, function () {
104
103
  var targets, _a, promptTarget_1, answers;
105
- var _b, _c;
106
- return __generator(this, function (_d) {
107
- switch (_d.label) {
104
+ return __generator(this, function (_b) {
105
+ switch (_b.label) {
108
106
  case 0:
109
107
  if (!appJsonContent) {
110
108
  handleExecCommandInErrorDir(mode);
@@ -116,10 +114,9 @@ function chooseBuildPackages(mode, buildConfigOption) {
116
114
  return [3, 4];
117
115
  case 1:
118
116
  if (!(targets.length === 1)) return [3, 2];
119
- storage_1.globalStorage.set((_b = {}, _b[project_1.buildStorageKey.targetDeviceToBuild] = targets[0], _b));
120
117
  return [2, [targets[0]]];
121
118
  case 2:
122
- _a = buildConfigOption.target, promptTarget_1 = _a === void 0 ? '' : _a;
119
+ _a = process.env._targetDeviceToBuild, promptTarget_1 = _a === void 0 ? '' : _a;
123
120
  return [4, inquirer_1["default"].prompt([
124
121
  {
125
122
  name: 'target',
@@ -154,8 +151,7 @@ function chooseBuildPackages(mode, buildConfigOption) {
154
151
  }
155
152
  ])];
156
153
  case 3:
157
- answers = _d.sent();
158
- storage_1.globalStorage.set((_c = {}, _c[project_1.buildStorageKey.targetDeviceToBuild] = answers.target, _c));
154
+ answers = _b.sent();
159
155
  return [2, typeof answers.target === 'string' ? [answers.target] : answers.target];
160
156
  case 4: return [2];
161
157
  }
@@ -163,17 +159,17 @@ function chooseBuildPackages(mode, buildConfigOption) {
163
159
  });
164
160
  }
165
161
  exports.chooseBuildPackages = chooseBuildPackages;
166
- var build = function (mode, packages, buildConfigOption) {
162
+ var build = function (mode, buildConfigOption) {
167
163
  if (mode === void 0) { mode = BuildMode.PROD; }
168
- if (packages === void 0) { packages = []; }
169
164
  return __awaiter(void 0, void 0, void 0, function () {
170
- 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;
171
166
  return __generator(this, function (_b) {
172
167
  switch (_b.label) {
173
168
  case 0:
174
169
  workspace = path.resolve('./');
175
- if (!!packages.length) return [3, 2];
176
- return [4, chooseBuildPackages(mode, buildConfigOption)];
170
+ process.env._targetDeviceToBuild = (buildConfigOption === null || buildConfigOption === void 0 ? void 0 : buildConfigOption.target) || '';
171
+ packages = [];
172
+ return [4, chooseBuildPackages(mode)];
177
173
  case 1:
178
174
  choosePackages = _b.sent();
179
175
  if (!choosePackages || !choosePackages.length) {
@@ -181,8 +177,9 @@ var build = function (mode, packages, buildConfigOption) {
181
177
  return [2];
182
178
  }
183
179
  packages.push.apply(packages, choosePackages);
184
- _b.label = 2;
185
- case 2:
180
+ if (!process.env._targetDeviceToBuild) {
181
+ process.env._targetDeviceToBuild = packages[0];
182
+ }
186
183
  buildOptions = {
187
184
  path: workspace,
188
185
  targets: packages,
@@ -208,50 +205,58 @@ var build = function (mode, packages, buildConfigOption) {
208
205
  jsc: curJscMode
209
206
  });
210
207
  }
211
- _b.label = 3;
212
- case 3:
213
- _b.trys.push([3, 8, , 9]);
214
- curTarget = (buildConfigOption ? buildConfigOption._ : [''])[0];
215
- 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];
216
213
  return [4, (0, node_js_1.start)(buildOptions)];
217
- case 4:
218
- buildInfo_1 = _b.sent();
219
- if (buildInfo_1) {
214
+ case 3:
215
+ productName_1 = _b.sent();
216
+ if (productName_1) {
220
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");
221
221
  rd.eachFileSync(DistDir_1, function (file) {
222
- if (file !== path.join(DistDir_1, buildInfo_1)) {
222
+ var oldName = path.join(DistDir_1, productName_1);
223
+ if (file !== oldName) {
223
224
  fs_extra_1["default"].removeSync(file);
224
225
  }
226
+ else {
227
+ fs_1["default"].renameSync(oldName, path.join(DistDir_1, newName_1));
228
+ }
225
229
  });
230
+ productName_1 = newName_1;
226
231
  }
227
- return [2, buildInfo_1];
228
- case 5:
229
- if (!(mode === BuildMode.DEV)) return [3, 7];
232
+ return [2, productName_1];
233
+ case 4:
234
+ if (!(mode === BuildMode.DEV)) return [3, 6];
230
235
  return [4, (0, node_js_1.startWithoutDist)(buildOptions)];
231
- case 6:
236
+ case 5:
232
237
  _b.sent();
233
238
  return [2, (0, node_js_1.getZpkBuf)(packages[0])];
234
- case 7: return [3, 9];
235
- case 8:
239
+ case 6: return [3, 8];
240
+ case 7:
236
241
  error_1 = _b.sent();
237
242
  logger.error(error_1);
238
- return [3, 9];
239
- case 9: return [2];
243
+ return [3, 8];
244
+ case 8: return [2];
240
245
  }
241
246
  });
242
247
  });
243
248
  };
244
249
  exports.build = build;
245
- var buildDev = function (args, packages) {
250
+ var buildDev = function (args) {
246
251
  (0, hm_analytics_1.HM_Analytics)('ZEPP_CLI_DEV_C');
247
- return (0, exports.build)(BuildMode.DEV, packages, args);
252
+ return (0, exports.build)(BuildMode.DEV, args);
248
253
  };
249
254
  exports.buildDev = buildDev;
250
255
  var buildProd = function (args) { return __awaiter(void 0, void 0, void 0, function () {
251
256
  var buildInfo;
252
257
  return __generator(this, function (_a) {
253
258
  switch (_a.label) {
254
- case 0: return [4, (0, exports.build)(BuildMode.PROD, [], args)];
259
+ case 0: return [4, (0, exports.build)(BuildMode.PROD, args)];
255
260
  case 1:
256
261
  buildInfo = _a.sent();
257
262
  if (buildInfo) {
@@ -273,7 +278,7 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
273
278
  _a = args._, curCommand = _a[0], curBridgeTarget = _a[1];
274
279
  buildMode = (curBridgeTarget && curBridgeTarget === 'simulator') ? BuildMode.DEV : BuildMode.PREVIEW;
275
280
  logger.info('building...');
276
- return [4, (0, exports.build)(buildMode, [], args)];
281
+ return [4, (0, exports.build)(buildMode, args)];
277
282
  case 1:
278
283
  buildInfo = _b.sent();
279
284
  appType = (0, lodash_1.get)(appJsonContent, 'app.appType');
@@ -283,28 +288,28 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
283
288
  form.append('file', fs_1["default"].createReadStream("./dist/".concat(buildInfo)));
284
289
  form.append('app_type', isWatchFaceProject ? '1' : '2');
285
290
  form.getLength(function (err, length) { return __awaiter(void 0, void 0, void 0, function () {
286
- var _a, _subRegionalHost, _accountEnv, protocol, code, res, error_2, url, _b, deviceSource, appId, appName, appType_1, deviceSourceArr, targetDeviceInternalName, packageInfo, url, preview, downloadPackageReturn;
287
- return __generator(this, function (_c) {
288
- 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) {
289
294
  case 0:
290
295
  if (err) {
291
296
  logger.error('getting package failed.');
292
297
  return [2];
293
298
  }
294
- _a = process.env, _subRegionalHost = _a._subRegionalHost, _accountEnv = _a._accountEnv;
299
+ _subRegionalHost = process.env._subRegionalHost;
295
300
  protocol = '';
296
301
  code = '';
297
- _c.label = 1;
302
+ _b.label = 1;
298
303
  case 1:
299
- _c.trys.push([1, 3, , 7]);
304
+ _b.trys.push([1, 3, , 7]);
300
305
  return [4, (0, api_1.uploadPackage)(form, length)];
301
306
  case 2:
302
- res = _c.sent();
307
+ res = _b.sent();
303
308
  protocol = res.protocol;
304
309
  code = res.code;
305
310
  return [3, 7];
306
311
  case 3:
307
- error_2 = _c.sent();
312
+ error_2 = _b.sent();
308
313
  if (!((error_2 === null || error_2 === void 0 ? void 0 : error_2.message) === '401')) return [3, 5];
309
314
  logger.warn("Login information is invalid. Please login again, or end this service and login again with the command 'zeus login'.");
310
315
  return [4, (0, login_1.login)().then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
@@ -315,7 +320,7 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
315
320
  });
316
321
  }); })];
317
322
  case 4:
318
- _c.sent();
323
+ _b.sent();
319
324
  return [3, 6];
320
325
  case 5:
321
326
  logger.error(error_2 === null || error_2 === void 0 ? void 0 : error_2.message);
@@ -326,7 +331,7 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
326
331
  url = "".concat(protocol, "://").concat(_subRegionalHost, "/custom/tools/app-dial/download/").concat(code);
327
332
  if (protocol && code) {
328
333
  logger.info('Generating preview qrcode...');
329
- logger.success('Please use Zepp APP to scan the following qrcode to preview your application within two hours.');
334
+ logger.success("Please use Zepp APP to scan the following qrcode to preview your ".concat(isWatchFaceProject ? 'WatchFace' : 'application', " within two hours."));
330
335
  qrcode_terminal_1["default"].generate(url, { small: true });
331
336
  storage_1.globalStorage.set({ ____preview_url: url });
332
337
  }
@@ -336,10 +341,10 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
336
341
  return [3, 10];
337
342
  case 8:
338
343
  if (!(curCommand === 'install')) return [3, 10];
339
- _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;
340
345
  return [4, (0, api_1.downloadPackage)(code, deviceSource, appType_1)];
341
346
  case 9:
342
- packageInfo = _c.sent();
347
+ packageInfo = _b.sent();
343
348
  url = packageInfo;
344
349
  preview = '';
345
350
  if (isWatchFaceProject) {
@@ -360,7 +365,7 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
360
365
  target: targetDeviceInternalName
361
366
  });
362
367
  }
363
- _c.label = 10;
368
+ _b.label = 10;
364
369
  case 10: return [2];
365
370
  }
366
371
  });
package/modules/run.js CHANGED
@@ -79,7 +79,7 @@ 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 simulatorHost, simulatorPort, _a, promptSimulatorHost, _b, promptSimulatorPort, answer, hasStarted, packages, simulatorWebSocketURL, simulator, refreshSimulator, gitignorePath, gitignore, ignored;
82
+ var simulatorHost, simulatorPort, _a, promptSimulatorHost, _b, promptSimulatorPort, answer, hasStarted, simulatorWebSocketURL, simulator, refreshSimulator, gitignorePath, gitignore, ignored;
83
83
  var _c;
84
84
  return __generator(this, function (_d) {
85
85
  switch (_d.label) {
@@ -127,9 +127,6 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
127
127
  _c));
128
128
  }
129
129
  hasStarted = false;
130
- return [4, (0, build_1.chooseBuildPackages)('development', args)];
131
- case 2:
132
- packages = _d.sent();
133
130
  simulatorWebSocketURL = "http://".concat(simulatorHost, ":").concat(simulatorPort);
134
131
  simulator = new simulator_1.Simulator(simulatorWebSocketURL);
135
132
  refreshSimulator = lodash_1["default"].debounce(function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -138,13 +135,13 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
138
135
  switch (_b.label) {
139
136
  case 0:
140
137
  logger.info('rebuilding...');
141
- return [4, (0, build_1.buildDev)(args, packages)];
138
+ return [4, (0, build_1.buildDev)(args)];
142
139
  case 1:
143
140
  zpkBuffer = _b.sent();
144
141
  if (zpkBuffer) {
145
142
  logger.info('rebuild done');
146
143
  logger.info('refreshing simulator...');
147
- _a = (0, common_1.getDeviceInfoFromAppJson)(packages[0]), targetDeviceInternalName = _a.targetDeviceInternalName, appId = _a.appId, devices = _a.deviceSourceArr;
144
+ _a = (0, common_1.getDeviceInfoFromAppJson)(), targetDeviceInternalName = _a.targetDeviceInternalName, appId = _a.appId, devices = _a.deviceSourceArr;
148
145
  projectName = path.parse(process.cwd()).base;
149
146
  simulator.upload(zpkBuffer, projectName, targetDeviceInternalName, appId, devices);
150
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeppos/zeus-cli",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "zeus mini-program tools",
5
5
  "main": "index.js",
6
6
  "author": "zepp",
package/utils/common.js CHANGED
@@ -31,8 +31,6 @@ var path = __importStar(require("path"));
31
31
  var fs_1 = __importDefault(require("fs"));
32
32
  var os_1 = __importDefault(require("os"));
33
33
  var logger = __importStar(require("./logger"));
34
- var storage_1 = require("../modules/storage");
35
- var project_1 = require("../config/project");
36
34
  var device_1 = require("../config/device");
37
35
  function uint8ToArray(source) {
38
36
  return Array.prototype.slice.call(source);
@@ -58,13 +56,13 @@ function handleListenMsgEvent(msgEventName, data) {
58
56
  }
59
57
  else if (typeof data === 'object' && ((_a = data === null || data === void 0 ? void 0 : data.params) === null || _a === void 0 ? void 0 : _a.clients)) {
60
58
  var connectedDevice = getOptionalConnectDevice(data.params.clients);
61
- project_1.____inner_global_variable.bridgeOptionalDevice = JSON.stringify(connectedDevice);
59
+ process.env._bridgeOptionalDevice = JSON.stringify(connectedDevice);
62
60
  }
63
61
  break;
64
62
  case 'connectClient':
65
63
  var _d = data.result, result = _d === void 0 ? '' : _d, _e = data.error, error = _e === void 0 ? {} : _e;
66
64
  if (result && result === 'success') {
67
- var choiredDevice = project_1.____inner_global_variable.bridgeChoiredDevice;
65
+ var choiredDevice = process.env._bridgeChoiredDevice;
68
66
  logger.info("successfully connected to ".concat(choiredDevice, "."));
69
67
  }
70
68
  if (error && JSON.stringify(error) !== '{}') {
@@ -94,7 +92,9 @@ function handleListenMsgEvent(msgEventName, data) {
94
92
  }
95
93
  else if (typeof data === 'object' && (data === null || data === void 0 ? void 0 : data.params)) {
96
94
  var _j = data.params, level = _j.level, time = _j.time, message = _j.message;
97
- 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);
98
98
  logger.info(str);
99
99
  }
100
100
  break;
@@ -114,8 +114,8 @@ function handleListenMsgEvent(msgEventName, data) {
114
114
  }
115
115
  }
116
116
  exports.handleListenMsgEvent = handleListenMsgEvent;
117
- var getDeviceInfoFromAppJson = function (curTarget) {
118
- var _curTarget = curTarget ? curTarget : storage_1.globalStorage.get(project_1.buildStorageKey.targetDeviceToBuild);
117
+ var getDeviceInfoFromAppJson = function () {
118
+ var _curTarget = process.env._targetDeviceToBuild;
119
119
  var appJsonFilePath = path.resolve('./app.json');
120
120
  var appJsonContent = JSON.parse(fs_1["default"].readFileSync(appJsonFilePath, 'utf-8'));
121
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,