aiot-toolkit 2.0.2-beta.4 → 2.0.2-beta.6

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.
@@ -66,6 +66,18 @@ class UxBuilder {
66
66
  name: 'enable-e2e',
67
67
  description: 'inject test-suite for current project',
68
68
  defaultValue: false
69
+ },
70
+ {
71
+ type: 'confirm',
72
+ name: 'enable-stats',
73
+ description: 'analyse time and size of webpack output files',
74
+ defaultValue: false
75
+ },
76
+ {
77
+ type: 'confirm',
78
+ name: 'optimize-css-attr',
79
+ description: 'optimize css attr',
80
+ defaultValue: false
69
81
  }
70
82
  ];
71
83
  }
@@ -2,9 +2,20 @@ import ParamType from '@aiot-toolkit/commander/lib/interface/IParam';
2
2
  import { IStartOptions } from '@aiot-toolkit/emulator';
3
3
  import UxBuilder from '../builder/UxBuilder';
4
4
  import IStarter from './IStarter';
5
+ /**
6
+ * UxStarter
7
+ * ux快应用启动器
8
+ */
5
9
  declare class UxStarter extends IStarter<IStartOptions> {
6
10
  builder: UxBuilder;
7
11
  params: ParamType[];
8
12
  start(projectPath: string, options: any): Promise<void>;
13
+ /**
14
+ * 检查选择的模拟器在当前环境下是否可以使用
15
+ * 下面的几种情况会导致模拟器不可用:1. 模拟器绑定的Vela镜像不存在;2. Vela4.0缺少coredump.core或者vela_data.bin文件
16
+ * @param avdName 模拟器名称
17
+ * @returns {boolean}
18
+ */
19
+ isAvailableEmulator(avdName: string): boolean;
9
20
  }
10
21
  export default UxStarter;
@@ -46,6 +46,11 @@ const portfinder_1 = __importDefault(require("portfinder"));
46
46
  const UxBuilder_1 = __importDefault(require("../builder/UxBuilder"));
47
47
  const VelaAvdUtils_1 = __importDefault(require("../utils/VelaAvdUtils"));
48
48
  const IStarter_1 = __importDefault(require("./IStarter"));
49
+ const fs_extra_1 = __importDefault(require("fs-extra"));
50
+ /**
51
+ * UxStarter
52
+ * ux快应用启动器
53
+ */
49
54
  class UxStarter extends IStarter_1.default {
50
55
  constructor() {
51
56
  super(...arguments);
@@ -74,9 +79,10 @@ class UxStarter extends IStarter_1.default {
74
79
  }
75
80
  start(projectPath, options) {
76
81
  return __awaiter(this, void 0, void 0, function* () {
82
+ // 获取已经创建的模拟器列表
77
83
  const avdList = VelaAvdUtils_1.default.velaAvdCls.getVelaAvdList();
78
84
  if (avdList.length === 0) {
79
- ColorConsole_1.default.error('### goldfish start ### No vela emulator available, please create it first.');
85
+ ColorConsole_1.default.error('no vela emulator available, please create it first.');
80
86
  VelaAvdUtils_1.default.createVelaAvdByInquire();
81
87
  return;
82
88
  }
@@ -86,6 +92,11 @@ class UxStarter extends IStarter_1.default {
86
92
  return { value: item.avdName };
87
93
  })
88
94
  });
95
+ // 检查选择的模拟器是否符合要求
96
+ if (!this.isAvailableEmulator(avdName)) {
97
+ ColorConsole_1.default.throw(`this emulator is unavailable, please create a new emulator.`);
98
+ return;
99
+ }
89
100
  let serverPort;
90
101
  // watch模型下开启server
91
102
  if (options.watch) {
@@ -104,19 +115,30 @@ class UxStarter extends IStarter_1.default {
104
115
  projectPath,
105
116
  compilerOption
106
117
  };
118
+ // 寻找对应的模拟器instance
107
119
  const goldfishInstance = (0, emulator_1.findInstance)(avdName, params);
108
120
  if (!goldfishInstance)
109
121
  return;
110
122
  let vncPort;
123
+ // 设置vncPort
111
124
  if (options.openVNC) {
112
125
  vncPort = yield portfinder_1.default.getPortPromise({ port: constants_1.defaultVncPort, stopPort: constants_1.defaultVncPort + 100 });
113
126
  }
127
+ // 设置adbPort
128
+ const adbPort = yield portfinder_1.default.getPortPromise({ port: constants_1.defaultAdbPort });
129
+ // 设置debugPort
130
+ let debugPort;
131
+ if (options.devtool) {
132
+ debugPort = yield portfinder_1.default.getPortPromise({ port: constants_1.defaultDebugPort });
133
+ }
114
134
  const startOptions = {
115
135
  avdName,
116
136
  devtool: options.devtool,
117
137
  disableNSH: options.disableNSH,
118
138
  serverPort,
119
139
  vncPort,
140
+ adbPort,
141
+ debugPort
120
142
  };
121
143
  goldfishInstance.start(startOptions);
122
144
  // waiter
@@ -137,5 +159,24 @@ class UxStarter extends IStarter_1.default {
137
159
  // startWaiter.start()
138
160
  });
139
161
  }
162
+ /**
163
+ * 检查选择的模拟器在当前环境下是否可以使用
164
+ * 下面的几种情况会导致模拟器不可用:1. 模拟器绑定的Vela镜像不存在;2. Vela4.0缺少coredump.core或者vela_data.bin文件
165
+ * @param avdName 模拟器名称
166
+ * @returns {boolean}
167
+ */
168
+ isAvailableEmulator(avdName) {
169
+ const { avdImagePath } = VelaAvdUtils_1.default.velaAvdCls.getVelaAvdInfo(avdName);
170
+ // 没有avdImagePath,即对应的configIni里没有 image.sysdir.1 字段
171
+ // 有avdImagePath,但是这个目录下没有nuttx
172
+ if (!avdImagePath || !fs_extra_1.default.existsSync(path_1.default.resolve(avdImagePath, 'nuttx'))) {
173
+ return false;
174
+ }
175
+ if (!avdImagePath.includes('0.0.2') &&
176
+ (!fs_extra_1.default.existsSync(path_1.default.resolve(avdImagePath, 'coredump.core')) || !fs_extra_1.default.existsSync(path_1.default.resolve(avdImagePath, 'vela_data.bin')))) {
177
+ return false;
178
+ }
179
+ return true;
180
+ }
140
181
  }
