@zeppos/zeus-cli 1.3.6 → 1.3.8

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.
Files changed (42) hide show
  1. package/bin/main.js +8 -8
  2. package/bin/post-command.js +1 -1
  3. package/modules/build.js +5 -3
  4. package/modules/create.js +6 -5
  5. package/package.json +2 -2
  6. package/private-modules/zeppos-app-utils/dist/config/device.js +105 -45
  7. package/private-modules/zeppos-app-utils/dist/config/project.js +1 -1
  8. package/private-modules/zeppos-app-utils/dist/modules/create/local-app.js +3 -2
  9. package/private-modules/zeppos-app-utils/dist/modules/fetchDevices.js +89 -0
  10. package/private-modules/zeppos-app-utils/dist/modules/index.js +1 -0
  11. package/private-modules/zeppos-app-utils/dist/public/template/os1.0/app/fetch-api/app-side/index.js +6 -18
  12. package/private-modules/zeppos-app-utils/dist/public/template/os1.0/app/fetch-api/pages/index.js +6 -6
  13. package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/app-side/index.js +6 -18
  14. package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/pages/index.js +6 -6
  15. package/private-modules/zeppos-app-utils/dist/public/template/os3.0/app/fetch-api/app-side/index.js +7 -35
  16. package/private-modules/zeppos-app-utils/dist/public/template/os3.0/app/fetch-api/page/index.js +1 -1
  17. package/private-modules/zeppos-app-utils/dist/public/template/os3.0/app/fetch-api/page/index.r.layout.js +8 -8
  18. package/private-modules/zeppos-app-utils/dist/public/template/os3.0/app/fetch-api/page/index.s.layout.js +1 -1
  19. package/private-modules/zeppos-app-utils/dist/tools/index.js +2 -1
  20. package/private-modules/zeppos-app-utils/package.json +1 -1
  21. package/private-modules/zeppos-app-utils/dist/config/device-server.js +0 -116
  22. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/.prettierrc.js +0 -0
  23. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/app-side/index.js +0 -0
  24. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/app.js +0 -0
  25. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/app.json +0 -0
  26. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/assets/gts/icon.png +0 -0
  27. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/page/home/index.page.js +0 -0
  28. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/page/home/index.page.json +0 -0
  29. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/page/home/index.style.js +0 -0
  30. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/page/i18n/en-US.po +0 -0
  31. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/secondary-widget/index.js +0 -0
  32. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/setting/i18n/en-US.po +0 -0
  33. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/setting/index.js +0 -0
  34. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/shared/data.js +0 -0
  35. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/shared/defer.js +0 -0
  36. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/shared/device-polyfill.js +0 -0
  37. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/shared/es6-promise.js +0 -0
  38. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/shared/event.js +0 -0
  39. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/shared/message-side.js +0 -0
  40. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/shared/message.js +0 -0
  41. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/utils/constants.js +0 -0
  42. /package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/{fetch-api/todo-list → todo-list}/utils/index.js +0 -0
package/bin/main.js CHANGED
@@ -49,7 +49,7 @@ var argv = hideBin(process.argv);
49
49
  var pre_check_1 = require("../utils/pre-check");
50
50
  var index_1 = require("../index");
51
51
  var zeppos_app_utils_1 = require("zeppos-app-utils");
52
- var login = zeppos_app_utils_1.modules.login, logout = zeppos_app_utils_1.modules.logout, status = zeppos_app_utils_1.modules.status, modulesConfig = zeppos_app_utils_1.modules.config;
52
+ var login = zeppos_app_utils_1.modules.login, logout = zeppos_app_utils_1.modules.logout, status = zeppos_app_utils_1.modules.status, modulesConfig = zeppos_app_utils_1.modules.config, fetchDevicesWrap = zeppos_app_utils_1.modules.fetchDevicesWrap;
53
53
  var context = {};
