@zeppos/zeus-cli 1.2.3 → 1.3.0-beta.10

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/modules/build.js CHANGED
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -64,14 +75,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
64
75
  exports.__esModule = true;
65
76
  exports.buildPreview = exports.buildProd = exports.chooseBuildPackages = exports.BuildMode = void 0;
66
77
  var path = __importStar(require("path"));
78
+ var fs_1 = __importDefault(require("fs"));
67
79
  var fs_extra_1 = __importDefault(require("fs-extra"));
68
80
  var lodash_1 = require("lodash");
69
81
  var dayjs_1 = __importDefault(require("dayjs"));
70
82
  var qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
71
83
  var inquirer_1 = __importDefault(require("inquirer"));
72
84
  var zeppos_app_utils_1 = require("zeppos-app-utils");
73
- var AppType = zeppos_app_utils_1.config.AppType, OSV2Devices = zeppos_app_utils_1.config.OSV2Devices;
74
- var appJsonContent = fs_extra_1["default"].readJSONSync(path.resolve('./app.json'), { throws: false });
85
+ var tools_1 = require("../utils/tools");
86
+ var AppType = zeppos_app_utils_1.config.AppType, deviceTargets = zeppos_app_utils_1.config.deviceTargets, OSV2Devices = zeppos_app_utils_1.config.OSV2Devices;
87
+ var appJsonPath = path.resolve('./app.json');
88
+ var appJsonContent = fs_extra_1["default"].readJSONSync(appJsonPath, { throws: false });
75
89
  var BuildMode;
