aiot-toolkit 2.0.1-alpha.9 → 2.0.2-batchmanifest-beta.1

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 (41) hide show
  1. package/README.md +32 -29
  2. package/lib/bin.js +110 -41
  3. package/lib/builder/IBuilder.js +0 -2
  4. package/lib/builder/UxBuilder.d.ts +9 -0
  5. package/lib/builder/UxBuilder.js +69 -23
  6. package/lib/builder/XtsBuilder.js +30 -12
  7. package/lib/interface/CommandInterface.js +0 -2
  8. package/lib/interface/VelaEmulatorInterface.d.ts +6 -0
  9. package/lib/interface/VelaEmulatorInterface.js +0 -2
  10. package/lib/starter/IStarter.d.ts +23 -0
  11. package/lib/starter/IStarter.js +39 -0
  12. package/lib/starter/UxStarter.d.ts +21 -0
  13. package/lib/starter/UxStarter.js +186 -0
  14. package/lib/starter/XtsStarter.d.ts +9 -0
  15. package/lib/starter/XtsStarter.js +19 -0
  16. package/lib/utils/AdbUtils.js +2 -11
  17. package/lib/utils/BatchBuild.d.ts +8 -0
  18. package/lib/utils/BatchBuild.js +69 -0
  19. package/lib/utils/DeviceUtil.d.ts +1 -1
  20. package/lib/utils/DeviceUtil.js +22 -93
  21. package/lib/utils/RequestUtils.js +4 -19
  22. package/lib/utils/UxBuilderUtils.d.ts +8 -0
  23. package/lib/utils/UxBuilderUtils.js +51 -0
  24. package/lib/utils/VelaAvdUtils.d.ts +26 -4
  25. package/lib/utils/VelaAvdUtils.js +263 -134
  26. package/lib/waiter.js +0 -2
  27. package/package.json +17 -11
  28. package/lib/bin.js.map +0 -1
  29. package/lib/builder/IBuilder.js.map +0 -1
  30. package/lib/builder/UxBuilder.js.map +0 -1
  31. package/lib/builder/XtsBuilder.js.map +0 -1
  32. package/lib/interface/CommandInterface.js.map +0 -1
  33. package/lib/interface/VelaEmulatorInterface.js.map +0 -1
  34. package/lib/starter/GoldfishStarter.d.ts +0 -9
  35. package/lib/starter/GoldfishStarter.js +0 -108
  36. package/lib/starter/GoldfishStarter.js.map +0 -1
  37. package/lib/utils/AdbUtils.js.map +0 -1
  38. package/lib/utils/DeviceUtil.js.map +0 -1
  39. package/lib/utils/RequestUtils.js.map +0 -1
  40. package/lib/utils/VelaAvdUtils.js.map +0 -1
  41. package/lib/waiter.js.map +0 -1
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
7
+ /**
8
+ * UxBuilderUtils
9
+ */
10
+ class UxBuilderUtils {
11
+ static getDevtoolValue(mode, devtool) {
12
+ const sourcemaps = {
13
+ development: {
14
+ default: 'cheap-source-map',
15
+ options: [
16
+ false,
17
+ 'cheap-source-map',
18
+ 'cheap-module-source-map',
19
+ 'inline-cheap-source-map',
20
+ 'inline-cheap-module-source-map',
21
+ 'source-map',
22
+ 'inline-source-map',
23
+ 'hidden-source-map',
24
+ 'nosources-source-map'
25
+ ]
26
+ },
27
+ production: {
28
+ default: false,
29
+ options: [
30
+ false,
31
+ 'cheap-source-map',
32
+ 'cheap-module-source-map',
33
+ 'source-map',
34
+ 'hidden-source-map',
35
+ 'nosources-source-map'
36
+ ]
37
+ }
38
+ };
39
+ const sourcemapArr = sourcemaps[mode].options;
40
+ const defaultSourcemap = sourcemaps[mode].default;
41
+ if (typeof devtool !== 'string' && typeof devtool !== 'boolean') {
42
+ return defaultSourcemap;
43
+ }
44
+ if (sourcemapArr.indexOf(devtool) === -1) {
45
+ ColorConsole_1.default.warn(`The devtool in ${mode} mode does not support '${devtool}', change to default '${defaultSourcemap}'`);
46
+ return defaultSourcemap;
47
+ }
48
+ return devtool;
49
+ }
50
+ }
51
+ exports.default = UxBuilderUtils;
@@ -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上下载资源文件
@@ -25,15 +26,36 @@ declare class VelaAvdUtils {
25
26
  static downloadAndUnzip(downloadUrl: string, targetDir: string): Promise<void>;
26
27
  /** 根据host获取模拟器下载地址 */
27
28
  static getEmulatorUrl(version?: string): string;
28
- /** 根据host获取vela镜像下载地址 */
29
- static getSystemImageUrl(version?: string, device?: string): string;
29
+ /** 获取模拟器平台的名称,darwin-aarch64 linux-aarch64 windows-x86_64等 */
30
+ static getEmulatorPlatform(): string;
31
+ /** 获取各项模拟器资源的根目录 */
32
+ static getEmulatorEnvHome(resourceName: string): string;
33
+ /**
34
+ * Vela镜像需要更新
35
+ * @param imageId 镜像id
36
+ * @returns {boolean}
37
+ */
38
+ static velaImageNeedUpdate(imageId: string): boolean;
39
+ /**
40
+ * Vela镜像是否为zip包(是否为0.0.2版本)
41
+ * 只有Vela开发版(dev, 0.0.2)这个版本的镜像不是zip包
42
+ * @param velaImage
43
+ * @returns
44
+ */
45
+ static isZipInImageUrl(velaImage: string): boolean;
46
+ /** 获取vela镜像的下载地址 */
47
+ static getSystemImageUrl(version?: string): string;
48
+ /** 获取模拟器其他资源的下载地址 */
49
+ static getDownloadUrl(dir: string, version?: string, filename?: string): string;
30
50
  /** 根据host获取ya-vm-file-server下载地址 */
31
51
  static getv9fsToolUrl(version?: string): string;
32
- /** 获取资源文件下载地址 */
33
- static getDownloadUrl(file: string, version?: string): string;
52
+ /** 获取镜像构建时间 */
53
+ static getImageBuildTime(imageId: string): string | Date | undefined;
34
54
  /**
35
55
  * 命令行访问方式创建模拟器
36
56
  */
37
57
  static createVelaAvdByInquire(): Promise<void>;
58
+ /** 初始化/重置模拟器环境 */
59
+ static initEmulatorEnv(): Promise<void>;
38
60
  }
