@zeppos/zeus-cli 1.1.0-beta → 1.1.2
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 +80 -103
- package/bin/cli.js +74 -22
- package/bin/post-command.js +8 -0
- package/config/device.js +0 -1
- package/config/project.js +11 -14
- package/font-icon.js +12 -0
- package/index.js +5 -1
- package/modules/bridge.js +88 -54
- package/modules/build.js +89 -75
- package/modules/config.js +15 -14
- package/modules/create/index.js +18 -15
- package/modules/create/local-app.js +2 -3
- package/modules/create/yeoman-app.js +1 -1
- package/modules/help.js +7 -4
- package/modules/login.js +96 -77
- package/modules/run.js +31 -9
- package/modules/simulator.js +6 -2
- package/modules/status.js +48 -17
- package/modules/storage.js +4 -77
- package/modules/websocket.js +7 -9
- package/package.json +7 -2
- package/utils/common.js +37 -17
- package/utils/hm-analytics.js +54 -0
- package/utils/logger.js +1 -13
- package/utils/pre-check.js +169 -0
- package/utils/hm_analytics.js +0 -35
package/modules/bridge.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -59,65 +63,61 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
63
|
};
|
|
60
64
|
exports.__esModule = true;
|
|
61
65
|
exports.bridge = void 0;
|
|
66
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
67
|
+
var fs_1 = require("fs");
|
|
68
|
+
var logger = __importStar(require("../utils/logger"));
|
|
62
69
|
var project_1 = require("../config/project");
|
|
63
70
|
var index_1 = require("../api/index");
|
|
64
|
-
var logger = __importStar(require("../utils/logger"));
|
|
65
|
-
var chalk_1 = __importDefault(require("chalk"));
|
|
66
|
-
var inquirer_1 = __importDefault(require("inquirer"));
|
|
67
71
|
var websocket_1 = __importDefault(require("./websocket"));
|
|
68
72
|
var build_1 = require("./build");
|
|
69
73
|
var common_1 = require("../utils/common");
|
|
70
|
-
|
|
74
|
+
var login_1 = require("./login");
|
|
71
75
|
var client;
|
|
72
76
|
var hasConnectDevice = false;
|
|
73
77
|
var choiredDevice;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var connectDevice = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
77
|
-
var debugConnectedDevice, optionalDeviceArr, len, clientId, answer;
|
|
78
|
+
var connectDevice = function (vorpal) { return __awaiter(void 0, void 0, void 0, function () {
|
|
79
|
+
var debugConnectedDevice, optionalDeviceArr, len, clientId_1;
|
|
78
80
|
return __generator(this, function (_a) {
|
|
79
81
|
switch (_a.label) {
|
|
80
82
|
case 0:
|
|
81
83
|
debugConnectedDevice = JSON.parse(project_1.____inner_global_variable.bridgeOptionalDevice);
|
|
82
84
|
optionalDeviceArr = Object.keys(debugConnectedDevice);
|
|
83
85
|
len = optionalDeviceArr.length;
|
|
84
|
-
if (!(len === 0)) return [3
|
|
85
|
-
|
|
86
|
-
return [3
|
|
86
|
+
if (!(len === 0)) return [3, 1];
|
|
87
|
+
vorpal.log(chalk_1["default"].yellow('No connectable online App or Simulator.'));
|
|
88
|
+
return [3, 4];
|
|
87
89
|
case 1:
|
|
88
|
-
|
|
90
|
+
clientId_1 = debugConnectedDevice[optionalDeviceArr[0]];
|
|
89
91
|
choiredDevice = optionalDeviceArr[0];
|
|
90
|
-
if (!(len > 1)) return [3
|
|
91
|
-
return [4
|
|
92
|
+
if (!(len > 1)) return [3, 3];
|
|
93
|
+
return [4, vorpal.activeCommand.prompt({
|
|
92
94
|
name: 'choiredDevice',
|
|
93
95
|
type: 'list',
|
|
94
96
|
choices: optionalDeviceArr,
|
|
95
97
|
message: 'Which online target would you like to connect?'
|
|
98
|
+
}, function (result) {
|
|
99
|
+
clientId_1 = debugConnectedDevice[result.choiredDevice];
|
|
100
|
+
choiredDevice = result.choiredDevice;
|
|
101
|
+
vorpal.delimiter('bridge$').show();
|
|
96
102
|
})];
|
|
97
103
|
case 2:
|
|
98
|
-
|
|
99
|
-
clientId = debugConnectedDevice[answer.choiredDevice];
|
|
100
|
-
choiredDevice = answer.choiredDevice;
|
|
104
|
+
_a.sent();
|
|
101
105
|
_a.label = 3;
|
|
102
106
|
case 3:
|
|
103
107
|
project_1.____inner_global_variable.bridgeChoiredDevice = choiredDevice;
|
|
104
|
-
|
|
105
|
-
client.sendMessage({ clientId: clientId }, 'connectClient');
|
|
108
|
+
client.sendMessage({ clientId: clientId_1 }, 'connectClient');
|
|
106
109
|
hasConnectDevice = true;
|
|
107
110
|
_a.label = 4;
|
|
108
|
-
case 4: return [2
|
|
111
|
+
case 4: return [2];
|
|
109
112
|
}
|
|
110
113
|
});
|
|
111
114
|
}); };
|
|
112
115
|
var connectBridgeWSCallback = function () {
|
|
113
|
-
// 创建:Vorpal
|
|
114
116
|
var vorpal = require('vorpal')();
|
|
115
117
|
vorpal.find('help').hidden();
|
|
116
118
|
vorpal.find('exit').remove();
|
|
117
119
|
vorpal.command('exit', 'Exits application.')
|
|
118
120
|
.action(function () {
|
|
119
|
-
project_1.____inner_global_variable.bridgeOptionalDevice = '';
|
|
120
|
-
project_1.____inner_global_variable.bridgeChoiredDevice = '';
|
|
121
121
|
process.exit(0);
|
|
122
122
|
});
|
|
123
123
|
vorpal
|
|
@@ -125,80 +125,114 @@ var connectBridgeWSCallback = function () {
|
|
|
125
125
|
.show();
|
|
126
126
|
vorpal["catch"]('[words...]', 'Catches incorrect commands.')
|
|
127
127
|
.action(function (args, cb) {
|
|
128
|
-
|
|
128
|
+
vorpal.log(" - '".concat(args.words.join(' '), "' is not a valid command.Enter 'help' to view Commands."));
|
|
129
129
|
cb();
|
|
130
130
|
});
|
|
131
131
|
vorpal
|
|
132
132
|
.command('connect', 'Connect the online App or Simulator for debugging.')
|
|
133
|
-
.
|
|
133
|
+
.option('--anchovies')
|
|
134
|
+
.action(function (args, cb) { return __awaiter(void 0, void 0, void 0, function () {
|
|
134
135
|
return __generator(this, function (_a) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return [2
|
|
136
|
+
connectDevice(vorpal);
|
|
137
|
+
cb();
|
|
138
|
+
return [2];
|
|
138
139
|
});
|
|
139
140
|
}); });
|
|
140
141
|
vorpal
|
|
141
142
|
.command('install', 'Install applications or watch face.')
|
|
142
|
-
.action(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
143
|
+
.action(function (args, cb) { return __awaiter(void 0, void 0, void 0, function () {
|
|
143
144
|
return __generator(this, function (_a) {
|
|
144
145
|
switch (_a.label) {
|
|
145
146
|
case 0:
|
|
146
|
-
if (!hasConnectDevice) return [3
|
|
147
|
-
return [4
|
|
147
|
+
if (!hasConnectDevice) return [3, 2];
|
|
148
|
+
return [4, (0, build_1.buildPreview)({ _: ['install', "".concat(choiredDevice.toLowerCase())], '$0': 'zeus' }, function (params) {
|
|
148
149
|
client.sendMessage(params, 'packagePush');
|
|
149
150
|
})];
|
|
150
151
|
case 1:
|
|
151
152
|
_a.sent();
|
|
152
|
-
return [3
|
|
153
|
+
return [3, 3];
|
|
153
154
|
case 2:
|
|
154
|
-
|
|
155
|
+
vorpal.log(chalk_1["default"].yellow("No device is connected, please connect the device with the command width 'connect' first."));
|
|
155
156
|
_a.label = 3;
|
|
156
|
-
case 3:
|
|
157
|
+
case 3:
|
|
158
|
+
cb();
|
|
159
|
+
return [2];
|
|
157
160
|
}
|
|
158
161
|
});
|
|
159
162
|
}); });
|
|
160
|
-
// 卸载命令
|
|
161
163
|
vorpal
|
|
162
|
-
.command('uninstall', 'Uninstall applications or watch face.')
|
|
163
|
-
.action(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
164
|
-
var _a, appid,
|
|
164
|
+
.command('uninstall [appid]', 'Uninstall applications or watch face.')
|
|
165
|
+
.action(function (args, cb) { return __awaiter(void 0, void 0, void 0, function () {
|
|
166
|
+
var _a, appid, appName, appType;
|
|
165
167
|
return __generator(this, function (_b) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
if (!args.appid) {
|
|
169
|
+
if (!(0, fs_1.existsSync)('./app.json')) {
|
|
170
|
+
vorpal.log("".concat(chalk_1["default"].red('error'), " If the [appid] is blank, this command needs to be executed in the root of the project."));
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
vorpal.log(chalk_1["default"].blue('Uninstalling'));
|
|
174
|
+
_a = (0, common_1.getDeviceInfoFromAppJson)(), appid = _a.appId, appName = _a.appName, appType = _a.appType;
|
|
175
|
+
client.sendMessage({ type: 'delete', appid: appid, appName: appName, appType: appType }, 'sysSettingPush');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else if (args.appid && typeof args.appid === 'number') {
|
|
179
|
+
vorpal.log(chalk_1["default"].blue('Uninstalling'));
|
|
180
|
+
client.sendMessage({ type: 'delete', appid: args.appid }, 'sysSettingPush');
|
|
181
|
+
}
|
|
182
|
+
else if (args.appid) {
|
|
183
|
+
vorpal.log("".concat(chalk_1["default"].red('error'), " invalid '").concat(args.appid, "', the 'uninstall' command should be followed by appid or blank."));
|
|
184
|
+
}
|
|
185
|
+
cb();
|
|
186
|
+
return [2];
|
|
170
187
|
});
|
|
171
188
|
}); });
|
|
172
189
|
};
|
|
173
190
|
var disConnectBridgeWSCallback = function () {
|
|
174
|
-
// 什么情况下会断开连接?
|
|
175
191
|
hasConnectDevice = false;
|
|
176
|
-
logger.log('
|
|
192
|
+
logger.log('Disconnected');
|
|
193
|
+
process.exit(1);
|
|
177
194
|
};
|
|
178
|
-
var bridge = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
195
|
+
var bridge = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
179
196
|
var bridgeWebSocketURL, error_1;
|
|
180
197
|
return __generator(this, function (_a) {
|
|
181
198
|
switch (_a.label) {
|
|
182
199
|
case 0:
|
|
183
|
-
_a.trys.push([0, 2, ,
|
|
184
|
-
return [4
|
|
185
|
-
// 第二步:连 WebSocket
|
|
186
|
-
];
|
|
200
|
+
_a.trys.push([0, 2, , 6]);
|
|
201
|
+
return [4, (0, index_1.getConnectDevServerWebSocketCode)()];
|
|
187
202
|
case 1:
|
|
188
203
|
bridgeWebSocketURL = _a.sent();
|
|
189
|
-
// 第二步:连 WebSocket
|
|
190
204
|
client = new websocket_1["default"]({
|
|
191
205
|
url: "".concat(bridgeWebSocketURL, "?type=development&name=CLI"),
|
|
192
206
|
connectCb: connectBridgeWSCallback,
|
|
193
207
|
disconnectCb: disConnectBridgeWSCallback
|
|
194
208
|
});
|
|
195
209
|
logger.log(" - Enter 'help' to view the command.");
|
|
196
|
-
return [3
|
|
210
|
+
return [3, 6];
|
|
197
211
|
case 2:
|
|
198
212
|
error_1 = _a.sent();
|
|
213
|
+
if (!((error_1 === null || error_1 === void 0 ? void 0 : error_1.message) === '401')) return [3, 4];
|
|
214
|
+
logger.warn("Login information is invalid. Please login again, or end this service and login again with the command 'zeus login'.");
|
|
215
|
+
return [4, (0, login_1.login)().then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
216
|
+
return __generator(this, function (_a) {
|
|
217
|
+
switch (_a.label) {
|
|
218
|
+
case 0:
|
|
219
|
+
args._loginAppToken = res.appToken;
|
|
220
|
+
process.env._loginAppToken = res.appToken;
|
|
221
|
+
return [4, (0, exports.bridge)(args)];
|
|
222
|
+
case 1:
|
|
223
|
+
_a.sent();
|
|
224
|
+
return [2];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}); })];
|
|
228
|
+
case 3:
|
|
229
|
+
_a.sent();
|
|
230
|
+
return [3, 5];
|
|
231
|
+
case 4:
|
|
199
232
|
logger.error(error_1 === null || error_1 === void 0 ? void 0 : error_1.message);
|
|
200
|
-
|
|
201
|
-
case
|
|
233
|
+
_a.label = 5;
|
|
234
|
+
case 5: return [3, 6];
|
|
235
|
+
case 6: return [2];
|
|
202
236
|
}
|
|
203
237
|
});
|
|
204
238
|
}); };
|
package/modules/build.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -59,7 +63,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
63
|
};
|
|
60
64
|
exports.__esModule = true;
|
|
61
65
|
exports.buildPreview = exports.buildProd = exports.buildDev = exports.build = exports.chooseBuildPackages = exports.BuildMode = void 0;
|
|
62
|
-
// @ts-ignore
|
|
63
66
|
var node_js_1 = require("@zeppos/zpm/lib/node.js");
|
|
64
67
|
var fs_1 = __importDefault(require("fs"));
|
|
65
68
|
var rd = __importStar(require("rd"));
|
|
@@ -71,10 +74,12 @@ var qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
|
71
74
|
var inquirer_1 = __importDefault(require("inquirer"));
|
|
72
75
|
var logger = __importStar(require("../utils/logger"));
|
|
73
76
|
var project_1 = require("../config/project");
|
|
74
|
-
var hm_analytics_1 = require("../utils/
|
|
77
|
+
var hm_analytics_1 = require("../utils/hm-analytics");
|
|
75
78
|
var api_1 = require("../api");
|
|
76
79
|
var storage_1 = require("./storage");
|
|
77
80
|
var common_1 = require("../utils/common");
|
|
81
|
+
var login_1 = require("./login");
|
|
82
|
+
var appJsonContent = fs_extra_1["default"].readJSONSync(path.resolve('./app.json'), { throws: false });
|
|
78
83
|
var BuildMode;
|
|
79
84
|
(function (BuildMode) {
|
|
80
85
|
BuildMode["DEV"] = "development";
|
|
@@ -89,37 +94,30 @@ var TransformType;
|
|
|
89
94
|
TransformType["Bin"] = "bin";
|
|
90
95
|
})(TransformType || (TransformType = {}));
|
|
91
96
|
function handleExecCommandInErrorDir(mode) {
|
|
92
|
-
// let curCommand = 'dev'
|
|
93
|
-
// if (mode === BuildMode.PROD) {
|
|
94
|
-
// curCommand = 'build'
|
|
95
|
-
// } else if (mode === BuildMode.PREVIEW) {
|
|
96
|
-
// curCommand = 'preview'
|
|
97
|
-
// }
|
|
98
97
|
logger.warn("This command needs to be executed in the root of the project.");
|
|
99
98
|
process.exit(1);
|
|
100
99
|
}
|
|
101
100
|
function chooseBuildPackages(mode) {
|
|
102
101
|
if (mode === void 0) { mode = 'development'; }
|
|
103
102
|
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
-
var
|
|
103
|
+
var targets, answers;
|
|
105
104
|
var _a, _b;
|
|
106
105
|
return __generator(this, function (_c) {
|
|
107
106
|
switch (_c.label) {
|
|
108
107
|
case 0:
|
|
109
|
-
|
|
110
|
-
if (!appJson) {
|
|
108
|
+
if (!appJsonContent) {
|
|
111
109
|
handleExecCommandInErrorDir(mode);
|
|
112
110
|
}
|
|
113
|
-
targets = Object.keys(lodash_1["default"].get(
|
|
114
|
-
if (!!targets.length) return [3
|
|
115
|
-
logger.error('
|
|
111
|
+
targets = Object.keys(lodash_1["default"].get(appJsonContent, 'targets', {}));
|
|
112
|
+
if (!!targets.length) return [3, 1];
|
|
113
|
+
logger.error('Please set at least one package.');
|
|
116
114
|
process.exit(1);
|
|
117
|
-
return [3
|
|
115
|
+
return [3, 4];
|
|
118
116
|
case 1:
|
|
119
|
-
if (!(targets.length === 1)) return [3
|
|
117
|
+
if (!(targets.length === 1)) return [3, 2];
|
|
120
118
|
storage_1.globalStorage.set((_a = {}, _a[project_1.buildStorageKey.targetDeviceToBuild] = targets[0], _a));
|
|
121
|
-
return [2
|
|
122
|
-
case 2: return [4
|
|
119
|
+
return [2, [targets[0]]];
|
|
120
|
+
case 2: return [4, inquirer_1["default"].prompt([
|
|
123
121
|
{
|
|
124
122
|
name: 'target',
|
|
125
123
|
type: 'list',
|
|
@@ -138,17 +136,14 @@ function chooseBuildPackages(mode) {
|
|
|
138
136
|
}); }),
|
|
139
137
|
message: 'Which targets would you like to build?'
|
|
140
138
|
}
|
|
141
|
-
])
|
|
142
|
-
// 存储 deviceSource
|
|
143
|
-
];
|
|
139
|
+
])];
|
|
144
140
|
case 3:
|
|
145
141
|
answers = _c.sent();
|
|
146
|
-
// 存储 deviceSource
|
|
147
142
|
if (BuildMode.PROD) {
|
|
148
|
-
storage_1.globalStorage.set((_b = {}, _b[project_1.buildStorageKey.targetDeviceToBuild] =
|
|
143
|
+
storage_1.globalStorage.set((_b = {}, _b[project_1.buildStorageKey.targetDeviceToBuild] = answers.target, _b));
|
|
149
144
|
}
|
|
150
|
-
return [2
|
|
151
|
-
case 4: return [2
|
|
145
|
+
return [2, mode !== BuildMode.PROD ? [answers.target] : answers.buildTargets];
|
|
146
|
+
case 4: return [2];
|
|
152
147
|
}
|
|
153
148
|
});
|
|
154
149
|
});
|
|
@@ -163,13 +158,13 @@ var build = function (mode, packages, buildConfigOption) {
|
|
|
163
158
|
switch (_b.label) {
|
|
164
159
|
case 0:
|
|
165
160
|
workspace = path.resolve('./');
|
|
166
|
-
if (!!packages.length) return [3
|
|
167
|
-
return [4
|
|
161
|
+
if (!!packages.length) return [3, 2];
|
|
162
|
+
return [4, chooseBuildPackages(mode)];
|
|
168
163
|
case 1:
|
|
169
164
|
choosePackages = _b.sent();
|
|
170
165
|
if (!choosePackages || !choosePackages.length) {
|
|
171
166
|
logger.error('please choose at least one package.');
|
|
172
|
-
return [2
|
|
167
|
+
return [2];
|
|
173
168
|
}
|
|
174
169
|
packages.push.apply(packages, choosePackages);
|
|
175
170
|
_b.label = 2;
|
|
@@ -178,7 +173,7 @@ var build = function (mode, packages, buildConfigOption) {
|
|
|
178
173
|
path: workspace,
|
|
179
174
|
targets: packages,
|
|
180
175
|
buildMode: mode,
|
|
181
|
-
jsc: TransformType.Default
|
|
176
|
+
jsc: TransformType.Default
|
|
182
177
|
};
|
|
183
178
|
if (mode === BuildMode.PROD || mode === BuildMode.PREVIEW) {
|
|
184
179
|
_a = buildConfigOption || {}, js2c = _a.js2c, js2bin = _a.js2bin, png2vg = _a.png2vg, prune = _a.prune;
|
|
@@ -203,8 +198,8 @@ var build = function (mode, packages, buildConfigOption) {
|
|
|
203
198
|
case 3:
|
|
204
199
|
_b.trys.push([3, 8, , 9]);
|
|
205
200
|
curTarget = (buildConfigOption ? buildConfigOption._ : [''])[0];
|
|
206
|
-
if (!(mode !== BuildMode.DEV || (mode === BuildMode.DEV && curTarget === 'install'))) return [3
|
|
207
|
-
return [4
|
|
201
|
+
if (!(mode !== BuildMode.DEV || (mode === BuildMode.DEV && curTarget === 'install'))) return [3, 5];
|
|
202
|
+
return [4, (0, node_js_1.start)(buildOptions)];
|
|
208
203
|
case 4:
|
|
209
204
|
buildInfo_1 = _b.sent();
|
|
210
205
|
if (buildInfo_1) {
|
|
@@ -215,19 +210,19 @@ var build = function (mode, packages, buildConfigOption) {
|
|
|
215
210
|
}
|
|
216
211
|
});
|
|
217
212
|
}
|
|
218
|
-
return [2
|
|
213
|
+
return [2, buildInfo_1];
|
|
219
214
|
case 5:
|
|
220
|
-
if (!(mode === BuildMode.DEV)) return [3
|
|
221
|
-
return [4
|
|
215
|
+
if (!(mode === BuildMode.DEV)) return [3, 7];
|
|
216
|
+
return [4, (0, node_js_1.startWithoutDist)(buildOptions)];
|
|
222
217
|
case 6:
|
|
223
218
|
_b.sent();
|
|
224
|
-
return [2
|
|
225
|
-
case 7: return [3
|
|
219
|
+
return [2, (0, node_js_1.getZpkBuf)(packages[0])];
|
|
220
|
+
case 7: return [3, 9];
|
|
226
221
|
case 8:
|
|
227
222
|
error_1 = _b.sent();
|
|
228
223
|
logger.error(error_1);
|
|
229
|
-
return [3
|
|
230
|
-
case 9: return [2
|
|
224
|
+
return [3, 9];
|
|
225
|
+
case 9: return [2];
|
|
231
226
|
}
|
|
232
227
|
});
|
|
233
228
|
});
|
|
@@ -242,7 +237,7 @@ var buildProd = function (args) { return __awaiter(void 0, void 0, void 0, funct
|
|
|
242
237
|
var buildInfo;
|
|
243
238
|
return __generator(this, function (_a) {
|
|
244
239
|
switch (_a.label) {
|
|
245
|
-
case 0: return [4
|
|
240
|
+
case 0: return [4, (0, exports.build)(BuildMode.PROD, [], args)];
|
|
246
241
|
case 1:
|
|
247
242
|
buildInfo = _a.sent();
|
|
248
243
|
if (buildInfo) {
|
|
@@ -251,76 +246,95 @@ var buildProd = function (args) { return __awaiter(void 0, void 0, void 0, funct
|
|
|
251
246
|
else {
|
|
252
247
|
(0, hm_analytics_1.HM_Analytics)('ZEPP_CLI_BUILD_C', { res: '0' });
|
|
253
248
|
}
|
|
254
|
-
return [2
|
|
249
|
+
return [2, buildInfo];
|
|
255
250
|
}
|
|
256
251
|
});
|
|
257
252
|
}); };
|
|
258
253
|
exports.buildProd = buildProd;
|
|
259
|
-
var checkIsWatchFaceProject = function () {
|
|
260
|
-
var appJsonPath = path.resolve('./app.json');
|
|
261
|
-
var appJsonContent = fs_extra_1["default"].readJsonSync(appJsonPath);
|
|
262
|
-
var appType = lodash_1["default"].get(appJsonContent, 'app.appType');
|
|
263
|
-
return appType === project_1.AppType.WATCHFACE;
|
|
264
|
-
};
|
|
265
254
|
var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0, function () {
|
|
266
|
-
var _a, curCommand, curBridgeTarget,
|
|
255
|
+
var _a, curCommand, curBridgeTarget, buildMode, buildInfo, appType, isWatchFaceProject, form;
|
|
267
256
|
return __generator(this, function (_b) {
|
|
268
257
|
switch (_b.label) {
|
|
269
258
|
case 0:
|
|
270
259
|
_a = args._, curCommand = _a[0], curBridgeTarget = _a[1];
|
|
271
|
-
form = new form_data_1["default"]();
|
|
272
260
|
buildMode = (curBridgeTarget && curBridgeTarget === 'simulator') ? BuildMode.DEV : BuildMode.PREVIEW;
|
|
273
261
|
logger.info('building...');
|
|
274
|
-
return [4
|
|
262
|
+
return [4, (0, exports.build)(buildMode, [], args)];
|
|
275
263
|
case 1:
|
|
276
264
|
buildInfo = _b.sent();
|
|
277
|
-
|
|
265
|
+
appType = lodash_1["default"].get(appJsonContent, 'app.appType');
|
|
266
|
+
isWatchFaceProject = appType === project_1.AppType.WATCHFACE;
|
|
278
267
|
logger.info('getting package...');
|
|
268
|
+
form = new form_data_1["default"]();
|
|
279
269
|
form.append('file', fs_1["default"].createReadStream("./dist/".concat(buildInfo)));
|
|
280
270
|
form.append('app_type', isWatchFaceProject ? '1' : '2');
|
|
281
271
|
form.getLength(function (err, length) { return __awaiter(void 0, void 0, void 0, function () {
|
|
282
|
-
var
|
|
272
|
+
var _a, _subRegionalHost, _accountEnv, protocol, code, res, error_2, url, _b, deviceSource, appId, appName, appType_1, deviceSourceArr, targetDeviceInternalName, packageInfo, url, preview, downloadPackageReturn;
|
|
283
273
|
return __generator(this, function (_c) {
|
|
284
274
|
switch (_c.label) {
|
|
285
275
|
case 0:
|
|
286
276
|
if (err) {
|
|
287
277
|
logger.error('getting package failed.');
|
|
288
|
-
return [2
|
|
278
|
+
return [2];
|
|
289
279
|
}
|
|
290
|
-
|
|
280
|
+
_a = process.env, _subRegionalHost = _a._subRegionalHost, _accountEnv = _a._accountEnv;
|
|
281
|
+
protocol = '';
|
|
282
|
+
code = '';
|
|
283
|
+
_c.label = 1;
|
|
291
284
|
case 1:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
285
|
+
_c.trys.push([1, 3, , 7]);
|
|
286
|
+
return [4, (0, api_1.uploadPackage)(form, length)];
|
|
287
|
+
case 2:
|
|
288
|
+
res = _c.sent();
|
|
289
|
+
protocol = res.protocol;
|
|
290
|
+
code = res.code;
|
|
291
|
+
return [3, 7];
|
|
292
|
+
case 3:
|
|
293
|
+
error_2 = _c.sent();
|
|
294
|
+
if (!((error_2 === null || error_2 === void 0 ? void 0 : error_2.message) === '401')) return [3, 5];
|
|
295
|
+
logger.warn("Login information is invalid. Please login again, or end this service and login again with the command 'zeus login'.");
|
|
296
|
+
return [4, (0, login_1.login)().then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
297
|
+
return __generator(this, function (_a) {
|
|
298
|
+
args._loginAppToken = res.appToken;
|
|
299
|
+
process.env._loginAppToken = res.appToken;
|
|
300
|
+
return [2, (0, exports.buildPreview)(args, cb)];
|
|
301
|
+
});
|
|
302
|
+
}); })];
|
|
303
|
+
case 4:
|
|
304
|
+
_c.sent();
|
|
305
|
+
return [3, 6];
|
|
306
|
+
case 5:
|
|
307
|
+
logger.error(error_2 === null || error_2 === void 0 ? void 0 : error_2.message);
|
|
308
|
+
return [2];
|
|
309
|
+
case 6: return [3, 7];
|
|
310
|
+
case 7:
|
|
311
|
+
if (!(curCommand === 'preview')) return [3, 8];
|
|
312
|
+
url = "".concat(protocol, "://").concat(_subRegionalHost, "/custom/tools/app-dial/download/").concat(code);
|
|
296
313
|
if (protocol && code) {
|
|
297
|
-
logger.info('
|
|
314
|
+
logger.info('Generating preview qrcode...');
|
|
298
315
|
logger.success('Below within two hours,please use Zepp APP to scan the qrcode below to preview your app.');
|
|
299
|
-
qrcode_terminal_1["default"].generate(
|
|
316
|
+
qrcode_terminal_1["default"].generate(url, { small: true });
|
|
300
317
|
}
|
|
301
318
|
else {
|
|
302
|
-
|
|
303
|
-
console.log('previewUrl', url);
|
|
304
|
-
}
|
|
305
|
-
logger.error('generating preview qrcode failed, please check your network.');
|
|
319
|
+
logger.error('Generating preview qrcode failed, please check your network.');
|
|
306
320
|
}
|
|
307
|
-
return [3
|
|
308
|
-
case
|
|
309
|
-
if (!(curCommand === 'install')) return [3
|
|
310
|
-
_b = (0, common_1.getDeviceInfoFromAppJson)(), deviceSource = _b.deviceSource, appId = _b.appId, appName = _b.appName,
|
|
311
|
-
return [4
|
|
312
|
-
case
|
|
321
|
+
return [3, 10];
|
|
322
|
+
case 8:
|
|
323
|
+
if (!(curCommand === 'install')) return [3, 10];
|
|
324
|
+
_b = (0, common_1.getDeviceInfoFromAppJson)(), deviceSource = _b.deviceSource, appId = _b.appId, appName = _b.appName, appType_1 = _b.appType, deviceSourceArr = _b.deviceSourceArr, targetDeviceInternalName = _b.targetDeviceInternalName;
|
|
325
|
+
return [4, (0, api_1.downloadPackage)(code, deviceSource, appType_1)];
|
|
326
|
+
case 9:
|
|
313
327
|
packageInfo = _c.sent();
|
|
314
|
-
downloadPackageReturn = lodash_1["default"].get(packageInfo, 'data', {});
|
|
315
328
|
url = packageInfo;
|
|
316
329
|
preview = '';
|
|
317
330
|
if (isWatchFaceProject) {
|
|
331
|
+
downloadPackageReturn = lodash_1["default"].get(packageInfo, 'data', {});
|
|
318
332
|
url = downloadPackageReturn.url;
|
|
319
333
|
preview = downloadPackageReturn.preview;
|
|
320
334
|
}
|
|
321
335
|
if (cb) {
|
|
322
336
|
cb({
|
|
323
|
-
appType:
|
|
337
|
+
appType: appType_1,
|
|
324
338
|
url: url,
|
|
325
339
|
preview: preview,
|
|
326
340
|
appid: appId,
|
|
@@ -331,12 +345,12 @@ var buildPreview = function (args, cb) { return __awaiter(void 0, void 0, void 0
|
|
|
331
345
|
target: targetDeviceInternalName
|
|
332
346
|
});
|
|
333
347
|
}
|
|
334
|
-
_c.label =
|
|
335
|
-
case
|
|
348
|
+
_c.label = 10;
|
|
349
|
+
case 10: return [2];
|
|
336
350
|
}
|
|
337
351
|
});
|
|
338
352
|
}); });
|
|
339
|
-
return [2
|
|
353
|
+
return [2];
|
|
340
354
|
}
|
|
341
355
|
});
|
|
342
356
|
}); };
|
package/modules/config.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -63,20 +67,20 @@ var lodash_1 = __importDefault(require("lodash"));
|
|
|
63
67
|
var chalk_1 = __importDefault(require("chalk"));
|
|
64
68
|
var storage_1 = require("./storage");
|
|
65
69
|
var logger = __importStar(require("../utils/logger"));
|
|
66
|
-
var hm_analytics_1 = require("../utils/
|
|
70
|
+
var hm_analytics_1 = require("../utils/hm-analytics");
|
|
67
71
|
var config = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
68
|
-
var
|
|
72
|
+
var cliName, _a, cmd, _b, method, values, allowedMethods, commonHandleNotKeyTips, config_1;
|
|
69
73
|
return __generator(this, function (_c) {
|
|
70
|
-
|
|
71
|
-
_a = lodash_1["default"].get(args, '_', []),
|
|
74
|
+
cliName = process.env.CMD_NAME;
|
|
75
|
+
_a = lodash_1["default"].get(args, '_', []), cmd = _a[0], _b = _a[1], method = _b === void 0 ? '' : _b, values = _a.slice(2);
|
|
72
76
|
allowedMethods = ['get', 'set', 'delete', 'list'];
|
|
73
77
|
if (!lodash_1["default"].includes(allowedMethods, method)) {
|
|
74
|
-
logger.error("invalid method: ".concat(method));
|
|
78
|
+
logger.error("invalid method: '".concat(method, "'"));
|
|
75
79
|
logger.log(chalk_1["default"].yellow('try to use one of the following:'));
|
|
76
|
-
logger.log("- ".concat(
|
|
77
|
-
logger.log("- ".concat(
|
|
78
|
-
logger.log("- ".concat(
|
|
79
|
-
logger.log("- ".concat(
|
|
80
|
+
logger.log("- ".concat(cliName, " ").concat(cmd, " set <key>=<value> [<key>=<value> ...]"));
|
|
81
|
+
logger.log("- ".concat(cliName, " ").concat(cmd, " get <key> [<key> ...]"));
|
|
82
|
+
logger.log("- ".concat(cliName, " ").concat(cmd, " delete <key> [<key> ...]"));
|
|
83
|
+
logger.log("- ".concat(cliName, " ").concat(cmd, " list [--json]"));
|
|
80
84
|
process.exit(0);
|
|
81
85
|
}
|
|
82
86
|
commonHandleNotKeyTips = function (method) {
|
|
@@ -103,7 +107,6 @@ var config = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|
|
103
107
|
logger.error('please input <key>');
|
|
104
108
|
}
|
|
105
109
|
else {
|
|
106
|
-
// TODO 需要知道 <key> 有那些,以便验证是否处理的没有遗漏
|
|
107
110
|
storage_1.globalStorage.set((_a = {}, _a[key] = value, _a));
|
|
108
111
|
logger.success("config: ".concat(key, "=").concat(value));
|
|
109
112
|
}
|
|
@@ -116,7 +119,6 @@ var config = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|
|
116
119
|
}
|
|
117
120
|
values.forEach(function (key) {
|
|
118
121
|
var curKey = key.trim();
|
|
119
|
-
// TODO 需要知道 <key> 有那些,以便验证是否处理的没有遗漏
|
|
120
122
|
if (!storage_1.globalStorage.has(key) || !key) {
|
|
121
123
|
logger.error('The <key> does not exist');
|
|
122
124
|
}
|
|
@@ -132,7 +134,6 @@ var config = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|
|
132
134
|
}
|
|
133
135
|
values.forEach(function (key) {
|
|
134
136
|
var curKey = key.trim();
|
|
135
|
-
// TODO 需要知道 <key> 有那些,以便验证是否处理的没有遗漏
|
|
136
137
|
if (!storage_1.globalStorage.has(key) || !key) {
|
|
137
138
|
logger.error('The <key> does not exist');
|
|
138
139
|
}
|
|
@@ -163,7 +164,7 @@ var config = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|
|
163
164
|
}
|
|
164
165
|
(0, hm_analytics_1.HM_Analytics)('ZEPP_CLI_CONFIG_C');
|
|
165
166
|
process.exit(0);
|
|
166
|
-
return [2
|
|
167
|
+
return [2];
|
|
167
168
|
});
|
|
168
169
|
}); };
|
|
169
170
|
exports.config = config;
|