76
90
  (function (BuildMode) {
77
91
  BuildMode["DEV"] = "development";
@@ -83,17 +97,77 @@ var isV2ApiVersion = function (appJson) {
83
97
  var minVersionArr = minVersion.split('.');
84
98
  return parseInt("0".concat(minVersionArr[0]), 10) >= 2;
85
99
  };
86
- var chooseBuildPackages = function (mode, args) {
100
+ var checkAppJson = function () {
101
+ if (!appJsonContent) {
102
+ try {
103
+ fs_1["default"].accessSync(appJsonPath, fs_1["default"].constants.R_OK);
104
+ zeppos_app_utils_1.logger.warn('Syntax error, malformed JSON in app.json file.');
105
+ }
106
+ catch (err) {
107
+ zeppos_app_utils_1.logger.warn("This command needs to be executed in the root of the project.");
108
+ }
109
+ process.exit(1);
110
+ }
111
+ };
112
+ var chooseBuildTargetsV3Config = function (mode, args) {
113
+ if (mode === void 0) { mode = 'development'; }
114
+ return __awaiter(void 0, void 0, void 0, function () {
115
+ var apiLevel, platforms, usefulScreenTypes, usefulDeviceSource, targetDevices, deviceNames, answers;
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0:
119
+ checkAppJson();
120
+ apiLevel = (0, lodash_1.get)(appJsonContent, 'runtime.apiVersion.minVersion', '1.0.0');
121
+ platforms = Object.values((0, lodash_1.get)(appJsonContent, 'targets', {})).reduce(function (list, item) {
122
+ return list.concat((0, lodash_1.get)(item, 'platforms', []));
123
+ }, []);
124
+ usefulScreenTypes = (0, lodash_1.compact)(Object.keys((0, lodash_1.groupBy)(platforms, 'st')));
125
+ usefulDeviceSource = (0, lodash_1.compact)(Object.keys((0, lodash_1.groupBy)(platforms, 'deviceSource')));
126
+ targetDevices = {};
127
+ Object.values(deviceTargets).forEach(function (device) {
128
+ var _a;
129
+ var _b = device.apiLevelLimit || {}, min = _b.min, max = _b.max;
130
+ if (usefulScreenTypes.includes((0, lodash_1.get)(device, 'screen.type', '')) || (0, lodash_1.find)(device.platforms, function (o) { return usefulDeviceSource.includes("".concat(o.deviceSource)); })) {
131
+ if ((0, tools_1.compareVersion)(min || '1.0.0', apiLevel) >= 0 && (0, tools_1.compareVersion)(max || '99.99.99', apiLevel) < 0) {
132
+ Object.assign(targetDevices, (_a = {},
133
+ _a[device.deviceName] = device,
134
+ _a));
135
+ }
136
+ }
137
+ });
138
+ deviceNames = Object.keys(targetDevices);
139
+ if (!deviceNames.length) {
140
+ zeppos_app_utils_1.logger.error("The current project's API Level version is too high and there is no available device for debugging, please check if the version is correct.");
141
+ process.exit(1);
142
+ }
143
+ return [4, inquirer_1["default"].prompt([
144
+ {
145
+ name: 'device',
146
+ type: 'list',
147
+ message: 'Which device would you like to preview?',
148
+ choices: deviceNames
149
+ },
150
+ ])];
151
+ case 1:
152
+ answers = _a.sent();
153
+ return [2, {
154
+ sources: (0, lodash_1.get)(targetDevices, "[".concat(answers.device, "].platforms"), []).reduce(function (list, item) {
155
+ list.push(Number(item.deviceSource));
156
+ return (0, lodash_1.uniq)((0, lodash_1.compact)(list));
157
+ }, [])
158
+ }];
159
+ }
160
+ });
161
+ });
162
+ };
163
+ var chooseBuildTargetsV2Config = function (mode, args) {
87
164
  if (mode === void 0) { mode = 'development'; }
88
165
  return __awaiter(void 0, void 0, void 0, function () {
89
166
  var jsonTargets_1, unsupportedTargets_1, targets, returnRes, _a, promptTarget_1, answers;
90
167
  return __generator(this, function (_b) {
91
168
  switch (_b.label) {
92
169
  case 0:
93
- if (!appJsonContent) {
94
- zeppos_app_utils_1.logger.warn("This command needs to be executed in the root of the project.");
95
- process.exit(1);
96
- }
170
+ checkAppJson();
97
171
  if (isV2ApiVersion(appJsonContent)) {
98
172
  jsonTargets_1 = (0, lodash_1.get)(appJsonContent, 'targets', {});
99
173
  unsupportedTargets_1 = [];
@@ -106,7 +180,8 @@ var chooseBuildPackages = function (mode, args) {
106
180
  unsupportedTargets_1.push(target);
107
181
  }
108
182
  });
109
- unsupportedTargets_1.length && zeppos_app_utils_1.logger.warn("Unsupported targets(".concat(unsupportedTargets_1.join(', '), ") have been removed."));
183
+ unsupportedTargets_1.length &&
184
+ zeppos_app_utils_1.logger.warn("Unsupported targets(".concat(unsupportedTargets_1.join(', '), ") have been removed."));
110
185
  }
111
186
  targets = Object.keys((0, lodash_1.get)(appJsonContent, 'targets', {}));
112
187
  returnRes = [];
@@ -139,7 +214,9 @@ var chooseBuildPackages = function (mode, args) {
139
214
  name: 'target',
140
215
  type: 'checkbox',
141
216
  when: function (args) {
142
- var arr = typeof promptTarget_1 === 'string' ? (0, lodash_1.intersection)(targets, promptTarget_1.split(',')) : [];
217
+ var arr = typeof promptTarget_1 === 'string'
218
+ ? (0, lodash_1.intersection)(targets, promptTarget_1.split(','))
219
+ : [];
143
220
  var bool = !!arr.length;
144
221
  if (bool) {
145
222
  args.target = arr;
@@ -152,11 +229,12 @@ var chooseBuildPackages = function (mode, args) {
152
229
  checked: true
153
230
  }); }),
154
231
  message: 'Which targets would you like to build?'
155
- }
232
+ },
156
233
  ])];
157
234
  case 3:
158
235
  answers = _b.sent();
159
- returnRes = typeof answers.target === 'string' ? [answers.target] : answers.target;
236
+ returnRes =
237
+ typeof answers.target === 'string' ? [answers.target] : answers.target;
160
238
  _b.label = 4;
161
239
  case 4:
162
240
  if (!process.env._targetDeviceToBuild) {
@@ -167,18 +245,53 @@ var chooseBuildPackages = function (mode, args) {
167
245
  });
168
246
  });
169
247
  };