39
61
  export default VelaAvdUtils;
@@ -13,7 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const emulator_1 = require("@aiot-toolkit/emulator");
16
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
+ const constants_1 = require("@aiot-toolkit/emulator/lib/static/constants");
17
+ const utils_1 = require("@aiot-toolkit/emulator/lib/utils");
17
18
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
18
19
  const prompts_1 = require("@inquirer/prompts");
19
20
  const adm_zip_1 = __importDefault(require("adm-zip"));
@@ -22,7 +23,9 @@ const cli_progress_1 = __importDefault(require("cli-progress"));
22
23
  const fs_extra_1 = __importDefault(require("fs-extra"));
23
24
  const os_1 = __importDefault(require("os"));
24
25
  const path_1 = __importDefault(require("path"));
26
+ const dayjs_1 = __importDefault(require("dayjs"));
25
27
  class VelaAvdUtils {
28
+ /** 校验AVD名称 */
26
29
  static validateAvdName(avdName) {
27
30
  if (!avdName) {
28
31
  return `Please enter avd name`;
@@ -68,11 +71,7 @@ class VelaAvdUtils {
68
71
  });
69
72
  }
70
73
  catch (e) {
71
- ColorConsole_1.default.log({
72
- level: shared_utils_1.LOG_LEVEL.Error,
73
- message: `download ${filename} failed`
74
- });
75
- progress.stop();
74
+ ColorConsole_1.default.throw(`Download ${filename} failed`);
76
75
  reject();
77
76
  }
78
77
  }));