54
54
  var yargsCmdBuilderFunc = function (cmdName, useProxy, yargs) {
55
55
  if (useProxy === void 0) { useProxy = false; }
@@ -84,15 +84,15 @@ yargs_1["default"].usage("Usage: ".concat(process.env.CMD_NAME, " <command> [arg
84
84
  .alias('h', 'help').describe('help', 'Display help information.')
85
85
  .alias('v', 'version').describe('version', 'Display version number.')
86
86
  .group(['help', 'version'], "Base Options")
87
- .command('init', 'Init a new project in current directory.', proxy, index_1.create)
88
- .command('create <projectName>', 'Named the <projectName> project and add to the current directory.', proxy, index_1.create)
87
+ .command('init', 'Init a new project in current directory.', proxy, fetchDevicesWrap(index_1.create))
88
+ .command('create <projectName>', 'Named the <projectName> project and add to the current directory.', proxy, fetchDevicesWrap(index_1.create))
89
89
  .command('login', 'Login to your account.', proxy, login)
90
90
  .command('logout', 'Sign out of your account.', proxy, logout)
91
- .command('dev', 'Run this project in development mode. Use "zeus dev -h" to see more information', yargsCmdBuilderFunc.bind(null, 'dev', true), index_1.run)
92
- .command('preview', 'Preview this project in your device.', proxy, index_1.buildPreview)
93
- .command('build', 'Build this project for production.', proxy, index_1.buildProd)
91
+ .command('dev', 'Run this project in development mode. Use "zeus dev -h" to see more information', yargsCmdBuilderFunc.bind(null, 'dev', true), fetchDevicesWrap(index_1.run))
92
+ .command('preview', 'Preview this project in your device.', proxy, fetchDevicesWrap(index_1.buildPreview))
93
+ .command('build', 'Build this project for production.', proxy, fetchDevicesWrap(index_1.buildProd))
94
94
  .command('status', 'View information such as login and emulator connection status.', proxy, status)
95
- .command('bridge', "Connect the online App or Simulator for development and debugging.", proxy, index_1.bridge)
96
- .command('config', "Operation config value.\n e.g.\n set <key>=<value> [<key>=<value> ...]\n get <key> [<key> ...]\n delete <key> [<key> ...]\n list [--json]", proxy, modulesConfig)
95
+ .command('bridge', "Connect the online App or Simulator for development and debugging.", proxy, fetchDevicesWrap(index_1.bridge))
96
+ .command('config', "Operation config value.\n e.g.\n set <key>=<value> [<key>=<value> ...]\n get <key> [<key> ...]\n delete <key> [<key> ...]\n list [--json]", proxy, fetchDevicesWrap(modulesConfig))
97
97
  .epilogue('For more information, see https://docs.zepp.com/')
98
98
  .parse(argv, context);
@@ -3,4 +3,4 @@ exports.__esModule = true;
3
3
  var zeppos_app_utils_1 = require("zeppos-app-utils");
4
4
  var bin = require('../package.json').bin;
5
5
  process.env.CMD_NAME = Object.keys(bin || {})[0] || 'zeus';
6
- process.env.ACCOUNT_ENV = zeppos_app_utils_1.globalStorage.get('account_env') || 'production';
6
+ process.env.ACCOUNT_ENV = zeppos_app_utils_1.globalStorage.get('account_env') === 'test' ? 'test' : 'production';
package/modules/build.js CHANGED
@@ -83,7 +83,7 @@ var qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
83
83
  var inquirer_1 = __importDefault(require("inquirer"));
84
84
  var zeppos_app_utils_1 = require("zeppos-app-utils");
85
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;
86
+ var AppType = zeppos_app_utils_1.config.AppType, getDeviceConf = zeppos_app_utils_1.config.getDeviceConf;
87
87
  var appJsonPath = path.resolve('./app.json');
88
88
  var appJsonContent = fs_extra_1["default"].readJSONSync(appJsonPath, { throws: false });
89
89
  var BuildMode;
@@ -112,12 +112,13 @@ var checkAppJson = function () {
112
112
  var chooseBuildTargetsV3Config = function (mode, args) {
113
113
  if (mode === void 0) { mode = 'development'; }
114
114
  return __awaiter(void 0, void 0, void 0, function () {
115
- var target, apiLevel, platforms, usefulScreenTypes, usefulDeviceSource, targetDevices, deviceNames, isValidDevice, answers, _a;
115
+ var target, deviceTargets, apiLevel, platforms, usefulScreenTypes, usefulDeviceSource, targetDevices, deviceNames, isValidDevice, answers, _a;
116
116
  return __generator(this, function (_b) {
117
117
  switch (_b.label) {
118
118
  case 0:
119
119
  checkAppJson();
120
120
  target = args.target;
121
+ deviceTargets = getDeviceConf().deviceTargets;
121
122
  apiLevel = (0, lodash_1.get)(appJsonContent, 'runtime.apiVersion.minVersion', '1.0.0');
122
123
  platforms = Object.values((0, lodash_1.get)(appJsonContent, 'targets', {})).reduce(function (list, item) {
123
124
  return list.concat((0, lodash_1.get)(item, 'platforms', []));
@@ -174,11 +175,12 @@ var chooseBuildTargetsV3Config = function (mode, args) {
174
175
  var chooseBuildTargetsV2Config = function (mode, args) {
175
176
  if (mode === void 0) { mode = 'development'; }
176
177
  return __awaiter(void 0, void 0, void 0, function () {
177
- var jsonTargets_1, unsupportedTargets_1, targets, returnRes, _a, promptTarget_1, answers;
178
+ var OSV2Devices, jsonTargets_1, unsupportedTargets_1, targets, returnRes, _a, promptTarget_1, answers;
178
179
  return __generator(this, function (_b) {
179
180
  switch (_b.label) {
180
181
  case 0:
181
182
  checkAppJson();
183
+ OSV2Devices = getDeviceConf().OSV2Devices;
182
184
  if (isV2ApiVersion(appJsonContent)) {
183
185
  jsonTargets_1 = (0, lodash_1.get)(appJsonContent, 'targets', {});
184
186
  unsupportedTargets_1 = [];
package/modules/create.js CHANGED
@@ -53,15 +53,16 @@ var lodash_1 = require("lodash");
53
53
  var inquirer_1 = __importDefault(require("inquirer"));
54
54
  var path_1 = require("path");
55
55
  var zeppos_app_utils_1 = require("zeppos-app-utils");
56
- var AppType = zeppos_app_utils_1.config.AppType, deviceTargets = zeppos_app_utils_1.config.deviceTargets, OSV2DeviceTargetNames = zeppos_app_utils_1.config.OSV2DeviceTargetNames;
56
+ var AppType = zeppos_app_utils_1.config.AppType, getDeviceConf = zeppos_app_utils_1.config.getDeviceConf;
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, _h, configVersion;
61
- return __generator(this, function (_j) {
62
- switch (_j.label) {
60
+ var _b, promptAppType, _c, promptOsVersion, _d, promptTemplate, _e, promptWithAppSide, _f, promptWithSettings, _g, promptBuildTargets, _h, configVersion, _j, deviceTargets, OSV2DeviceTargetNames;
61
+ return __generator(this, function (_k) {
62
+ switch (_k.label) {
63
63
  case 0:
64
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
+ _j = getDeviceConf(), deviceTargets = _j.deviceTargets, OSV2DeviceTargetNames = _j.OSV2DeviceTargetNames;
65
66
  return [4, inquirer_1["default"].prompt([
66
67
  {
67
68
  name: 'appType',
@@ -241,7 +242,7 @@ var inquirerFunc = function (args, _a) {
241
242
  }
242
243
  });
243
244
  }); })];
244
- case 1: return [2, _j.sent()];
245
+ case 1: return [2, _k.sent()];
245
246
  }
246
247
  });
247
248
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeppos/zeus-cli",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
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": "^3.0.1",
24
+ "@zeppos/zpm": "^3.0.3",
25
25
  "axios": "^0.27.2",
26
26
  "chalk": "^4.1.2",
27
27
  "chokidar": "^3.5.3",
@@ -1,62 +1,122 @@
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
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  exports.__esModule = true;
17
- exports.deviceInternalCodeName = exports.OSV2DeviceTargetNames = exports.OSV2Devices = exports.deviceTargets = exports.DeviceScreenType = void 0;
6
+ exports.getDeviceConf = exports.DeviceScreenType = void 0;
18
7
  var lodash_1 = require("lodash");
19
- var device_server_1 = __importDefault(require("./device-server"));
8
+ var path_1 = __importDefault(require("path"));
9
+ var os_1 = __importDefault(require("os"));
10
+ var fs_1 = __importDefault(require("fs"));
11
+ var fs_extra_1 = __importDefault(require("fs-extra"));
20
12
  var tools_1 = require("../tools/tools");
13
+ var LOCAL_CACHE_DEVICE_PATH = path_1["default"].resolve(os_1["default"].homedir(), ".zepp/.zeus_devices");
21
14
  var DeviceScreenType;
22
15
  (function (DeviceScreenType) {
23
16
  DeviceScreenType["R"] = "r";
24
17
  DeviceScreenType["S"] = "s";
25
18
  DeviceScreenType["B"] = "b";
26
19
  })(DeviceScreenType = exports.DeviceScreenType || (exports.DeviceScreenType = {}));
27
- exports.deviceTargets = __assign({}, device_server_1["default"]);
28
- exports.OSV2Devices = Object.values(exports.deviceTargets).reduce(function (targetDevices, target) {
29
- var _a = target.platforms, platforms = _a === void 0 ? [] : _a, _b = target.apiLevelLimit, apiLevelLimit = _b === void 0 ? {} : _b;
30
- var min = apiLevelLimit.min, max = apiLevelLimit.max;
31
- if (!(0, lodash_1.isEmpty)(platforms) &&
32
- (0, tools_1.compareVersion)(min || '1.0.0', '2.0.0') >= 0 &&
33
- max && (0, tools_1.compareVersion)(max, '2.0.0') <= 0) {
34
- targetDevices.push.apply(targetDevices, platforms.reduce(function (list, o) { return (0, lodash_1.compact)(list.concat([o.deviceSource])); }, []));
20
+ var shapeMap = {
21
+ square: DeviceScreenType.S,
22
+ round: DeviceScreenType.R,
23
+ bar: DeviceScreenType.B
24
+ };
25
+ function getDeviceInfo() {
26
+ var localContent = {};
27
+ if (fs_1["default"].existsSync(LOCAL_CACHE_DEVICE_PATH)) {
28
+ try {
29
+ localContent = fs_extra_1["default"].readJsonSync(LOCAL_CACHE_DEVICE_PATH);
30
+ }
31
+ catch (_e) { }
35
32
  }
36
- return targetDevices;
37
- }, []);
38
- exports.OSV2DeviceTargetNames = Object.keys(exports.deviceTargets).reduce(function (targetNames, target) {
39
- var flag = true;
40
- var _a = exports.deviceTargets[target].platforms, platforms = _a === void 0 ? [] : _a;
41
- if (platforms && platforms.length) {
33
+ var deviceList = (0, lodash_1.get)(localContent, 'devices', []);
34
+ var deviceGroup = (0, lodash_1.groupBy)(deviceList, 'productName');
35
+ var deviceInfo = {};
36
+ Object.values(deviceGroup).forEach(function (devices) {
37
+ var _a;
38
+ var info = {
39
+ deviceName: '',
40
+ platforms: [],
41
+ screen: {
42
+ type: DeviceScreenType.R,
43
+ width: 0,
44
+ height: 0
45
+ },
46
+ apiLevelLimit: {
47
+ min: '1.0.0'
48
+ }
49
+ };
50
+ var deviceInnerName = devices.reduce(function (acc, cur) {
51
+ !info.deviceName && (info.deviceName = cur.productName);
52
+ var screenType = (0, lodash_1.get)(shapeMap, (0, lodash_1.get)(cur, 'value.shape'));
53
+ var _a = (0, lodash_1.get)(cur, 'value.screen.size', '').split('*'), width = _a[0], height = _a[1];
54
+ if (screenType) {
55
+ info.screen.type = screenType;
56
+ }
57
+ if (width && height) {
58
+ info.screen.width = Number(width);
59
+ info.screen.height = Number(height);
60
+ }
61
+ info.platforms.push({
62
+ name: cur.code,
63
+ deviceSource: cur.deviceSource
64
+ });
65
+ Object.assign(info.apiLevelLimit, {
66
+ min: (0, lodash_1.get)(cur, 'value.os.apiLevelLimitMin', '1.0.0'),
67
+ max: (0, lodash_1.get)(cur, 'value.os.version', '')
68
+ });
69
+ return cur.code.length < acc.length ? cur.code : acc;
70
+ }, devices[0].code);
71
+ var lowerName = (0, lodash_1.toLower)(deviceInnerName.replace(/[^a-zA-Z]/g, ''));
72
+ lowerName && Object.assign(deviceInfo, (_a = {},
73
+ _a[lowerName] = info,
74
+ _a));
75
+ });
76
+ return deviceInfo;
77
+ }
78
+ var getDeviceConf = function () {
79
+ var deviceTargets = getDeviceInfo();
80
+ var OSV2Devices = Object.values(deviceTargets).reduce(function (targetDevices, target) {
81
+ var _a = target.platforms, platforms = _a === void 0 ? [] : _a, _b = target.apiLevelLimit, apiLevelLimit = _b === void 0 ? {} : _b;
82
+ var min = apiLevelLimit.min, max = apiLevelLimit.max;
83
+ if (!(0, lodash_1.isEmpty)(platforms) &&
84
+ (0, tools_1.compareVersion)(min || '1.0.0', '2.0.0') >= 0 &&
85
+ max && (0, tools_1.compareVersion)(max, '2.0.0') <= 0) {
86
+ targetDevices.push.apply(targetDevices, platforms.reduce(function (list, o) { return (0, lodash_1.compact)(list.concat([o.deviceSource])); }, []));
87
+ }
88
+ return targetDevices;
89
+ }, []);
90
+ var OSV2DeviceTargetNames = Object.keys(deviceTargets).reduce(function (targetNames, target) {
91
+ var flag = true;
92
+ var _a = deviceTargets[target].platforms, platforms = _a === void 0 ? [] : _a;
93
+ if (platforms && platforms.length) {
94
+ platforms.forEach(function (_a) {
95
+ var deviceSource = _a.deviceSource;
96
+ if (!OSV2Devices.includes(deviceSource)) {
97
+ flag = false;
98
+ }
99
+ });
100
+ }
101
+ else {
102
+ flag = false;
103
+ }
104
+ flag && targetNames.push(target);
105
+ return targetNames;
106
+ }, []);
107
+ var deviceInternalCodeName = Object.keys(deviceTargets).reduce(function (deviceSources, target) {
108
+ var _a = deviceTargets[target].platforms, platforms = _a === void 0 ? [] : _a;
42
109
  platforms.forEach(function (_a) {
43
110
  var deviceSource = _a.deviceSource;
44
- if (!exports.OSV2Devices.includes(deviceSource)) {
45
- flag = false;
46
- }
111
+ deviceSource && (deviceSources[deviceSource] = target);
47
112
  });
48
- }
49
- else {
50
- flag = false;
51
- }
52
- flag && targetNames.push(target);
53
- return targetNames;
54
- }, []);
55
- exports.deviceInternalCodeName = Object.keys(exports.deviceTargets).reduce(function (deviceSources, target) {
56
- var _a = exports.deviceTargets[target].platforms, platforms = _a === void 0 ? [] : _a;
57
- platforms.forEach(function (_a) {
58
- var deviceSource = _a.deviceSource;
59
- deviceSource && (deviceSources[deviceSource] = target);
60
- });
61
- return deviceSources;
62
- }, {});
113
+ return deviceSources;
114
+ }, {});
115
+ return {
116
+ deviceTargets: deviceTargets,
117
+ OSV2Devices: OSV2Devices,
118
+ OSV2DeviceTargetNames: OSV2DeviceTargetNames,
119
+ deviceInternalCodeName: deviceInternalCodeName
120
+ };
121
+ };
122
+ exports.getDeviceConf = getDeviceConf;
@@ -71,7 +71,7 @@ var getLocalStorage = function () {
71
71
  exports.getLocalStorage = getLocalStorage;
72
72
  var getLocalConfig = function () {
73
73
  var zeusStorageInfo = (0, exports.getLocalStorage)();
74
- var account_env = zeusStorageInfo.account_env || 'production';
74
+ var account_env = zeusStorageInfo.account_env === 'test' ? 'test' : 'production';
75
75
  var LOGIN_URL = new URL(getLoginURL[account_env]);
76
76
  var ANALYTICS_HOST = getAnalyticsHost[account_env];
77
77
  var accountPrefix = "____".concat(LOGIN_URL.host.replace(/\./g, '_'), "__");
@@ -57,11 +57,12 @@ var path_1 = require("path");
57
57
  var fs_1 = __importDefault(require("fs"));
58
58
  var fs_extra_1 = __importDefault(require("fs-extra"));
59
59
  var index_1 = require("../../index");
60
- var TemplateCopyType = index_1.config.TemplateCopyType, deviceTargets = index_1.config.deviceTargets;
60
+ var TemplateCopyType = index_1.config.TemplateCopyType, getDeviceConf = index_1.config.getDeviceConf;
61
61
  var createLocalApp = function (args) { return __awaiter(void 0, void 0, void 0, function () {
62
- var workDir, templateInfo, withAppSide, withSettings, buildTargets, appType, shapeOfPlatform, appJsonPath, appJson, appID, defaultTarget, targets, shapes, needDelShapeConfig, defaultAssetsPath_1;
62
+ var workDir, templateInfo, withAppSide, withSettings, buildTargets, appType, shapeOfPlatform, deviceTargets, appJsonPath, appJson, appID, defaultTarget, targets, shapes, needDelShapeConfig, defaultAssetsPath_1;
63
63
  return __generator(this, function (_a) {
64
64
  workDir = args.workDir, templateInfo = args.templateInfo, withAppSide = args.withAppSide, withSettings = args.withSettings, buildTargets = args.buildTargets, appType = args.appType, shapeOfPlatform = args.shapeOfPlatform;
65
+ deviceTargets = getDeviceConf().deviceTargets;
65
66
  fs_extra_1["default"].copySync(templateInfo.path, workDir);
66
67
  if (fs_extra_1["default"].existsSync((0, path_1.resolve)(workDir, "./_package.json"))) {
67
68
  fs_1["default"].renameSync((0, path_1.resolve)(workDir, "./_package.json"), (0, path_1.resolve)(workDir, "./package.json"));
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ exports.__esModule = true;
29
+ exports.fetchDevicesWrap = exports.fetchDevices = exports.DeviceScreenType = void 0;
30
+ var axios_1 = __importDefault(require("axios"));
31
+ var os = __importStar(require("os"));
32
+ var path = __importStar(require("path"));
33
+ var fs = __importStar(require("fs"));
34
+ var fs_extra_1 = __importDefault(require("fs-extra"));
35
+ var lodash_1 = require("lodash");
36
+ var config_1 = require("../config");
37
+ var accountEnv = (0, config_1.getLocalConfig)().account_env;
38
+ var LOCAL_CACHE_DEVICE_PATH = path.resolve(os.homedir(), ".zepp/.zeus_devices");
39
+ var serverPath = accountEnv === 'test' ? 'https://upload-testing-cdn.huami.com/zeppos/devkit/zeus/devices.json' : 'https://upload-cdn.zepp.com/zeppos/devkit/zeus/devices.json';
40
+ var DeviceScreenType;
41
+ (function (DeviceScreenType) {
42
+ DeviceScreenType["R"] = "r";
43
+ DeviceScreenType["S"] = "s";
44
+ DeviceScreenType["B"] = "b";
45
+ })(DeviceScreenType = exports.DeviceScreenType || (exports.DeviceScreenType = {}));
46
+ var fetchDevices = function () {
47
+ var localContent = {};
48
+ if (fs.existsSync(LOCAL_CACHE_DEVICE_PATH)) {
49
+ try {
50
+ localContent = fs_extra_1["default"].readJsonSync(LOCAL_CACHE_DEVICE_PATH);
51
+ }
52
+ catch (_e) { }
53
+ }
54
+ var now = Date.now().valueOf();
55
+ return new Promise(function (resolve) {
56
+ if (!((0, lodash_1.get)(localContent, 'expiredTime') > now)) {
57
+ axios_1["default"].get(serverPath).then(function (res) {
58
+ if (res.status === 200) {
59
+ var data = res.data;
60
+ if (!(0, lodash_1.isEmpty)(data)) {
61
+ fs_extra_1["default"].writeJsonSync(LOCAL_CACHE_DEVICE_PATH, {
62
+ devices: data,
63
+ expiredTime: now + 2 * 60 * 60 * 1000
64
+ });
65
+ resolve({});
66
+ }
67
+ }
68
+ })["catch"](function (e) {
69
+ console.log(e);
70
+ resolve({});
71
+ process.exit(1);
72
+ });
73
+ }
74
+ else {
75
+ resolve({});
76
+ }
77
+ });
78
+ };
79
+ exports.fetchDevices = fetchDevices;
80
+ var fetchDevicesWrap = function (func) {
81
+ return function () {
82
+ var args = [];
83
+ for (var _i = 0; _i < arguments.length; _i++) {
84
+ args[_i] = arguments[_i];
85
+ }
86
+ return (0, exports.fetchDevices)().then(function () { return func.apply(void 0, args); });
87
+ };
88
+ };
89
+ exports.fetchDevicesWrap = fetchDevicesWrap;
@@ -18,4 +18,5 @@ __exportStar(require("./login"), exports);
18
18
  __exportStar(require("./config"), exports);
19
19
  __exportStar(require("./status"), exports);
20
20
  __exportStar(require("./build"), exports);
21
+ __exportStar(require("./fetchDevices"), exports);
21
22
  __exportStar(require("./create/index"), exports);
@@ -2,21 +2,6 @@ import { MessageBuilder } from "../shared/message";
2
2
 
3
3
  const messageBuilder = new MessageBuilder();
4
4
 
5
- // Simulating an asynchronous network request using Promise
6
- async function mockAPI() {
7
- return new Promise((resolve, reject) => {
8
- setTimeout(() => {
9
- resolve({
10
- body: {
11
- data: {
12
- text: "HELLO ZEPPOS",
13
- },
14
- },
15
- });
16
- }, 1000);
17
- });
18
- };
19
-
20
5
  async function fetchData(ctx) {
21
6
  try {
22
7
  // Requesting network data using the fetch API
@@ -38,12 +23,15 @@ async function fetchData(ctx) {
38
23
  // })
39
24
  // })
40
25
 
41
- // A network request is simulated here
42
- const res = await mockAPI()
26
+ // A network request is simulated here, Reference documentation: https://jsonplaceholder.typicode.com/
27
+ const res = await fetch({
28
+ url: 'https://jsonplaceholder.typicode.com/todos/1',
29
+ method: 'GET'
30
+ })
43
31
  const resBody = typeof res.body === 'string' ? JSON.parse(res.body) : res.body
44
32
 
45
33
  ctx.response({
46
- data: { result: resBody.data },
34
+ data: { result: resBody },
47
35
  })
48
36
 
49
37
  } catch (error) {
@@ -34,19 +34,19 @@ Page({
34
34
  .then((data) => {
35
35
  logger.log("receive data");
36
36
  const { result = {} } = data;
37
- const { text } = result;
37
+ const text = JSON.stringify(result);
38
38
 
39
39
  hmUI.createWidget(hmUI.widget.TEXT, {
40
- x: px(96),
41
- y: px(100),
42
- w: px(288),
43
- h: px(46),
40
+ x: px(56),
41
+ y: px(74),
42
+ w: DEVICE_WIDTH - 2 * px(56),
43
+ h: px(200),
44
44
  color: 0xffffff,
45
45
  text_size: px(36),
46
46
  align_h: hmUI.align.CENTER_H,
47
47
  align_v: hmUI.align.CENTER_V,
48
48
  text_style: hmUI.text_style.NONE,
49
- text,
49
+ text: text,
50
50
  });
51
51
  });
52
52
  },
@@ -2,21 +2,6 @@ import { MessageBuilder } from "../shared/message-side";
2
2
 
3
3
  const messageBuilder = new MessageBuilder();
4
4
 
5
- // Simulating an asynchronous network request using Promise
6
- async function mockAPI() {
7
- return new Promise((resolve, reject) => {
8
- setTimeout(() => {
9
- resolve({
10
- body: {
11
- data: {
12
- text: "HELLO ZEPPOS",
13
- },
14
- },
15
- });
16
- }, 1000);
17
- });
18
- };
19
-
20
5
  async function fetchData(ctx) {
21
6
  try {
22
7
  // Requesting network data using the fetch API
@@ -38,12 +23,15 @@ async function fetchData(ctx) {
38
23
  // })
39
24
  // })
40
25
 
41
- // A network request is simulated here
42
- const res = await mockAPI()
26
+ // A network request is simulated here, Reference documentation: https://jsonplaceholder.typicode.com/
27
+ const res = await fetch({
28
+ url: 'https://jsonplaceholder.typicode.com/todos/1',
29
+ method: 'GET'
30
+ })
43
31
  const resBody = typeof res.body === 'string' ? JSON.parse(res.body) : res.body
44
32
 
45
33
  ctx.response({
46
- data: { result: resBody.data },
34
+ data: { result: resBody },
47
35
  })
48
36
 
49
37
  } catch (error) {
@@ -36,13 +36,13 @@ Page({
36
36
  .then((data) => {
37
37
  logger.log("receive data");
38
38
  const { result = {} } = data;
39
- const { text } = result;
39
+ const text = JSON.stringify(result);
40
40
 
41
41
  createWidget(widget.TEXT, {
42
- x: px(50),
43
- y: px(100),
44
- w: DEVICE_WIDTH - 2 * px(50),
45
- h: px(46),
42
+ x: px(56),
43
+ y: px(74),
44
+ w: DEVICE_WIDTH - 2 * px(56),
45
+ h: px(200),
46
46
  color: 0xffffff,
47
47
  text_size: px(36),
48
48
  align_h: align.CENTER_H,
@@ -52,5 +52,5 @@ Page({
52
52
  })
53
53
  .catch((res) => { });
54
54
  })
55
- }
55
+ }
56
56
  })
@@ -1,37 +1,5 @@
1
1
  import { BaseSideService } from "@zeppos/zml/base-side";
2
2
 
3
- const padStart = (str, maxLength, fillStr = "0") => {
4
- return str.toString().padStart(maxLength, fillStr);
5
- };
6
-
7
- const formatDate = (date = new Date()) => {
8
- const y = date.getFullYear();
9
- const m = date.getMonth() + 1;
10
- const d = date.getDate();
11
- const h = date.getHours();
12
- const mm = date.getMinutes();
13
- const s = date.getSeconds();
14
-
15
- return `${y}-${padStart(m, 2)}-${padStart(d, 2)} ${padStart(h, 2)}:${padStart(
16
- mm,
17
- 2
18
- )}:${padStart(s, 2)}`;
19
- };
20
- // Simulating an asynchronous network request using Promise
21
- async function mockAPI() {
22
- return new Promise((resolve, reject) => {
23
- setTimeout(() => {
24
- resolve({
25
- body: {
26
- data: {
27
- text: "HELLO ZEPPOS: " + formatDate(),
28
- },
29
- },
30
- });
31
- }, 1000);
32
- });
33
- };
34
-
35
3
  async function fetchData(res) {
36
4
  try {
37
5
  // Requesting network data using the fetch API
@@ -53,11 +21,15 @@ async function fetchData(res) {
53
21
  // })
54
22
  // })
55
23
 
56
- // A network request is simulated here
57
- const { body: { data = {} } = {} } = await mockAPI();
24
+ // A network request is simulated here, Reference documentation: https://jsonplaceholder.typicode.com/
25
+ const response = await fetch({
26
+ url: 'https://jsonplaceholder.typicode.com/todos/1',
27
+ method: 'GET'
28
+ })
29
+ const resBody = typeof response.body === 'string' ? JSON.parse(response.body) : response.body
58
30
 
59
31
  res(null, {
60
- result: data,
32
+ result: resBody,
61
33
  });
62
34
  } catch (error) {
63
35
  res(null, {
@@ -28,7 +28,7 @@ Page(
28
28
  .then((data) => {
29
29
  logger.log("receive data");
30
30
  const { result = {} } = data;
31
- const { text } = result;
31
+ const text = JSON.stringify(result);
32
32
 
33
33
  if (!textWidget) {
34
34
  textWidget = hmUI.createWidget(hmUI.widget.TEXT, {
@@ -8,10 +8,10 @@ import {
8
8
  import { DEVICE_WIDTH } from "../utils/config/device";
9
9
 
10
10
  export const FETCH_BUTTON = {
11
- x: (DEVICE_WIDTH - px(400)) / 2,
12
- y: px(260),
13
- w: px(400),
14
- h: px(100),
11
+ x: (DEVICE_WIDTH - px(360)) / 2,
12
+ y: px(300),
13
+ w: px(360),
14
+ h: px(80),
15
15
  text_size: px(36),
16
16
  radius: px(12),
17
17
  normal_color: DEFAULT_COLOR,
@@ -20,10 +20,10 @@ export const FETCH_BUTTON = {
20
20
  };
21
21
 
22
22
  export const FETCH_RESULT_TEXT = {
23
- x: px(50),
24
- y: px(100),
25
- w: DEVICE_WIDTH - 2 * px(50),
26
- h: px(120),
23
+ x: px(56),
24
+ y: px(74),
25
+ w: DEVICE_WIDTH - 2 * px(56),
26
+ h: px(200),
27
27
  color: 0xffffff,
28
28
  text_size: px(36),
29
29
  align_h: hmUI.align.CENTER_H,
@@ -11,7 +11,7 @@ export const FETCH_BUTTON = {
11
11
  x: (DEVICE_WIDTH - px(340)) / 2,
12
12
  y: px(280),
13
13
  w: px(340),
14
- h: px(100),
14
+ h: px(80),
15
15
  text_size: px(36),
16
16
  radius: px(12),
17
17
  normal_color: DEFAULT_COLOR,
@@ -67,9 +67,9 @@ var yargs_parser_1 = __importDefault(require("yargs-parser"));
67
67
  var path = __importStar(require("path"));
68
68
  var fs_extra_1 = __importDefault(require("fs-extra"));
69
69
  var index_1 = require("../index");
70
- var deviceInternalCodeName = index_1.config.deviceInternalCodeName;
71
70
  var fs_1 = require("fs");
72
71
  var rd = __importStar(require("rd"));
72
+ var getDeviceConf = index_1.config.getDeviceConf;
73
73
  var parserZeusCommand = function (command) {
74
74
  return (0, yargs_parser_1["default"])(command.replace(/^(zeus )/, ''));
75
75
  };
@@ -88,6 +88,7 @@ var getDeviceInfoFromAppJson = function (root) {
88
88
  var deviceSourceArr = platforms.map(function (item) {
89
89
  return item.deviceSource;
90
90
  });
91
+ var deviceInternalCodeName = getDeviceConf().deviceInternalCodeName;
91
92
  return {
92
93
  deviceSource: deviceSource,
93
94
  appId: appId,
@@ -13,7 +13,7 @@
13
13
  "dev": "nodemon -e ts,tsx --exec \"rm -rf dist && tsc && ts-node build.ts\" --ignore types/ --ignore dist/"
14
14
  },
15
15
  "dependencies": {
16
- "@zeppos/zpm": "^3.0.1",
16
+ "@zeppos/zpm": "^3.0.3",
17
17
  "axios": "^0.27.2",
18
18
  "chalk": "^4.1.2",
19
19
  "chokidar": "^3.5.3",
@@ -1,116 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- exports.__esModule = true;
29
- exports.DeviceScreenType = void 0;
30
- var axios_1 = __importDefault(require("axios"));
31
- var os = __importStar(require("os"));
32
- var path = __importStar(require("path"));
33
- var fs = __importStar(require("fs"));
34
- var fs_extra_1 = __importDefault(require("fs-extra"));
35
- var lodash_1 = require("lodash");
36
- var LOCAL_CACHE_DEVICE_PATH = path.resolve(os.homedir(), ".zepp/.zeus_devices");
37
- var serverPath = 'https://upload-cdn.zepp.com/zeppos/devkit/zeus/devices.json';
38
- var DeviceScreenType;
39
- (function (DeviceScreenType) {
40
- DeviceScreenType["R"] = "r";
41
- DeviceScreenType["S"] = "s";
42
- DeviceScreenType["B"] = "b";
43
- })(DeviceScreenType = exports.DeviceScreenType || (exports.DeviceScreenType = {}));
44
- var shapeMap = {
45
- square: DeviceScreenType.S,
46
- round: DeviceScreenType.R,
47
- bar: DeviceScreenType.B
48
- };
49
- var localContent = {};
50
- if (fs.existsSync(LOCAL_CACHE_DEVICE_PATH)) {
51
- try {
52
- localContent = fs_extra_1["default"].readJsonSync(LOCAL_CACHE_DEVICE_PATH);
53
- }
54
- catch (_e) { }
55
- }
56
- var now = Date.now().valueOf();
57
- if (!((0, lodash_1.get)(localContent, 'expiredTime') > now)) {
58
- axios_1["default"].get(serverPath).then(function (res) {
59
- if (res.status === 200) {
60
- var data = res.data;
61
- if (!(0, lodash_1.isEmpty)(data)) {
62
- fs_extra_1["default"].writeJsonSync(LOCAL_CACHE_DEVICE_PATH, {
63
- devices: data,
64
- expiredTime: now + 24 * 60 * 60 * 1000
65
- });
66
- }
67
- }
68
- })["catch"](function (e) {
69
- console.log(e);
70
- process.exit(1);
71
- });
72
- }
73
- var deviceList = (0, lodash_1.get)(localContent, 'devices', []);
74
- var deviceGroup = (0, lodash_1.groupBy)(deviceList, 'productName');
75
- var deviceInfo = {};
76
- Object.values(deviceGroup).forEach(function (devices) {
77
- var _a;
78
- var info = {
79
- deviceName: '',
80
- platforms: [],
81
- screen: {
82
- type: DeviceScreenType.R,
83
- width: 0,
84
- height: 0
85
- },
86
- apiLevelLimit: {
87
- min: '1.0.0'
88
- }
89
- };
90
- var deviceInnerName = devices.reduce(function (acc, cur) {
91
- !info.deviceName && (info.deviceName = cur.productName);
92
- var screenType = (0, lodash_1.get)(shapeMap, (0, lodash_1.get)(cur, 'value.shape'));
93
- var _a = (0, lodash_1.get)(cur, 'value.screen.size', '').split('*'), width = _a[0], height = _a[1];
94
- if (screenType) {
95
- info.screen.type = screenType;
96
- }
97
- if (width && height) {
98
- info.screen.width = Number(width);
99
- info.screen.height = Number(height);
100
- }
101
- info.platforms.push({
102
- name: cur.code,
103
- deviceSource: cur.deviceSource
104
- });
105
- Object.assign(info.apiLevelLimit, {
106
- min: (0, lodash_1.get)(cur, 'value.os.apiLevelLimitMin', '1.0.0'),
107
- max: (0, lodash_1.get)(cur, 'value.os.version', '')
108
- });
109
- return cur.code.length < acc.length ? cur.code : acc;
110
- }, devices[0].code);
111
- var lowerName = (0, lodash_1.toLower)(deviceInnerName.replace(/[^a-zA-Z]/g, ''));
112
- lowerName && Object.assign(deviceInfo, (_a = {},
113
- _a[lowerName] = info,
114
- _a));
115
- });
116
- exports["default"] = deviceInfo;