248
+ var chooseBuildPackages = function (mode, args) {
249
+ if (mode === void 0) { mode = 'development'; }
250
+ return __awaiter(void 0, void 0, void 0, function () {
251
+ var configVersion, result, _a, _b, _c, _d, _e, _f;
252
+ var _g;
253
+ return __generator(this, function (_h) {
254
+ switch (_h.label) {
255
+ case 0:
256
+ configVersion = (0, lodash_1.toLower)((0, lodash_1.get)(appJsonContent, 'configVersion'));
257
+ result = {};
258
+ if (!(configVersion === 'v3')) return [3, 3];
259
+ if (!(mode !== BuildMode.PROD)) return [3, 2];
260
+ _b = (_a = Object).assign;
261
+ _c = [result];
262
+ return [4, chooseBuildTargetsV3Config(mode, args)];
263
+ case 1:
264
+ _b.apply(_a, _c.concat([_h.sent()]));
265
+ _h.label = 2;
266
+ case 2: return [3, 5];
267
+ case 3:
268
+ _e = (_d = Object).assign;
269
+ _f = [result];
270
+ _g = {};
271
+ return [4, chooseBuildTargetsV2Config(mode, args)];
272
+ case 4:
273
+ _e.apply(_d, _f.concat([(_g.targets = _h.sent(),
274
+ _g)]));
275
+ _h.label = 5;
276
+ case 5: return [2, result];
277
+ }
278
+ });
279
+ });
280
+ };
170
281
  exports.chooseBuildPackages = chooseBuildPackages;