@@ -107,34 +106,68 @@ class VelaAvdUtils {
107
106
  /** 根据host获取模拟器下载地址 */
108
107
  static getEmulatorUrl(version = '0.0.1') {
109
108
  const systemOs = os_1.default.platform();
110
- const arch = os_1.default.arch();
111
- let hostOs = '';
112
- let hostArch = '';
113
- switch (systemOs) {
114
- case 'linux':
115
- hostOs = 'linux';
116
- hostArch = arch === 'x64' ? 'x86_64' : 'aarch64';
117
- break;
118
- case 'win32':
119
- hostOs = 'windows';
120
- hostArch = arch === 'x64' ? 'x86_64' : 'aarch64';
121
- break;
122
- case 'darwin':
123
- hostOs = 'darwin';
124
- hostArch = arch === 'x64' ? 'x86_64' : 'aarch64';
125
- default:
126
- break;
127
- }
109
+ const hostArch = (0, utils_1.getSystemArch)();
110
+ let hostOs = systemOs === 'win32' ? 'windows' : systemOs;
128
111
  return `${VelaAvdUtils.emulatorBaseUrl}/v${version}/${hostOs}-${hostArch}.zip`;
129
112
  }
130
- /** 根据host获取vela镜像下载地址 */
131
- static getSystemImageUrl(version = '0.0.1', device = 'arm') {
132
- return `${VelaAvdUtils.systemImageBaseUrl}/v${version}/${device}/nuttx`;
113
+ /** 获取模拟器平台的名称,darwin-aarch64 linux-aarch64 windows-x86_64等 */
114
+ static getEmulatorPlatform() {
115
+ const systemOs = os_1.default.platform();
116
+ const hostArch = (0, utils_1.getSystemArch)();
117
+ const hostOs = systemOs === 'win32' ? 'windows' : systemOs;
118
+ return `${hostOs}-${hostArch}`;
119
+ }
120
+ /** 获取各项模拟器资源的根目录 */
121
+ static getEmulatorEnvHome(resourceName) {
122
+ return path_1.default.resolve(VelaAvdUtils.sdkHome, resourceName);
123
+ }
124
+ /**
125
+ * Vela镜像需要更新
126
+ * @param imageId 镜像id
127
+ * @returns {boolean}
128
+ */
129
+ static velaImageNeedUpdate(imageId) {
130
+ // 兼容之前的version.json
131
+ if (typeof imageId !== 'string' || !imageId)
132
+ return true;
133
+ let avdImagePath = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', imageId, 'nuttx');
134
+ if (!fs_extra_1.default.existsSync(avdImagePath)) {
135
+ return true;
136
+ }
137
+ if (VelaAvdUtils.isZipInImageUrl(imageId)) {
138
+ const stats = fs_extra_1.default.statSync(avdImagePath);
139
+ const version = constants_1.VelaImageVersionList.find((item) => item.value === imageId);
140
+ if (version && (0, dayjs_1.default)(version.time).isAfter(stats.mtime, 'day'))
141
+ return true;
142
+ }
143
+ return false;
144
+ }
145
+ /**
146
+ * Vela镜像是否为zip包(是否为0.0.2版本)
147
+ * 只有Vela开发版(dev, 0.0.2)这个版本的镜像不是zip包
148
+ * @param velaImage
149
+ * @returns
150
+ */
151
+ static isZipInImageUrl(velaImage) {
152
+ return velaImage.indexOf('0.0.2') < 0;
153
+ }
154
+ /** 获取vela镜像的下载地址 */
155
+ static getSystemImageUrl(version = 'vela-release-4.0') {
156
+ if (VelaAvdUtils.isZipInImageUrl(version)) {
157
+ const velaImage = constants_1.VelaImageVersionList.find((item) => item.value = version);
158
+ const dayOfTime = (0, dayjs_1.default)(velaImage === null || velaImage === void 0 ? void 0 : velaImage.time).format('YYYYMMDD');
159
+ return `${VelaAvdUtils.systemImageBaseUrl}/${version}/${dayOfTime}/${version}.zip`;
160
+ }
161
+ return `${VelaAvdUtils.systemImageBaseUrl}/${version}/nuttx`;
162
+ }
163
+ /** 获取模拟器其他资源的下载地址 */
164
+ static getDownloadUrl(dir, version = '0.0.1', filename = dir) {
165
+ return `${VelaAvdUtils.baseUrl}/${dir}/v${version}/${filename}.zip`;
133
166
  }
134
167
  /** 根据host获取ya-vm-file-server下载地址 */
135
168
  static getv9fsToolUrl(version = '0.0.1') {
136
169
  const systemOs = os_1.default.platform();
137
- const arch = os_1.default.arch();
170
+ const arch = (0, utils_1.getSystemArch)();
138
171
  let v9fsTool = '';
139
172
  switch (systemOs) {
140
173
  case 'linux':
@@ -144,32 +177,58 @@ class VelaAvdUtils {
144
177
  v9fsTool = 'ya-vm-file-server-windows.exe';
145
178
  break;
146
179
  case 'darwin':
147
- v9fsTool = (arch === 'x64') ? 'ya-vm-file-server-darwin-x84_64' : 'ya-vm-file-server-darwin-aarch64';
180
+ v9fsTool = `ya-vm-file-server-darwin-${arch}`;
181
+ break;
148
182
  default:
149
183
  break;
150
184
  }
151
185
  return `${VelaAvdUtils.baseUrl}/tools/v${version}/${v9fsTool}`;
152
186
  }
153
- /** 获取资源文件下载地址 */
154
- static getDownloadUrl(file, version = '0.0.1') {
155
- return `${VelaAvdUtils.baseUrl}/${file}/v${version}/${file}.zip`;
187
+ /** 获取镜像构建时间 */
188
+ static getImageBuildTime(imageId) {
189
+ var _a;
190
+ if (!imageId)
191
+ return;
192
+ const imagePath = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', imageId, 'nuttx');
193
+ if (fs_extra_1.default.existsSync(imagePath)) {
194
+ if (VelaAvdUtils.isZipInImageUrl(imageId)) {
195
+ const stats = fs_extra_1.default.statSync(imagePath);
196
+ return stats.mtime;
197
+ }
198
+ else {
199
+ const time = (_a = constants_1.VelaImageVersionList.find((item) => item.value === imageId)) === null || _a === void 0 ? void 0 : _a.time;
200
+ return time;
201
+ }
202
+ }
203
+ return;
156
204
  }
157
205
  /**
158
206
  * 命令行访问方式创建模拟器
159
207
  */
160
208
  static createVelaAvdByInquire() {
161
209
  return __awaiter(this, void 0, void 0, function* () {
210
+ const versionFile = path_1.default.resolve(VelaAvdUtils.sdkHome, 'versions.json');
211
+ const versionFileExist = fs_extra_1.default.existsSync(versionFile);
212
+ let currVersionInfo = {
213
+ name: '模拟器资源版本管理',
214
+ emulator: '',
215
+ qa: '',
216
+ skins: '',
217
+ 'system-images': '',
218
+ tools: '',
219
+ modem_simulator: ''
220
+ };
221
+ if (versionFileExist) {
222
+ currVersionInfo = fs_extra_1.default.readJSONSync(versionFile);
223
+ }
224
+ const onlineVersionInfo = constants_1.EmulatorEnvVersion;
225
+ // 模拟器各项资源(除了镜像)是否存在
226
+ const emulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'emulator', VelaAvdUtils.getEmulatorPlatform()));
227
+ const qaExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'qa/font'));
228
+ const skinsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
229
+ const toolsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'tools'));
230
+ const modemSimulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'modem_simulator/modem_nvram.json'));
162
231
  try {
163
- const versionFile = path_1.default.resolve(VelaAvdUtils.sdkHome, 'versions.json');
164
- const versionFileExist = fs_extra_1.default.existsSync(versionFile);
165
- let versionInfo = undefined;
166
- if (versionFileExist) {
167
- versionInfo = fs_extra_1.default.readJSONSync(versionFile);
168
- }
169
- // 下载version.json,保证每次下载的文件都是最新的版本
170
- yield VelaAvdUtils.downloadFromCdn(VelaAvdUtils.versionUrl, VelaAvdUtils.sdkHome, 'online-version.json');
171
- const onlineVersionFile = path_1.default.resolve(VelaAvdUtils.sdkHome, 'online-version.json');
172
- const onlineVersionInfo = fs_extra_1.default.readJSONSync(onlineVersionFile);
173
232
  // avdName
174
233
  const avdName = yield (0, prompts_1.input)({
175
234
  message: 'avd name starting with Vela. (eg. Vela_Virtual_Device)',
@@ -178,117 +237,189 @@ class VelaAvdUtils {
178
237
  return VelaAvdUtils.validateAvdName(value);
179
238
  }
180
239
  });
240
+ // 镜像
241
+ const velaImage = (yield (0, prompts_1.select)({
242
+ message: 'vela image.',
243
+ choices: constants_1.VelaImageVersionList.map((item) => {
244
+ return { value: item.value, name: item.label };
245
+ })
246
+ }));
181
247
  // skin或者size
182
- const needSkin = yield (0, prompts_1.confirm)({
183
- message: 'need avd skin?',
184
- default: true
185
- });
186
- const skinDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins');
187
- const skinExists = fs_extra_1.default.existsSync(skinDir);
188
248
  let avdSkin = '';
189
- let avdWidth = '';
190
- let avdHeight = '';
191
- if (needSkin) {
192
- if (!skinExists || (versionInfo && versionInfo.skins < onlineVersionInfo.skins)) {
193
- const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', onlineVersionInfo.skins);
194
- yield VelaAvdUtils.downloadAndUnzip(skinsUrl, path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
195
- ColorConsole_1.default.log({
196
- level: shared_utils_1.LOG_LEVEL.Success,
197
- message: `download skins succeed.`
249
+ let avdWidth = '466';
250
+ let avdHeight = '466';
251
+ // vela4.0不允许自定义分辨率
252
+ if (velaImage.indexOf('vela-release') < 0) {
253
+ const needSkin = yield (0, prompts_1.confirm)({
254
+ message: 'need avd skin?',
255
+ default: true
256
+ });
257
+ if (needSkin) {
258
+ if (!skinsExist || (currVersionInfo && currVersionInfo.skins < onlineVersionInfo.skins)) {
259
+ const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', onlineVersionInfo.skins);
260
+ yield VelaAvdUtils.downloadAndUnzip(skinsUrl, path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
261
+ currVersionInfo.skins = constants_1.EmulatorEnvVersion.skins;
262
+ ColorConsole_1.default.success(`Download skins succeed.`);
263
+ }
264
+ const skinList = VelaAvdUtils.velaAvdCls.getVelaSkinList();
265
+ avdSkin = yield (0, prompts_1.select)({
266
+ message: 'avd skin.',
267
+ choices: skinList.map((item) => {
268
+ return {
269
+ name: item,
270
+ value: item,
271
+ description: item
272
+ };
273
+ })
274
+ });
275
+ }
276
+ else {
277
+ avdWidth = yield (0, prompts_1.input)({
278
+ message: 'avd width.',
279
+ default: '466'
280
+ });
281
+ avdHeight = yield (0, prompts_1.input)({
282
+ message: 'avd height.',
283
+ default: '466'
198
284
  });
199
285
  }
200
- const skinList = VelaAvdUtils.velaAvdCls.getVelaSkinList();
201
- avdSkin = yield (0, prompts_1.select)({
202
- message: 'avd skin.',
203
- choices: skinList.map((item) => {
204
- return {
205
- name: item,
206
- value: item,
207
- description: item
208
- };
209
- })
210
- });
211
- }
212
- else {
213
- avdWidth = yield (0, prompts_1.input)({
214
- message: 'avd width.',
215
- default: '480'
216
- });
217
- avdHeight = yield (0, prompts_1.input)({
218
- message: 'avd height.',
219
- default: '480'
220
- });
221
286
  }
222
- // 镜像,TODO:后续需要考虑多种设备的镜像
223
- const avdArch = (yield (0, prompts_1.select)({
224
- message: 'vela image.',
225
- choices: [{ value: 'arm' }, { value: 'arm64' }]
226
- }));
227
287
  // 下载模拟器
228
- const emulatorDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'emulator');
229
- const emulatorExists = fs_extra_1.default.existsSync(emulatorDir);
230
- if (!emulatorExists || (versionInfo && versionInfo.emulator < onlineVersionInfo.emulator)) {
288
+ if (!emulatorExist || (currVersionInfo && currVersionInfo.emulator < onlineVersionInfo.emulator)) {
231
289
  const emulatorDownloadUrl = VelaAvdUtils.getEmulatorUrl(onlineVersionInfo.emulator);
232
- yield VelaAvdUtils.downloadAndUnzip(emulatorDownloadUrl, emulatorDir);
233
- ColorConsole_1.default.log({
234
- level: shared_utils_1.LOG_LEVEL.Success,
235
- message: `download emulator succeed.`
236
- });
290
+ yield VelaAvdUtils.downloadAndUnzip(emulatorDownloadUrl, VelaAvdUtils.getEmulatorEnvHome('emulator'));
291
+ currVersionInfo.emulator = constants_1.EmulatorEnvVersion.emulator;
292
+ ColorConsole_1.default.success(`Download emulator succeed.`);
237
293
  }
238
294
  // 下载镜像
239
- const velaImageDownloadUrl = this.getSystemImageUrl(onlineVersionInfo['system-images'], avdArch);
240
- const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', avdArch);
241
- const imageExists = fs_extra_1.default.existsSync(path_1.default.resolve(imageDir, 'nuttx'));
242
- if (!imageExists ||
243
- (versionInfo && versionInfo['system-images'] < onlineVersionInfo['system-images'])) {
244
- yield VelaAvdUtils.downloadFromCdn(velaImageDownloadUrl, imageDir, 'nuttx');
245
- ColorConsole_1.default.log({
246
- level: shared_utils_1.LOG_LEVEL.Success,
247
- message: `download vela image succeed.`
248
- });
295
+ const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', velaImage);
296
+ if (this.velaImageNeedUpdate(velaImage)) {
297
+ const velaImageDownloadUrl = this.getSystemImageUrl(velaImage);
298
+ if (VelaAvdUtils.isZipInImageUrl(velaImage)) {
299
+ yield VelaAvdUtils.downloadAndUnzip(velaImageDownloadUrl, imageDir);
300
+ currVersionInfo['system-images'] = constants_1.EmulatorEnvVersion['system-images'];
301
+ }
302
+ else {
303
+ yield VelaAvdUtils.downloadFromCdn(velaImageDownloadUrl, imageDir, 'nuttx');
304
+ }
305
+ ColorConsole_1.default.success(`Download vela image succeed.`);
249
306
  }
250
307
  // 下载快应用qa文件
251
- const qaDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'qa');
252
- const qaExists = fs_extra_1.default.existsSync(qaDir);
253
- if (!qaExists || (versionInfo && versionInfo.qa < onlineVersionInfo.qa)) {
308
+ if (!qaExist || (currVersionInfo && currVersionInfo.qa < onlineVersionInfo.qa)) {
254
309
  const qaUrl = VelaAvdUtils.getDownloadUrl('qa', onlineVersionInfo.qa);
255
- yield VelaAvdUtils.downloadAndUnzip(qaUrl, qaDir);
256
- ColorConsole_1.default.log({
257
- level: shared_utils_1.LOG_LEVEL.Success,
258
- message: `download quickapp font succeed.`
259
- });
310
+ yield VelaAvdUtils.downloadAndUnzip(qaUrl, VelaAvdUtils.getEmulatorEnvHome('qa'));
311
+ currVersionInfo.qa = constants_1.EmulatorEnvVersion.qa;
312
+ ColorConsole_1.default.success(`Download quickapp font succeed.`);
260
313
  }
261
314
  // 下载tools
262
- const toolsDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'tools');
263
- const toolsExists = fs_extra_1.default.existsSync(toolsDir);
264
- if (!toolsExists || (versionInfo && versionInfo.tools < onlineVersionInfo.tools)) {
315
+ if (!toolsExist || (currVersionInfo && currVersionInfo.tools < onlineVersionInfo.tools)) {
265
316
  const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl();
266
- const filename = (os_1.default.platform() === 'win32') ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
267
- yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, toolsDir, filename);
268
- ColorConsole_1.default.log({
269
- level: shared_utils_1.LOG_LEVEL.Success,
270
- message: `download tools succeed.`
271
- });
317
+ const filename = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
318
+ yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, VelaAvdUtils.getEmulatorEnvHome('tools'), filename);
319
+ currVersionInfo.tools = constants_1.EmulatorEnvVersion.tools;
320
+ ColorConsole_1.default.success(`Download tools succeed.`);
272
321
  }
273
- // 替换version.json
274
- if (versionFileExist) {
275
- fs_extra_1.default.rmSync(versionFile);
322
+ // 下载modem_simulator
323
+ if (!modemSimulatorExist || currVersionInfo.modem_simulator < constants_1.EmulatorEnvVersion.modem_simulator) {
324
+ const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', constants_1.EmulatorEnvVersion.modem_simulator);
325
+ yield VelaAvdUtils.downloadAndUnzip(modemSimulatorUrl, VelaAvdUtils.getEmulatorEnvHome('modem_simulator'));
326
+ currVersionInfo.modem_simulator = constants_1.EmulatorEnvVersion.modem_simulator;
327
+ ColorConsole_1.default.success(`Download modem simulator succeed.`);
276
328
  }
277
- fs_extra_1.default.renameSync(onlineVersionFile, versionFile);
278
329
  // 创建avd文本文件
279
330
  const avdImagePath = imageDir;
280
- const avdParams = { avdName, avdSkin, avdWidth, avdHeight, avdArch, avdImagePath };
331
+ const avdParams = { avdName, avdSkin, avdWidth, avdHeight, avdArch: emulator_1.IAvdArchType.arm, avdImagePath };
281
332
  VelaAvdUtils.velaAvdCls.createVelaAvd(avdParams);
282
- ColorConsole_1.default.log({
283
- level: shared_utils_1.LOG_LEVEL.Success,
284
- message: `create avd succeed.`
285
- });
333
+ ColorConsole_1.default.success(`Create avd succeed.`);
286
334
  }
287
335
  catch (e) {
288
- ColorConsole_1.default.log({
289
- level: shared_utils_1.LOG_LEVEL.Error,
290
- message: `create avd failed. Error: ${e.message}`
291
- });
336
+ ColorConsole_1.default.throw(`Create avd failed. Error: ${e.message}`);
337
+ }
338
+ finally {
339
+ // 写入versions.json
340
+ const versionJson = JSON.stringify(currVersionInfo, null, 2);
341
+ fs_extra_1.default.writeFileSync(versionFile, versionJson);
342
+ }
343
+ });
344
+ }
345
+ /** 初始化/重置模拟器环境 */
346
+ static initEmulatorEnv() {
347
+ return __awaiter(this, void 0, void 0, function* () {
348
+ const versionFile = path_1.default.resolve(VelaAvdUtils.sdkHome, 'versions.json');
349
+ const versionFileExist = fs_extra_1.default.existsSync(versionFile);
350
+ let currVersionInfo = {
351
+ name: '模拟器资源版本管理',
352
+ emulator: '',
353
+ qa: '',
354
+ skins: '',
355
+ 'system-images': '',
356
+ tools: '',
357
+ modem_simulator: ''
358
+ };
359
+ if (versionFileExist) {
360
+ currVersionInfo = fs_extra_1.default.readJSONSync(versionFile);
361
+ }
362
+ // 模拟器的各项资源是否存在
363
+ const emulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'emulator', VelaAvdUtils.getEmulatorPlatform()));
364
+ const qaExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'qa/font'));
365
+ const skinsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
366
+ const toolsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'tools'));
367
+ const modemSimulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'modem_simulator/modem_nvram.json'));
368
+ const systemImageExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', constants_1.VelaImageVersionList[0].value, 'nuttx'));
369
+ try {
370
+ // 下载皮肤
371
+ if (!skinsExist || currVersionInfo.skins < constants_1.EmulatorEnvVersion.skins) {
372
+ const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', constants_1.EmulatorEnvVersion.skins);
373
+ yield VelaAvdUtils.downloadAndUnzip(skinsUrl, VelaAvdUtils.getEmulatorEnvHome('skins'));
374
+ currVersionInfo.skins = constants_1.EmulatorEnvVersion.skins;
375
+ ColorConsole_1.default.success(`Download skins succeed.`);
376
+ }
377
+ // 下载快应用font
378
+ if (!qaExist || currVersionInfo.qa < constants_1.EmulatorEnvVersion.qa) {
379
+ const qaUrl = VelaAvdUtils.getDownloadUrl('qa', constants_1.EmulatorEnvVersion.qa);
380
+ yield VelaAvdUtils.downloadAndUnzip(qaUrl, VelaAvdUtils.getEmulatorEnvHome('qa'));
381
+ currVersionInfo.qa = constants_1.EmulatorEnvVersion.qa;
382
+ ColorConsole_1.default.success(`Download quickapp font succeed.`);
383
+ }
384
+ // 下载工具
385
+ if (!toolsExist || currVersionInfo.tools < constants_1.EmulatorEnvVersion.tools) {
386
+ const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl(constants_1.EmulatorEnvVersion.tools);
387
+ const filename = (os_1.default.platform() === 'win32') ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
388
+ yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, VelaAvdUtils.getEmulatorEnvHome('tools'), filename);
389
+ currVersionInfo.tools = constants_1.EmulatorEnvVersion.tools;
390
+ ColorConsole_1.default.success(`Download tools succeed.`);
391
+ }
392
+ // 下载模拟器
393
+ if (!emulatorExist || currVersionInfo.emulator < constants_1.EmulatorEnvVersion.emulator) {
394
+ const emulatorUrl = VelaAvdUtils.getEmulatorUrl(constants_1.EmulatorEnvVersion.emulator);
395
+ yield VelaAvdUtils.downloadAndUnzip(emulatorUrl, VelaAvdUtils.getEmulatorEnvHome('emulator'));
396
+ currVersionInfo.emulator = constants_1.EmulatorEnvVersion.emulator;
397
+ ColorConsole_1.default.success(`Download emulator succeed.`);
398
+ }
399
+ // 下载modem_simultor
400
+ if (!modemSimulatorExist || currVersionInfo.modem_simulator < constants_1.EmulatorEnvVersion.modem_simulator) {
401
+ const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', constants_1.EmulatorEnvVersion.modem_simulator);
402
+ yield VelaAvdUtils.downloadAndUnzip(modemSimulatorUrl, VelaAvdUtils.getEmulatorEnvHome('modem_simulator'));
403
+ currVersionInfo.modem_simulator = constants_1.EmulatorEnvVersion.modem_simulator;
404
+ ColorConsole_1.default.success(`Download modem simulator succeed.`);
405
+ }
406
+ // 下载vela镜像,默认只下载最新的vela正式版,dev版本需要创建模拟器的时候手动勾选
407
+ if (!systemImageExist || VelaAvdUtils.velaImageNeedUpdate(constants_1.VelaImageVersionList[0].value)) {
408
+ const systemImageUrl = VelaAvdUtils.getSystemImageUrl(constants_1.VelaImageVersionList[0].value);
409
+ const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', constants_1.VelaImageVersionList[0].value);
410
+ yield VelaAvdUtils.downloadAndUnzip(systemImageUrl, imageDir);
411
+ currVersionInfo['system-images'] = constants_1.EmulatorEnvVersion['system-images'];
412
+ ColorConsole_1.default.success(`Download vela image succeed.`);
413
+ }
414
+ ColorConsole_1.default.success(`Create emulator environment succeed.`);
415
+ }
416
+ catch (e) {
417
+ ColorConsole_1.default.throw(`Create emulator environment failed. Error: ${e.message}`);
418
+ }
419
+ finally {
420
+ // 写入versions.json
421
+ const versionJson = JSON.stringify(currVersionInfo, null, 2);
422
+ fs_extra_1.default.writeFileSync(versionFile, versionJson);
292
423
  }
