@zeppos/zeus-cli 1.0.7 → 1.0.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.
package/config/device.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
- var _a;
2
+ var _a, _b;
3
3
  exports.__esModule = true;
4
- exports.deviceTargets = exports.DeviceScreenType = exports.DeviceSource = exports.DevicePlatformName = exports.DeviceTarget = void 0;
4
+ exports.deviceInternalCodename = exports.deviceTargets = exports.DeviceScreenType = exports.DeviceSource = exports.DevicePlatformName = exports.DeviceTarget = void 0;
5
5
  var DeviceTarget;
6
6
  (function (DeviceTarget) {
7
7
  DeviceTarget["MADRID"] = "madrid";
@@ -87,3 +87,11 @@ exports.deviceTargets = (_a = {},
87
87
  }
88
88
  },
89
89
  _a);
90
+ exports.deviceInternalCodename = (_b = {},
91
+ _b[DeviceSource.MADRID] = DeviceTarget.MADRID,
92
+ _b[DeviceSource.MADRIDW] = DeviceTarget.MADRID,
93
+ _b[DeviceSource.VERONA] = DeviceTarget.VERONA,
94
+ _b[DeviceSource.VERONAW] = DeviceTarget.VERONA,
95
+ _b[DeviceSource.ZURICH] = DeviceTarget.ZURICH,
96
+ _b[DeviceSource.ZURICHW] = DeviceTarget.ZURICH,
97
+ _b);
package/modules/build.js CHANGED
@@ -72,19 +72,17 @@ exports.__esModule = true;
72
72
  exports.buildPreview = exports.buildProd = exports.buildDev = exports.build = exports.chooseBuildPackages = exports.BuildMode = void 0;
73
73
  // @ts-ignore
74
74
  var node_js_1 = require("@zeppos/zpm/lib/node.js");
75
- var os_1 = __importDefault(require("os"));
76
75
  var fs_1 = __importDefault(require("fs"));
76
+ var rd = __importStar(require("rd"));
77
77
  var path = __importStar(require("path"));
78
78
  var lodash_1 = __importDefault(require("lodash"));
79
79
  var axios_1 = __importDefault(require("axios"));
80
80
  var url_1 = require("url");
81
81
  var fs_extra_1 = __importDefault(require("fs-extra"));
82
- var path_1 = require("path");
83
82
  var form_data_1 = __importDefault(require("form-data"));
84
83
  var qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
85
84
  var inquirer_1 = __importDefault(require("inquirer"));
86
85
  var login_1 = require("./login");
87
- var md5_1 = require("../utils/md5");
88
86
  var logger = __importStar(require("../utils/logger"));
89
87
  var STUDIO_URL = 'https://studio.huami.com';
90
88
  var BuildMode;