171
282
  var buildProd = function (args) { return __awaiter(void 0, void 0, void 0, function () {
172
- var packages, appId, buildInfo;
173
- return __generator(this, function (_a) {
174
- switch (_a.label) {
175
- case 0: return [4, (0, exports.chooseBuildPackages)(BuildMode.PROD, args)];
283
+ var _a, _b, _c, buildInfo;
284
+ return __generator(this, function (_d) {
285
+ switch (_d.label) {
286
+ case 0:
287
+ _b = (_a = Object).assign;
288
+ _c = [args];
289
+ return [4, (0, exports.chooseBuildPackages)(BuildMode.PROD, args)];
176
290
  case 1:
177
- packages = _a.sent();
178
- appId = (0, lodash_1.get)(appJsonContent, 'app.appId');
179
- return [4, zeppos_app_utils_1.modules.build(path.resolve('./'), BuildMode.PROD, args, packages, appId)];
291
+ _b.apply(_a, _c.concat([_d.sent()]));
292
+ return [4, zeppos_app_utils_1.modules.buildSupportV3Config(path.resolve('./'), BuildMode.PROD, __assign(__assign({}, args), { renameWithAppId: (0, lodash_1.get)(appJsonContent, 'app.appId') }))];
180
293
  case 2:
181
- buildInfo = _a.sent();
294
+ buildInfo = _d.sent();
182
295
  if (buildInfo) {
183
296
  (0, zeppos_app_utils_1.HM_Analytics)('ZEPP_CLI_BUILD_C', { res: '1' });
184
297
  }
@@ -191,30 +304,37 @@ var buildProd = function (args) { return __awaiter(void 0, void 0, void 0, funct
191
304
  }); };
192
305
  exports.buildProd = buildProd;
193
306
  var buildPreview = function (args, callback) { return __awaiter(void 0, void 0, void 0, function () {
194
- var _a, curCommand, curBridgeTarget, buildMode, appType, appId, packages, buildInfo;
195
- return __generator(this, function (_b) {
196
- switch (_b.label) {
307
+ var _a, curCommand, curBridgeTarget, buildMode, appType, _b, _c, _d, buildInfo;
308
+ return __generator(this, function (_e) {
309
+ switch (_e.label) {
197
310
  case 0:
198
311
  _a = args._, curCommand = _a[0], curBridgeTarget = _a[1];
199
- buildMode = (curBridgeTarget && curBridgeTarget === 'simulator') ? BuildMode.DEV : BuildMode.PREVIEW;
312
+ buildMode = curBridgeTarget && curBridgeTarget === 'simulator'
313
+ ? BuildMode.DEV
314
+ : BuildMode.PREVIEW;
200
315
  zeppos_app_utils_1.logger.info('building...');
201
316
  appType = (0, lodash_1.get)(appJsonContent, 'app.appType');
202
- appId = (0, lodash_1.get)(appJsonContent, 'app.appId');
203
- return [4, (0, exports.chooseBuildPackages)(buildMode, args)];
317
+ _c = (_b = Object).assign;
318
+ _d = [args];
319
+ return [4, (0, exports.chooseBuildPackages)(BuildMode.PREVIEW, args)];
204
320
  case 1:
205
- packages = _b.sent();
206
- return [4, zeppos_app_utils_1.modules.build(path.resolve('./'), buildMode, args, packages, appId)];
321
+ _c.apply(_b, _d.concat([_e.sent()]));
322
+ return [4, zeppos_app_utils_1.modules.buildSupportV3Config(path.resolve('./'), buildMode, __assign(__assign({}, args), { renameWithAppId: (0, lodash_1.get)(appJsonContent, 'app.appId') }))];
207
323
  case 2:
208
- buildInfo = _b.sent();
324
+ buildInfo = _e.sent();
209
325
  zeppos_app_utils_1.logger.info('getting package...');
210
- return [4, zeppos_app_utils_1.modules.previewBuild(path.resolve('./'), args, "./dist/".concat(buildInfo), appType, curCommand).then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
326
+ return [4, zeppos_app_utils_1.modules
327
+ .previewBuild(path.resolve('./'), args, "./dist/".concat(buildInfo), appType, curCommand)
328
+ .then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
211
329
  return __generator(this, function (_a) {
212
330
  switch (_a.label) {
213
331
  case 0:
214
332
  if (!(res.type === 'preview')) return [3, 1];
215
333
  zeppos_app_utils_1.logger.info('Generating preview QR code...');
216
334
  zeppos_app_utils_1.logger.success("Please use Zepp APP to scan the following QR code to preview your ".concat(appType === AppType.WATCHFACE ? 'WatchFace' : 'application', "."));
217
- zeppos_app_utils_1.logger.success("The QR code will expire on ".concat((0, dayjs_1["default"])().add(2, 'hour').format('YYYY-MM-DD HH:mm:ss'), "."));
335
+ zeppos_app_utils_1.logger.success("The QR code will expire on ".concat((0, dayjs_1["default"])()
336
+ .add(2, 'hour')
337
+ .format('YYYY-MM-DD HH:mm:ss'), "."));
218
338
  qrcode_terminal_1["default"].generate(res.url, { small: true });
219
339
  callback && callback(res);
220
340
  return [3, 4];
@@ -234,7 +354,7 @@ var buildPreview = function (args, callback) { return __awaiter(void 0, void 0,
234
354
  zeppos_app_utils_1.logger.error('Generating preview qrcode failed, please check your network.');
235
355
  })];
236
356
  case 3:
237
- _b.sent();
357
+ _e.sent();
238
358
  return [2];
239
359
  }
240
360
  });
package/modules/create.js CHANGED
@@ -57,11 +57,11 @@ var AppType = zeppos_app_utils_1.config.AppType, deviceTargets = zeppos_app_util
57
57
  var inquirerFunc = function (args, _a) {
58
58
  var appTemplateChoices = _a.appTemplateChoices, watchfaceTemplateChoices = _a.watchfaceTemplateChoices;
59
59
  return __awaiter(void 0, void 0, void 0, function () {
60
- var _b, promptAppType, _c, promptOsVersion, _d, promptTemplate, _e, promptWithAppSide, _f, promptWithSettings, _g, promptBuildTargets;
61
- return __generator(this, function (_h) {
62
- switch (_h.label) {
60
+ var _b, promptAppType, _c, promptOsVersion, _d, promptTemplate, _e, promptWithAppSide, _f, promptWithSettings, _g, promptBuildTargets, _h, configVersion;
61
+ return __generator(this, function (_j) {
62
+ switch (_j.label) {
63
63
  case 0:
64
- _b = args.appType, promptAppType = _b === void 0 ? '' : _b, _c = args.OSVersion, promptOsVersion = _c === void 0 ? '' : _c, _d = args.template, promptTemplate = _d === void 0 ? '' : _d, _e = args.withAppSide, promptWithAppSide = _e === void 0 ? false : _e, _f = args.withSettings, promptWithSettings = _f === void 0 ? false : _f, _g = args.buildTargets, promptBuildTargets = _g === void 0 ? [] : _g;
64
+ _b = args.appType, promptAppType = _b === void 0 ? '' : _b, _c = args.OSVersion, promptOsVersion = _c === void 0 ? '' : _c, _d = args.template, promptTemplate = _d === void 0 ? '' : _d, _e = args.withAppSide, promptWithAppSide = _e === void 0 ? false : _e, _f = args.withSettings, promptWithSettings = _f === void 0 ? false : _f, _g = args.buildTargets, promptBuildTargets = _g === void 0 ? [] : _g, _h = args.configVersion, configVersion = _h === void 0 ? 'v2' : _h;
65
65
  return [4, inquirer_1["default"].prompt([
66
66
  {
67
67
  name: 'appType',
@@ -180,6 +180,7 @@ var inquirerFunc = function (args, _a) {
180
180
  args.buildTargets = (0, lodash_1.intersection)(Object.keys(deviceTargets), promptBuildTargets.split(','));
181
181
  return [3, 3];
182
182
  case 1:
183
+ if (!(configVersion !== 'v3')) return [3, 3];
183
184
  choicePlatforms_1 = [];
184
185
  switch (args.OSVersion) {
185
186
  case 'v1':
@@ -212,7 +213,7 @@ var inquirerFunc = function (args, _a) {
212
213
  }
213
214
  });
214
215
  }); })];
215
- case 1: return [2, _h.sent()];
216
+ case 1: return [2, _j.sent()];
216
217
  }
217
218
  });
218
219
  });
package/modules/run.js CHANGED
@@ -69,10 +69,10 @@ var path = __importStar(require("path"));
69
69
  var zeppos_app_utils_1 = require("zeppos-app-utils");
70
70
  var DEFAULT_HOST = zeppos_app_utils_1.config.DEFAULT_HOST, DEFAULT_PORT = zeppos_app_utils_1.config.DEFAULT_PORT, simulatorStorageKey = zeppos_app_utils_1.config.simulatorStorageKey;
71
71
  var run = function (args) { return __awaiter(void 0, void 0, void 0, function () {
72
- var simulatorHost, simulatorPort, _a, promptSimulatorHost, _b, promptSimulatorPort, answer, packages, simulatorWebSocketURL, root;
73
- var _c;
74
- return __generator(this, function (_d) {
75
- switch (_d.label) {
72
+ var simulatorHost, simulatorPort, _a, promptSimulatorHost, _b, promptSimulatorPort, answer, _c, _d, _e, simulatorWebSocketURL, root;
73
+ var _f;
74
+ return __generator(this, function (_g) {
75
+ switch (_g.label) {
76
76
  case 0:
77
77
  simulatorHost = '';
78
78
  simulatorPort = '';
@@ -108,22 +108,24 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
108
108
  }
109
109
  ])];
110
110
  case 1:
111
- answer = _d.sent();
111
+ answer = _g.sent();
112
112
  if (!simulatorHost) {
113
113
  simulatorHost = answer.host || DEFAULT_HOST;
114
114
  simulatorPort = answer.port || DEFAULT_PORT;
115
- zeppos_app_utils_1.globalStorage.set((_c = {},
116
- _c[simulatorStorageKey.simulatorHost] = answer.host || DEFAULT_HOST,
117
- _c[simulatorStorageKey.simulatorPort] = answer.port || DEFAULT_PORT,
118
- _c));
115
+ zeppos_app_utils_1.globalStorage.set((_f = {},
116
+ _f[simulatorStorageKey.simulatorHost] = answer.host || DEFAULT_HOST,
117
+ _f[simulatorStorageKey.simulatorPort] = answer.port || DEFAULT_PORT,
118
+ _f));
119
119
  }
120
120
  (0, zeppos_app_utils_1.HM_Analytics)('ZEPP_CLI_DEV_C');
121
+ _d = (_c = Object).assign;
122
+ _e = [args];
121
123
  return [4, (0, build_1.chooseBuildPackages)(build_1.BuildMode.DEV, args)];
122
124
  case 2:
123
- packages = _d.sent();
125
+ _d.apply(_c, _e.concat([_g.sent()]));
124
126
  simulatorWebSocketURL = "http://".concat(simulatorHost, ":").concat(simulatorPort);
125
127
  root = path.resolve('./');
126
- zeppos_app_utils_1.modules.runX(root, args, simulatorWebSocketURL, packages);
128
+ zeppos_app_utils_1.modules.runX(root, args, simulatorWebSocketURL);
127
129
  return [2];
128
130
  }
129
131
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeppos/zeus-cli",
3
- "version": "1.2.3",
3
+ "version": "1.3.0-beta.10",
4
4
  "description": "zeus mini-program tools",
5
5
  "main": "index.ts",
6
6
  "author": "zepp",
@@ -21,7 +21,7 @@
21
21
  "qrcode-terminal": "^0.12.0",
22
22
  "vorpal": "^1.12.0",
23
23
  "yargs": "^17.5.1",
24
- "@zeppos/zpm": "^2.6.6",
24
+ "@zeppos/zpm": "^2.9.24-beta",
25
25
  "axios": "^0.27.2",
26
26
  "chalk": "^4.1.2",
27
27
  "chokidar": "^3.5.3",