293
424
  });
294
425
  }
@@ -296,7 +427,7 @@ class VelaAvdUtils {
296
427
  VelaAvdUtils.sdkHome = path_1.default.resolve(os_1.default.homedir(), '.export');
297
428
  VelaAvdUtils.avdHome = path_1.default.resolve(os_1.default.homedir(), '.android', 'avd');
298
429
  VelaAvdUtils.baseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide';
299
- VelaAvdUtils.versionUrl = 'https://cdn.cnbj3-fusion.fds.api.mi-img.com/vela-ide/versions.json';
430
+ VelaAvdUtils.versionUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/versions.json';
300
431
  VelaAvdUtils.emulatorBaseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/emulator';
301
432
  VelaAvdUtils.systemImageBaseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide/system-images';
302
433
  VelaAvdUtils.velaAvdCls = new emulator_1.VelaAvdCls({
@@ -304,5 +435,3 @@ VelaAvdUtils.velaAvdCls = new emulator_1.VelaAvdCls({
304
435
  avdHome: VelaAvdUtils.avdHome
305
436
  });
306
437
  exports.default = VelaAvdUtils;
307
-
308
- //# sourceMappingURL=VelaAvdUtils.js.map
package/lib/waiter.js CHANGED
@@ -35,5 +35,3 @@ const waiter = new commander_1.PersistentCommand({
35
35
  ]
36
36
  });
37
37
  exports.default = waiter;
38
-
39
- //# sourceMappingURL=waiter.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiot-toolkit",
3
- "version": "2.0.1-alpha.9",
3
+ "version": "2.0.2-batchmanifest-beta.1",
4
4
  "description": "Tools for creating, developing, and packaging aiot applications.",
5
5
  "keywords": [
6
6
  "aiot"
@@ -17,26 +17,32 @@
17
17
  "files": [
18
18
  "lib"
19
19
  ],
20
- "repository": {
21
- "type": "git",
22
- "url": "ssh://xujunjie1@git.mioffice.cn:29418/vela/aiot-toolkit"
23
- },
24
20
  "scripts": {
25
21
  "test": "node ./__tests__/aiot-toolkit.test.js"
26
22
  },
27
23
  "dependencies": {
28
- "@aiot-toolkit/emulator": "2.0.1-alpha.9",
29
- "@aiot-toolkit/shared-utils": "2.0.1-alpha.9",
24
+ "@aiot-toolkit/commander": "2.0.2-batchmanifest-beta.1",
25
+ "@aiot-toolkit/emulator": "2.0.2-batchmanifest-beta.1",
26
+ "@aiot-toolkit/shared-utils": "2.0.2-batchmanifest-beta.1",
30
27
  "@miwt/adb": "^0.7.1",
31
28
  "adb-commander": "^0.1.9",
32
29
  "adm-zip": "^0.5.10",
33
30
  "axios": "^1.5.0",
34
31
  "cli-progress": "^3.12.0",
35
- "create-aiot": "2.0.1-alpha.9",
36
- "fast-glob": "^3.3.2"
32
+ "create-aiot": "2.0.2-batchmanifest-beta.1",
33
+ "dayjs": "^1.11.10",
34
+ "fast-glob": "^3.3.2",
35
+ "file-lane": "2.0.2-batchmanifest-beta.1",
36
+ "lodash": "^4.17.21",
37
+ "semver": "^7.6.0",
38
+ "ws": "^8.15.1"
37
39
  },
38
40
  "devDependencies": {
39
- "@types/adm-zip": "^0.5.4"
41
+ "@types/adm-zip": "^0.5.4",
42
+ "@types/fs-extra": "^11.0.4",
43
+ "@types/semver": "^7.5.8",
44
+ "@types/ws": "^8.5.10",
45
+ "fs-extra": "^11.2.0"
40
46
  },
41
- "gitHead": "d593999b9ca345bce8b3ba40a7d11f6685ac03b5"
47
+ "gitHead": "9e58a0cbe0e2d35a38e99d669398caaa8fd648a8"
42
48
  }