141
182
  exports.default = UxStarter;
@@ -7,6 +7,7 @@ declare class VelaAvdUtils {
7
7
  static emulatorBaseUrl: string;
8
8
  static systemImageBaseUrl: string;
9
9
  static velaAvdCls: VelaAvdCls;
10
+ /** 校验AVD名称 */
10
11
  static validateAvdName(avdName: string): true | "Please enter avd name" | "The avd name must starts with Vela" | "The avd already exists. Please change avd name";
11
12
  /**
12
13
  * 从CDN上下载资源文件
@@ -27,10 +28,20 @@ declare class VelaAvdUtils {
27
28
  static getEmulatorUrl(version?: string): string;
28
29
  /** 获取模拟器平台的名称,darwin-aarch64 linux-aarch64 windows-x86_64等 */
29
30
  static getEmulatorPlatform(): string;
31
+ /** 获取各项模拟器资源的根目录 */
30
32
  static getEmulatorEnvHome(resourceName: string): string;
31
- /** vela镜像需要更新 */
33
+ /**
34
+ * Vela镜像需要更新
35
+ * @param imageId 镜像id
36
+ * @returns {boolean}
37
+ */
32
38
  static velaImageNeedUpdate(imageId: string): boolean;
33
- /** vela镜像是否为zip包 */
39
+ /**
40
+ * Vela镜像是否为zip包(是否为0.0.2版本)
41
+ * 只有Vela开发版(dev, 0.0.2)这个版本的镜像不是zip包
42
+ * @param velaImage
43
+ * @returns
44
+ */
34
45
  static isZipInImageUrl(velaImage: string): boolean;
35
46
  /** 获取vela镜像的下载地址 */
36
47
  static getSystemImageUrl(version?: string): string;
@@ -25,6 +25,7 @@ const os_1 = __importDefault(require("os"));
25
25
  const path_1 = __importDefault(require("path"));
26
26
  const dayjs_1 = __importDefault(require("dayjs"));
27
27
  class VelaAvdUtils {
28
+ /** 校验AVD名称 */
28
29
  static validateAvdName(avdName) {
29
30
  if (!avdName) {
30
31
  return `Please enter avd name`;
@@ -116,16 +117,24 @@ class VelaAvdUtils {
116
117
  const hostOs = systemOs === 'win32' ? 'windows' : systemOs;
117
118
  return `${hostOs}-${hostArch}`;
118
119
  }
120
+ /** 获取各项模拟器资源的根目录 */
119
121
  static getEmulatorEnvHome(resourceName) {
120
122
  return path_1.default.resolve(VelaAvdUtils.sdkHome, resourceName);
121
123
  }
122
- /** vela镜像需要更新 */
124
+ /**
125
+ * Vela镜像需要更新
126
+ * @param imageId 镜像id
127
+ * @returns {boolean}
128
+ */
123
129
  static velaImageNeedUpdate(imageId) {
124
130
  // 兼容之前的version.json
125
- if (typeof imageId !== 'string')
131
+ if (typeof imageId !== 'string' || !imageId)
126
132
  return true;
127
133
  let avdImagePath = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', imageId, 'nuttx');
128
- if (fs_extra_1.default.existsSync(avdImagePath) && VelaAvdUtils.isZipInImageUrl(imageId)) {
134
+ if (!fs_extra_1.default.existsSync(avdImagePath)) {
135
+ return true;
136
+ }
137
+ if (VelaAvdUtils.isZipInImageUrl(imageId)) {
129
138
  const stats = fs_extra_1.default.statSync(avdImagePath);
130
139
  const version = constants_1.VelaImageVersionList.find((item) => item.value === imageId);
131
140
  if (version && (0, dayjs_1.default)(version.time).isAfter(stats.mtime, 'day'))
@@ -133,7 +142,12 @@ class VelaAvdUtils {
133
142
  }
134
143
  return false;
135
144
  }
136
- /** vela镜像是否为zip包 */
145
+ /**
146
+ * Vela镜像是否为zip包(是否为0.0.2版本)
147
+ * 只有Vela开发版(dev, 0.0.2)这个版本的镜像不是zip包
148
+ * @param velaImage
149
+ * @returns
150
+ */
137
151
  static isZipInImageUrl(velaImage) {
138
152
  return velaImage.indexOf('0.0.2') < 0;
139
153
  }
@@ -278,26 +292,18 @@ class VelaAvdUtils {
278
292
  ColorConsole_1.default.success(`Download emulator succeed.`);
279
293
  }
280
294
  // 下载镜像
281
- const velaImageDownloadUrl = this.getSystemImageUrl(velaImage);
282
295
  const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', velaImage);
283
- const imageExists = fs_extra_1.default.existsSync(path_1.default.resolve(imageDir, 'nuttx'));
284
- // 镜像不存在
285
- if (!imageExists) {
296
+ if (this.velaImageNeedUpdate(velaImage)) {
297
+ const velaImageDownloadUrl = this.getSystemImageUrl(velaImage);
286
298
  if (VelaAvdUtils.isZipInImageUrl(velaImage)) {
287
299
  yield VelaAvdUtils.downloadAndUnzip(velaImageDownloadUrl, imageDir);
300
+ currVersionInfo['system-images'] = constants_1.EmulatorEnvVersion['system-images'];
288
301
  }
289
302
  else {
290
303
  yield VelaAvdUtils.downloadFromCdn(velaImageDownloadUrl, imageDir, 'nuttx');
291
304
  }
292
305
  ColorConsole_1.default.success(`Download vela image succeed.`);
293
306
  }
294
- else {
295
- // 镜像版本过低
296
- if (VelaAvdUtils.isZipInImageUrl(velaImage) && VelaAvdUtils.velaImageNeedUpdate(velaImage)) {
297
- yield VelaAvdUtils.downloadAndUnzip(velaImageDownloadUrl, imageDir);
298
- ColorConsole_1.default.success(`Download vela image succeed.`);
299
- }
300
- }
301
307
  // 下载快应用qa文件
302
308
  if (!qaExist || (currVersionInfo && currVersionInfo.qa < onlineVersionInfo.qa)) {
303
309
  const qaUrl = VelaAvdUtils.getDownloadUrl('qa', onlineVersionInfo.qa);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiot-toolkit",
3
- "version": "2.0.2-beta.4",
3
+ "version": "2.0.2-beta.6",
4
4
  "description": "Tools for creating, developing, and packaging aiot applications.",
5
5
  "keywords": [
6
6
  "aiot"
@@ -21,25 +21,28 @@
21
21
  "test": "node ./__tests__/aiot-toolkit.test.js"
22
22
  },
23
23
  "dependencies": {
24
- "@aiot-toolkit/commander": "2.0.2-beta.4",
25
- "@aiot-toolkit/emulator": "2.0.2-beta.4",
26
- "@aiot-toolkit/shared-utils": "2.0.2-beta.4",
24
+ "@aiot-toolkit/commander": "2.0.2-beta.6",
25
+ "@aiot-toolkit/emulator": "2.0.2-beta.6",
26
+ "@aiot-toolkit/shared-utils": "2.0.2-beta.6",
27
27
  "@miwt/adb": "^0.7.1",
28
28
  "adb-commander": "^0.1.9",
29
29
  "adm-zip": "^0.5.10",
30
30
  "axios": "^1.5.0",
31
31
  "cli-progress": "^3.12.0",
32
- "create-aiot": "2.0.2-beta.4",
32
+ "create-aiot": "2.0.2-beta.6",
33
33
  "dayjs": "^1.11.10",
34
34
  "fast-glob": "^3.3.2",
35
- "file-lane": "2.0.2-beta.4",
35
+ "file-lane": "2.0.2-beta.6",
36
+ "lodash": "^4.17.21",
36
37
  "semver": "^7.6.0",
37
38
  "ws": "^8.15.1"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@types/adm-zip": "^0.5.4",
42
+ "@types/fs-extra": "^11.0.4",
41
43
  "@types/semver": "^7.5.8",
42
- "@types/ws": "^8.5.10"
44
+ "@types/ws": "^8.5.10",
45
+ "fs-extra": "^11.2.0"
43
46
  },
44
- "gitHead": "656add8e64d8101b9f3886957c5b9ae23e2e854f"
47
+ "gitHead": "b9b99afff176075380c2ec95b43797d696c393c1"
45
48
  }