@@ -99,7 +97,7 @@ function chooseBuildPackages() {
99
97
  return __generator(this, function (_a) {
100
98
  switch (_a.label) {
101
99
  case 0:
102
- appJson = fs_extra_1["default"].readJSONSync((0, path_1.resolve)('./app.json'));
100
+ appJson = fs_extra_1["default"].readJSONSync(path.resolve('./app.json'));
103
101
  return [4 /*yield*/, inquirer_1["default"].prompt([
104
102
  {
105
103
  name: 'target',
@@ -120,19 +118,11 @@ var build = function (mode, packages) {
120
118
  if (mode === void 0) { mode = BuildMode.PROD; }
121
119
  if (packages === void 0) { packages = []; }
122
120
  return __awaiter(void 0, void 0, void 0, function () {
123
- var buildTempDir, choosedPackages, buildOptions, buildInfo, distPath;
121
+ var workspace, choosedPackages, buildOptions, buildInfo, DistDir_1;
124
122
  return __generator(this, function (_a) {
125
123
  switch (_a.label) {
126
124
  case 0:
127
- buildTempDir = '';
128
- try {
129
- buildTempDir = path.join(os_1["default"].tmpdir(), "zepp-" + (0, md5_1.md5)(path.resolve('./')));
130
- fs_extra_1["default"].copySync('./', buildTempDir);
131
- }
132
- catch (err) {
133
- logger.error('failed to copy project to temp dir');
134
- logger.log(err);
135
- }
125
+ workspace = path.resolve('./');
136
126
  if (!(mode === BuildMode.PROD)) return [3 /*break*/, 1];
137
127
  packages.length = 0;
138
128
  return [3 /*break*/, 3];
@@ -149,7 +139,7 @@ var build = function (mode, packages) {
149
139
  _a.label = 3;
150
140
  case 3:
151
141
  buildOptions = {
152
- path: buildTempDir,
142
+ path: workspace,
153
143
  targets: packages,
154
144
  buildMode: mode,
155
145
  jsc: '' // 不开启 js => c
@@ -161,10 +151,12 @@ var build = function (mode, packages) {
161
151
  case 4:
162
152
  buildInfo = _a.sent();
163
153
  if (buildInfo) {
164
- distPath = path.join('./', 'dist');
165
- fs_extra_1["default"].emptyDirSync(distPath);
166
- fs_extra_1["default"].copySync(path.join(buildTempDir, 'dist'), distPath);
167
- fs_extra_1["default"].removeSync(buildTempDir);
154
+ DistDir_1 = path.join(workspace, 'dist');
155
+ rd.eachFileSync(DistDir_1, function (file) {
156
+ if (file !== path.join(DistDir_1, buildInfo)) {
157
+ fs_extra_1["default"].removeSync(file);
158
+ }
159
+ });
168
160
  }
169
161
  return [2 /*return*/, buildInfo];
170
162
  }
package/modules/run.js CHANGED
@@ -71,8 +71,16 @@ var logger = __importStar(require("../utils/logger"));
71
71
  var build_1 = require("./build");
72
72
  var storage_1 = require("./storage");
73
73
  var simulator_1 = require("./simulator");
74
+ var device_1 = require("../config/device");
74
75
  var DEFAULT_HOST = '127.0.0.1';
75
76
  var DEFAULT_PORT = '7650';
77
+ var getDeviceInternalCodename = function (curTarget) {
78
+ var _a;
79
+ var appJsonFilePath = path.resolve('./app.json');
80
+ var appJsonContent = JSON.parse(fs_1["default"].readFileSync(appJsonFilePath, 'utf-8'));
81
+ var _b = ((_a = appJsonContent === null || appJsonContent === void 0 ? void 0 : appJsonContent.targets[curTarget]) === null || _a === void 0 ? void 0 : _a.platforms[0]).deviceSource, deviceSource = _b === void 0 ? 229 : _b;
82
+ return device_1.deviceInternalCodename[deviceSource];
83
+ };
76
84
  var run = function (args) { return __awaiter(void 0, void 0, void 0, function () {
77
85
  var storage, simulatorHost, simulatorPort, answer, hasStarted, packages, simulator, refreshSimulator;
78
86
  return __generator(this, function (_a) {
@@ -108,7 +116,7 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
108
116
  packages = _a.sent();
109
117
  simulator = new simulator_1.Simulator("http://" + simulatorHost + ":" + simulatorPort);
110
118
  refreshSimulator = lodash_1["default"].debounce(function () { return __awaiter(void 0, void 0, void 0, function () {
111
- var zabName, zabPath, uzipZabPath, zabFileList, zabBuffer, zpkFileName, projectName;
119
+ var zabName, zabPath, uzipZabPath, zabFileList, zabBuffer, zpkFileName, zpkPath, projectName, targetDeviceInternalName;
112
120
  return __generator(this, function (_a) {
113
121
  switch (_a.label) {
114
122
  case 0:
@@ -131,13 +139,15 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
131
139
  return lodash_1["default"].startsWith(fileName, packages[0] + ".");
132
140
  });
133
141
  if (zpkFileName) {
134
- zabBuffer = Buffer.from(fs_1["default"].readFileSync(path.resolve(uzipZabPath, "./" + zpkFileName)));
142
+ zpkPath = path.resolve(uzipZabPath, "./" + zpkFileName);
143
+ zabBuffer = Buffer.from(fs_1["default"].readFileSync(zpkPath));
135
144
  }
136
145
  }
137
146
  projectName = process.cwd().split('/').slice(-1)[0];
138
147
  if (zabBuffer.length) {
139
148
  logger.info('refrshing simulator...');
140
- simulator.upload(zabBuffer, projectName);
149
+ targetDeviceInternalName = getDeviceInternalCodename(packages[0]);
150
+ simulator.upload(zabBuffer, projectName, targetDeviceInternalName);
141
151
  }
142
152
  else {
143
153
  logger.error('can\'t find device package, pleace check the build result');
@@ -41,12 +41,13 @@ var Simulator = /** @class */ (function () {
41
41
  Simulator.prototype.emit = function (space, jsonData) {
42
42
  this.socket.emit(space, jsonData);
43
43
  };
44
- Simulator.prototype.upload = function (data, projectName) {
44
+ Simulator.prototype.upload = function (data, projectName, target) {
45
45
  var dataArr = this.uint8ToArray(new Uint8Array(data));
46
46
  var message = this.encodeMessage({
47
+ target: target,
48
+ projectName: projectName,
47
49
  size: data.byteLength,
48
- data: dataArr,
49
- projectName: projectName
50
+ data: dataArr
50
51
  });
51
52
  this.sendMessage(message);
52
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeppos/zeus-cli",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "zeus mini-program tools",
5
5
  "main": "index.js",
6
6
  "author": "zepp",
@@ -37,7 +37,7 @@
37
37
  "webpack": "^5.52.0"
38
38
  },
39
39
  "dependencies": {
40
- "@zeppos/zpm": "^2.1.32",
40
+ "@zeppos/zpm": "^2.1.37",
41
41
  "axios": "^0.23.0",
42
42
  "chalk": "^4.1.2",
43
43
  "chokidar": "^3.5.2",