@zeppos/zeus-cli 1.7.10 → 1.8.0
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/bin/main.js +85 -30
- package/bin/post-command.js +1 -1
- package/index.js +1 -1
- package/modules/bridge.js +43 -33
- package/modules/build.js +72 -36
- package/modules/create.js +213 -216
- package/modules/help.js +21 -11
- package/modules/prune.js +1 -1
- package/modules/run.js +29 -17
- package/modules/version.js +5 -6
- package/modules/yargsCmdBuilders.js +3 -3
- package/package.json +6 -4
- package/private-modules/zeppos-app-utils/dist/api/index.js +18 -20
- package/private-modules/zeppos-app-utils/dist/config/device.js +19 -17
- package/private-modules/zeppos-app-utils/dist/config/index.js +1 -1
- package/private-modules/zeppos-app-utils/dist/config/project.js +14 -14
- package/private-modules/zeppos-app-utils/dist/hm-analytics.js +14 -13
- package/private-modules/zeppos-app-utils/dist/index.js +18 -8
- package/private-modules/zeppos-app-utils/dist/logger/index.js +5 -5
- package/private-modules/zeppos-app-utils/dist/logger/my-logger.js +1 -1
- package/private-modules/zeppos-app-utils/dist/modules/build.js +73 -46
- package/private-modules/zeppos-app-utils/dist/modules/config.js +14 -12
- package/private-modules/zeppos-app-utils/dist/modules/create/index.js +71 -39
- package/private-modules/zeppos-app-utils/dist/modules/create/local-app.js +82 -66
- package/private-modules/zeppos-app-utils/dist/modules/create/yeoman-app.js +6 -6
- package/private-modules/zeppos-app-utils/dist/modules/fetchDevices.js +73 -40
- package/private-modules/zeppos-app-utils/dist/modules/index.js +1 -1
- package/private-modules/zeppos-app-utils/dist/modules/login.js +16 -15
- package/private-modules/zeppos-app-utils/dist/modules/open/index.js +62 -50
- package/private-modules/zeppos-app-utils/dist/modules/prune.js +5 -5
- package/private-modules/zeppos-app-utils/dist/modules/status.js +12 -12
- package/private-modules/zeppos-app-utils/dist/simulator.js +3 -3
- package/private-modules/zeppos-app-utils/dist/storage/index.js +7 -7
- package/private-modules/zeppos-app-utils/dist/tools/index.js +24 -14
- package/private-modules/zeppos-app-utils/dist/tools/tools.js +3 -3
- package/private-modules/zeppos-app-utils/dist/websocket.js +9 -9
- package/private-modules/zeppos-app-utils/package.json +2 -1
- package/utils/pre-check.js +52 -29
- package/utils/tools.js +4 -4
|
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g =
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -49,7 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
|
-
exports
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.createLocalApp = void 0;
|
|
54
54
|
var os_1 = __importDefault(require("os"));
|
|
55
55
|
var lodash_1 = __importDefault(require("lodash"));
|
|
@@ -61,70 +61,86 @@ var TemplateCopyType = index_1.config.TemplateCopyType, getDeviceConf = index_1.
|
|
|
61
61
|
var createLocalApp = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
switch (_a.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
workDir = args.workDir, templateInfo = args.templateInfo, withAppSide = args.withAppSide, withSettings = args.withSettings, buildTargets = args.buildTargets, appType = args.appType, shapeOfPlatform = args.shapeOfPlatform;
|
|
67
|
+
deviceTargets = getDeviceConf().deviceTargets;
|
|
68
|
+
fs_extra_1.default.copySync(templateInfo.path, workDir);
|
|
69
|
+
if (fs_extra_1.default.existsSync((0, path_1.resolve)(workDir, "./_package.json"))) {
|
|
70
|
+
fs_1.default.renameSync((0, path_1.resolve)(workDir, "./_package.json"), (0, path_1.resolve)(workDir, "./package.json"));
|
|
71
|
+
}
|
|
72
|
+
if (fs_extra_1.default.existsSync((0, path_1.resolve)(templateInfo.path, "./package.json")) &&
|
|
73
|
+
!fs_extra_1.default.existsSync((0, path_1.resolve)(templateInfo.path, "./global.d.ts"))) {
|
|
74
|
+
fs_1.default.writeFileSync("".concat(workDir, "/global.d.ts"), args.OSVersion === 'v1'
|
|
75
|
+
? '/// <reference path="node_modules/@zeppos/device-types/index.d.ts" />'
|
|
76
|
+
: '/// <reference path="node_modules/@zeppos/device-types/dist/index.d.ts" />');
|
|
77
|
+
}
|
|
78
|
+
appJsonPath = (0, path_1.resolve)(workDir, './app.json');
|
|
79
|
+
appJson = fs_extra_1.default.readJsonSync(appJsonPath);
|
|
80
|
+
if (args.OSVersion !== 'v1') {
|
|
81
|
+
appID = Math.floor(Math.random() * 10001) + 20000;
|
|
82
|
+
lodash_1.default.set(appJson, 'app.appId', appID);
|
|
83
|
+
}
|
|
84
|
+
if (!(templateInfo.copyType !== TemplateCopyType.EDIT)) return [3, 2];
|
|
85
|
+
return [4, fs_extra_1.default.writeJson(appJsonPath, appJson, {
|
|
86
|
+
spaces: 2,
|
|
87
|
+
EOL: os_1.default.EOL,
|
|
88
|
+
})];
|
|
89
|
+
case 1:
|
|
90
|
+
_a.sent();
|
|
91
|
+
return [2];
|
|
92
|
+
case 2:
|
|
93
|
+
defaultTarget = lodash_1.default.get(appJson, 'targets.default');
|
|
94
|
+
targets = {};
|
|
95
|
+
if (!!withAppSide) return [3, 4];
|
|
96
|
+
lodash_1.default.unset(defaultTarget, 'module.app-side');
|
|
97
|
+
return [4, fs_extra_1.default.remove((0, path_1.resolve)(workDir, './app-side'))];
|
|
98
|
+
case 3:
|
|
99
|
+
_a.sent();
|
|
100
|
+
_a.label = 4;
|
|
101
|
+
case 4:
|
|
102
|
+
if (!!withSettings) return [3, 6];
|
|
103
|
+
lodash_1.default.unset(defaultTarget, 'module.setting');
|
|
104
|
+
return [4, fs_extra_1.default.remove((0, path_1.resolve)(workDir, './setting'))];
|
|
105
|
+
case 5:
|
|
106
|
+
_a.sent();
|
|
107
|
+
_a.label = 6;
|
|
108
|
+
case 6:
|
|
109
|
+
if (Array.isArray(shapeOfPlatform)) {
|
|
110
|
+
shapes = ['r', 's', 'b'];
|
|
111
|
+
needDelShapeConfig = shapes.filter(function (item) { return !shapeOfPlatform.includes(item); });
|
|
112
|
+
needDelShapeConfig.forEach(function (shape) {
|
|
113
|
+
fs_extra_1.default.remove((0, path_1.resolve)(workDir, "./assets/gt.".concat(shape)));
|
|
114
|
+
fs_extra_1.default.remove((0, path_1.resolve)(workDir, "./page/index.".concat(shape, ".layout.js")));
|
|
115
|
+
var targets = lodash_1.default.get(appJson, 'targets');
|
|
116
|
+
var firstTarget = Object.keys(targets)[0] || 'default';
|
|
117
|
+
var platformsPathStr = "targets.".concat(firstTarget, ".platforms");
|
|
118
|
+
var platforms = lodash_1.default.get(appJson, platformsPathStr);
|
|
119
|
+
if (!Array.isArray(platforms))
|
|
120
|
+
return;
|
|
121
|
+
var filteredPlatforms = lodash_1.default.filter(platforms, function (platform) { return platform.st !== shape; });
|
|
122
|
+
lodash_1.default.set(appJson, platformsPathStr, filteredPlatforms);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (buildTargets && buildTargets.length) {
|
|
126
|
+
defaultAssetsPath_1 = (0, path_1.resolve)(workDir, './assets/default');
|
|
127
|
+
buildTargets.forEach(function (type) {
|
|
128
|
+
var _a = deviceTargets[type], deviceName = _a.deviceName, platforms = _a.platforms, screen = _a.screen;
|
|
129
|
+
var pkgName = "".concat(screen.width, "x").concat(screen.height, "-").concat(lodash_1.default.kebabCase(lodash_1.default.toLower(deviceName)));
|
|
130
|
+
lodash_1.default.set(targets, pkgName, __assign(__assign({}, defaultTarget), { platforms: platforms, designWidth: screen.width }));
|
|
131
|
+
fs_extra_1.default.copySync(defaultAssetsPath_1, (0, path_1.resolve)(workDir, "./assets/".concat(pkgName)));
|
|
132
|
+
});
|
|
133
|
+
fs_extra_1.default.removeSync(defaultAssetsPath_1);
|
|
134
|
+
lodash_1.default.set(appJson, 'targets', targets);
|
|
135
|
+
}
|
|
136
|
+
return [4, fs_extra_1.default.writeJson(appJsonPath, appJson, {
|
|
137
|
+
spaces: 2,
|
|
138
|
+
EOL: os_1.default.EOL,
|
|
139
|
+
})];
|
|
140
|
+
case 7:
|
|
141
|
+
_a.sent();
|
|
142
|
+
return [2];
|
|
69
143
|
}
|
|
70
|
-
if (fs_extra_1["default"].existsSync((0, path_1.resolve)(templateInfo.path, "./package.json")) && !fs_extra_1["default"].existsSync((0, path_1.resolve)(templateInfo.path, "./global.d.ts"))) {
|
|
71
|
-
fs_1["default"].writeFileSync("".concat(workDir, "/global.d.ts"), args.OSVersion === 'v1' ? '/// <reference path="node_modules/@zeppos/device-types/index.d.ts" />' : '/// <reference path="node_modules/@zeppos/device-types/dist/index.d.ts" />');
|
|
72
|
-
}
|
|
73
|
-
appJsonPath = (0, path_1.resolve)(workDir, './app.json');
|
|
74
|
-
appJson = fs_extra_1["default"].readJsonSync(appJsonPath);
|
|
75
|
-
if (args.OSVersion !== 'v1') {
|
|
76
|
-
appID = Math.floor(Math.random() * 10001) + 20000;
|
|
77
|
-
lodash_1["default"].set(appJson, 'app.appId', appID);
|
|
78
|
-
}
|
|
79
|
-
if (templateInfo.copyType !== TemplateCopyType.EDIT) {
|
|
80
|
-
fs_extra_1["default"].writeJson(appJsonPath, appJson, {
|
|
81
|
-
spaces: 2,
|
|
82
|
-
EOL: os_1["default"].EOL
|
|
83
|
-
});
|
|
84
|
-
return [2];
|
|
85
|
-
}
|
|
86
|
-
defaultTarget = lodash_1["default"].get(appJson, 'targets.default');
|
|
87
|
-
targets = {};
|
|
88
|
-
if (!withAppSide) {
|
|
89
|
-
lodash_1["default"].unset(defaultTarget, 'module.app-side');
|
|
90
|
-
fs_extra_1["default"].remove((0, path_1.resolve)(workDir, './app-side'));
|
|
91
|
-
}
|
|
92
|
-
if (!withSettings) {
|
|
93
|
-
lodash_1["default"].unset(defaultTarget, 'module.setting');
|
|
94
|
-
fs_extra_1["default"].remove((0, path_1.resolve)(workDir, './setting'));
|
|
95
|
-
}
|
|
96
|
-
if (Array.isArray(shapeOfPlatform)) {
|
|
97
|
-
shapes = ['r', 's', 'b'];
|
|
98
|
-
needDelShapeConfig = shapes.filter(function (item) { return !shapeOfPlatform.includes(item); });
|
|
99
|
-
needDelShapeConfig.forEach(function (shape) {
|
|
100
|
-
fs_extra_1["default"].remove((0, path_1.resolve)(workDir, "./assets/gt.".concat(shape)));
|
|
101
|
-
fs_extra_1["default"].remove((0, path_1.resolve)(workDir, "./page/index.".concat(shape, ".layout.js")));
|
|
102
|
-
var targets = lodash_1["default"].get(appJson, 'targets');
|
|
103
|
-
var firstTarget = Object.keys(targets)[0] || 'default';
|
|
104
|
-
var platformsPathStr = "targets.".concat(firstTarget, ".platforms");
|
|
105
|
-
var platforms = lodash_1["default"].get(appJson, platformsPathStr);
|
|
106
|
-
if (!Array.isArray(platforms))
|
|
107
|
-
return;
|
|
108
|
-
var filteredPlatforms = lodash_1["default"].filter(platforms, function (platform) { return platform.st !== shape; });
|
|
109
|
-
lodash_1["default"].set(appJson, platformsPathStr, filteredPlatforms);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (buildTargets && buildTargets.length) {
|
|
113
|
-
defaultAssetsPath_1 = (0, path_1.resolve)(workDir, './assets/default');
|
|
114
|
-
buildTargets.forEach(function (type) {
|
|
115
|
-
var _a = deviceTargets[type], deviceName = _a.deviceName, platforms = _a.platforms, screen = _a.screen;
|
|
116
|
-
var pkgName = "".concat(screen.width, "x").concat(screen.height, "-").concat(lodash_1["default"].kebabCase(lodash_1["default"].toLower(deviceName)));
|
|
117
|
-
lodash_1["default"].set(targets, pkgName, __assign(__assign({}, defaultTarget), { platforms: platforms, designWidth: screen.width }));
|
|
118
|
-
fs_extra_1["default"].copySync(defaultAssetsPath_1, (0, path_1.resolve)(workDir, "./assets/".concat(pkgName)));
|
|
119
|
-
});
|
|
120
|
-
fs_extra_1["default"].removeSync(defaultAssetsPath_1);
|
|
121
|
-
lodash_1["default"].set(appJson, 'targets', targets);
|
|
122
|
-
}
|
|
123
|
-
fs_extra_1["default"].writeJson(appJsonPath, appJson, {
|
|
124
|
-
spaces: 2,
|
|
125
|
-
EOL: os_1["default"].EOL
|
|
126
|
-
});
|
|
127
|
-
return [2];
|
|
128
144
|
});
|
|
129
145
|
}); };
|
|
130
146
|
exports.createLocalApp = createLocalApp;
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -38,7 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
|
-
exports
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.createYeomanApp = void 0;
|
|
43
43
|
var lodash_1 = require("lodash");
|
|
44
44
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -47,15 +47,15 @@ var update_notifier_1 = __importDefault(require("update-notifier"));
|
|
|
47
47
|
var yeoman_environment_1 = require("yeoman-environment");
|
|
48
48
|
var findup_sync_1 = __importDefault(require("findup-sync"));
|
|
49
49
|
var resolveGenerator = function (generator) {
|
|
50
|
-
var pkgPath = (0, findup_sync_1
|
|
50
|
+
var pkgPath = (0, findup_sync_1.default)('package.json', { cwd: (0, path_1.dirname)(generator.resolved), nocase: true }) || '';
|
|
51
51
|
if (!pkgPath) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
var pkg = fs_extra_1
|
|
54
|
+
var pkg = fs_extra_1.default.readJSONSync(pkgPath);
|
|
55
55
|
pkg.namespace = generator.namespace;
|
|
56
56
|
pkg.appGenerator = true;
|
|
57
57
|
pkg.prettyName = (0, lodash_1.kebabCase)((0, lodash_1.toLower)((0, yeoman_environment_1.namespaceToName)(generator.namespace)));
|
|
58
|
-
pkg.update = (0, update_notifier_1
|
|
58
|
+
pkg.update = (0, update_notifier_1.default)({ pkg: pkg }).update;
|
|
59
59
|
if (pkg.update && pkg.version !== pkg.update.latest) {
|
|
60
60
|
pkg.updateAvailable = true;
|
|
61
61
|
}
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -35,10 +35,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
38
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
49
|
};
|
|
41
|
-
exports
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
51
|
exports.fetchDevices = exports.DeviceScreenType = void 0;
|
|
43
52
|
var axios_1 = __importDefault(require("axios"));
|
|
44
53
|
var os_1 = __importDefault(require("os"));
|
|
@@ -47,19 +56,21 @@ var fs_1 = __importDefault(require("fs"));
|
|
|
47
56
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
48
57
|
var lodash_1 = require("lodash");
|
|
49
58
|
var config_1 = require("../config");
|
|
50
|
-
var logger_1 = require("../logger");
|
|
51
59
|
var chalk_1 = __importDefault(require("chalk"));
|
|
60
|
+
var ora_1 = __importDefault(require("ora"));
|
|
52
61
|
var accountEnv = (0, config_1.getLocalConfig)().account_env;
|
|
53
62
|
var dayMS = 24 * 60 * 60 * 1000;
|
|
54
|
-
var LOCAL_CACHE_DEVICE_PATH = path_1
|
|
55
|
-
var serverPath = accountEnv === 'test'
|
|
63
|
+
var LOCAL_CACHE_DEVICE_PATH = path_1.default.resolve(os_1.default.homedir(), ".zepp/.zeus_devices");
|
|
64
|
+
var serverPath = accountEnv === 'test'
|
|
65
|
+
? 'https://upload-testing-cdn.huami.com/zeppos/devkit/zeus/devices.json'
|
|
66
|
+
: 'https://upload-cdn.zepp.com/zeppos/devkit/zeus/devices.json';
|
|
56
67
|
var serverPathBeta = 'https://upload-cdn.zepp.com/zeppos/devkit/zeus/devices.beta.json';
|
|
57
68
|
var DeviceScreenType;
|
|
58
69
|
(function (DeviceScreenType) {
|
|
59
70
|
DeviceScreenType["R"] = "r";
|
|
60
71
|
DeviceScreenType["S"] = "s";
|
|
61
72
|
DeviceScreenType["B"] = "b";
|
|
62
|
-
})(DeviceScreenType
|
|
73
|
+
})(DeviceScreenType || (exports.DeviceScreenType = DeviceScreenType = {}));
|
|
63
74
|
var fetchDevicesData = function (cdnUrl) {
|
|
64
75
|
if (cdnUrl === void 0) { cdnUrl = ''; }
|
|
65
76
|
return new Promise(function (resolve, reject) {
|
|
@@ -68,62 +79,84 @@ var fetchDevicesData = function (cdnUrl) {
|
|
|
68
79
|
process.exit(1);
|
|
69
80
|
}
|
|
70
81
|
cdnUrl = cdnUrl + (cdnUrl.includes('?') ? '&' : '?') + 'no-cache=' + Date.now();
|
|
71
|
-
axios_1
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
axios_1.default
|
|
83
|
+
.get(cdnUrl, {
|
|
84
|
+
headers: { 'Cache-Control': 'no-cache' },
|
|
85
|
+
})
|
|
86
|
+
.then(function (res) {
|
|
74
87
|
if (res.status === 200) {
|
|
75
88
|
var data = res.data;
|
|
76
89
|
resolve(data);
|
|
77
90
|
}
|
|
78
|
-
})
|
|
91
|
+
})
|
|
92
|
+
.catch(function (e) {
|
|
79
93
|
console.log(e);
|
|
80
94
|
resolve([]);
|
|
81
95
|
process.exit(1);
|
|
82
96
|
});
|
|
83
97
|
});
|
|
84
98
|
};
|
|
85
|
-
var fetchDevices = function (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
var fetchDevices = function () {
|
|
100
|
+
var args_1 = [];
|
|
101
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
102
|
+
args_1[_i] = arguments[_i];
|
|
103
|
+
}
|
|
104
|
+
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (currentVersion, force) {
|
|
105
|
+
var localContent, generatedVersion, fetchAndSaveRemoteDevices, now;
|
|
106
|
+
if (currentVersion === void 0) { currentVersion = ''; }
|
|
107
|
+
if (force === void 0) { force = false; }
|
|
89
108
|
return __generator(this, function (_a) {
|
|
90
109
|
switch (_a.label) {
|
|
91
110
|
case 0:
|
|
92
111
|
localContent = {};
|
|
93
|
-
if (fs_1
|
|
112
|
+
if (fs_1.default.existsSync(LOCAL_CACHE_DEVICE_PATH)) {
|
|
94
113
|
try {
|
|
95
|
-
localContent = fs_extra_1
|
|
114
|
+
localContent = fs_extra_1.default.readJsonSync(LOCAL_CACHE_DEVICE_PATH);
|
|
96
115
|
}
|
|
97
116
|
catch (_e) { }
|
|
98
117
|
}
|
|
99
118
|
generatedVersion = (0, lodash_1.get)(localContent, 'version') || '';
|
|
100
119
|
if (generatedVersion === '' || generatedVersion !== currentVersion) {
|
|
101
|
-
fs_extra_1
|
|
120
|
+
fs_extra_1.default.removeSync(LOCAL_CACHE_DEVICE_PATH);
|
|
102
121
|
localContent = {};
|
|
103
122
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
fetchAndSaveRemoteDevices = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
124
|
+
var spinner, prodDevices, betaDevices;
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
switch (_a.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
spinner = (0, ora_1.default)(chalk_1.default.hex('#DB8C41')('Updating devices, waiting ...')).start();
|
|
129
|
+
return [4, fetchDevicesData(serverPath)];
|
|
130
|
+
case 1:
|
|
131
|
+
prodDevices = _a.sent();
|
|
132
|
+
return [4, fetchDevicesData(serverPathBeta)];
|
|
133
|
+
case 2:
|
|
134
|
+
betaDevices = _a.sent();
|
|
135
|
+
if (!(0, lodash_1.isEmpty)(prodDevices) || !(0, lodash_1.isEmpty)(betaDevices)) {
|
|
136
|
+
fs_extra_1.default.writeJsonSync(LOCAL_CACHE_DEVICE_PATH, {
|
|
137
|
+
devices: prodDevices,
|
|
138
|
+
devices_beta: betaDevices,
|
|
139
|
+
expiredTime: now + 3 * dayMS,
|
|
140
|
+
version: currentVersion,
|
|
141
|
+
});
|
|
142
|
+
spinner.succeed('Updating devices, success.');
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return [2, {}];
|
|
146
|
+
}
|
|
147
|
+
return [2];
|
|
148
|
+
}
|
|
119
149
|
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
150
|
+
}); };
|
|
151
|
+
if (!force) return [3, 2];
|
|
152
|
+
return [4, fetchAndSaveRemoteDevices()];
|
|
153
|
+
case 1: return [2, _a.sent()];
|
|
154
|
+
case 2:
|
|
155
|
+
now = Date.now().valueOf();
|
|
156
|
+
if (!!((0, lodash_1.get)(localContent, 'expiredTime') > now)) return [3, 4];
|
|
157
|
+
return [4, fetchAndSaveRemoteDevices()];
|
|
158
|
+
case 3: return [2, _a.sent()];
|
|
159
|
+
case 4: return [2, {}];
|
|
127
160
|
}
|
|
128
161
|
});
|
|
129
162
|
});
|
|
@@ -13,7 +13,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./login"), exports);
|
|
18
18
|
__exportStar(require("./config"), exports);
|
|
19
19
|
__exportStar(require("./status"), exports);
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -38,7 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
|
-
exports
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.logout = exports.login = void 0;
|
|
43
43
|
var open_1 = __importDefault(require("./open"));
|
|
44
44
|
var http_1 = __importDefault(require("http"));
|
|
@@ -55,24 +55,25 @@ var loginCallbackServer = function (cb) { return __awaiter(void 0, void 0, void
|
|
|
55
55
|
switch (_a.label) {
|
|
56
56
|
case 0:
|
|
57
57
|
callbackPath = '/login/callback';
|
|
58
|
-
return [4, (0, get_port_1
|
|
58
|
+
return [4, (0, get_port_1.default)()];
|
|
59
59
|
case 1:
|
|
60
60
|
port = _a.sent();
|
|
61
|
-
server = (0, stoppable_1
|
|
61
|
+
server = (0, stoppable_1.default)(http_1.default.createServer(function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
62
|
var reqUrl, query, appToken, userId, cname;
|
|
63
63
|
return __generator(this, function (_a) {
|
|
64
64
|
reqUrl = req.url || '';
|
|
65
|
-
if (lodash_1
|
|
65
|
+
if (lodash_1.default.startsWith(reqUrl, callbackPath)) {
|
|
66
66
|
res.statusCode = 200;
|
|
67
67
|
res.setHeader('Content-Type', 'text/html');
|
|
68
|
-
res.end("<!DOCTYPE html>\n <html>\n <head> \n <meta charset=\"utf-8\"> \n <title>Login | Zepp Health</title>\n <style>html,iframe,body,div{margin: 0;padding: 0;border: 0;outline: 0;font-size: 0;vertical-align: baseline;background: transparent;}</style>\n </head> \n <body>\n <iframe src=\"https://upload-cdn.huami.com/tposts/4436118\" style=\"width: 100vw; height: 100vh;\"></iframe>\n </body>\n </html>");
|
|
69
|
-
query = url_1
|
|
68
|
+
res.end("<!DOCTYPE html>\n <html lang=\"en\">\n <head> \n <meta charset=\"utf-8\"> \n <title>Login | Zepp Health</title>\n <style>html,iframe,body,div{margin: 0;padding: 0;border: 0;outline: 0;font-size: 0;vertical-align: baseline;background: transparent;}</style>\n </head> \n <body>\n <iframe src=\"https://upload-cdn.huami.com/tposts/4436118\" style=\"width: 100vw; height: 100vh;\"></iframe>\n </body>\n </html>");
|
|
69
|
+
query = url_1.default.parse(reqUrl, true).query;
|
|
70
70
|
appToken = query.apptoken, userId = query.userid, cname = query.cname;
|
|
71
|
-
cb &&
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
cb &&
|
|
72
|
+
cb({
|
|
73
|
+
appToken: appToken,
|
|
74
|
+
userId: userId,
|
|
75
|
+
cname: cname,
|
|
76
|
+
});
|
|
76
77
|
server.stop();
|
|
77
78
|
}
|
|
78
79
|
return [2];
|
|
@@ -118,10 +119,10 @@ var login = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|
|
118
119
|
_h.label = 2;
|
|
119
120
|
case 2:
|
|
120
121
|
_h.trys.push([2, 4, , 5]);
|
|
121
|
-
return [4, (0, open_1
|
|
122
|
+
return [4, (0, open_1.default)("".concat(loginConfig.LOGIN_URL, "?").concat(qs_1.default.stringify({
|
|
122
123
|
project_name: loginConfig.PROJECT_NAME,
|
|
123
124
|
platform_app: loginConfig.PLATFORM_APP,
|
|
124
|
-
project_redirect_uri: loginCallbackUrl
|
|
125
|
+
project_redirect_uri: loginCallbackUrl,
|
|
125
126
|
})))];
|
|
126
127
|
case 3:
|
|
127
128
|
_h.sent();
|