aiot-toolkit 2.0.2-beta.3 → 2.0.2-beta.4
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/lib/bin.js +8 -1
- package/lib/builder/UxBuilder.d.ts +8 -0
- package/lib/builder/UxBuilder.js +24 -16
- package/lib/interface/VelaEmulatorInterface.d.ts +7 -6
- package/lib/starter/UxStarter.js +3 -1
- package/lib/utils/VelaAvdUtils.d.ts +14 -9
- package/lib/utils/VelaAvdUtils.js +232 -84
- package/package.json +8 -7
package/lib/bin.js
CHANGED
|
@@ -196,7 +196,14 @@ function main() {
|
|
|
196
196
|
VelaAvdUtils_1.default.velaAvdCls.deleteVelaAvd(avdName);
|
|
197
197
|
});
|
|
198
198
|
})
|
|
199
|
-
}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: 'initEmulatorEnv',
|
|
202
|
+
description: 'init/reset emulator environment',
|
|
203
|
+
action: () => __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
VelaAvdUtils_1.default.initEmulatorEnv();
|
|
205
|
+
})
|
|
206
|
+
},
|
|
200
207
|
]
|
|
201
208
|
};
|
|
202
209
|
commander_1.Command.registeProgram(config);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import CompileMode from '@aiot-toolkit/aiotpack/lib/compiler/enum/CompileMode';
|
|
2
|
+
import IJavascriptCompileOption from '@aiot-toolkit/aiotpack/lib/compiler/javascript/interface/IJavascriptCompileOption';
|
|
2
3
|
import ParamType from '@aiot-toolkit/commander/lib/interface/IParam';
|
|
3
4
|
import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
|
|
4
5
|
import IBuilder from './IBuilder';
|
|
@@ -6,12 +7,19 @@ interface IUxBuilderOption extends Dictionary {
|
|
|
6
7
|
watch?: boolean;
|
|
7
8
|
mode: CompileMode;
|
|
8
9
|
disabledJsc: boolean;
|
|
10
|
+
enableE2e?: boolean;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* UxBuilder
|
|
12
14
|
*/
|
|
13
15
|
declare class UxBuilder implements IBuilder<IUxBuilderOption> {
|
|
14
16
|
readonly QUICKAPP_CONFIG = "quickapp.config.js";
|
|
17
|
+
/**
|
|
18
|
+
* 获取build的编译配置
|
|
19
|
+
* @param projectPath 项目路径
|
|
20
|
+
* @param options 命令参数
|
|
21
|
+
*/
|
|
22
|
+
getCompilerOption(projectPath: string, options: IUxBuilderOption): Partial<IJavascriptCompileOption>;
|
|
15
23
|
/**
|
|
16
24
|
* ux项目的build函数
|
|
17
25
|
* @param projectPath 项目路径
|
package/lib/builder/UxBuilder.js
CHANGED
|
@@ -40,10 +40,6 @@ class UxBuilder {
|
|
|
40
40
|
constructor() {
|
|
41
41
|
this.QUICKAPP_CONFIG = 'quickapp.config.js';
|
|
42
42
|
this.params = [
|
|
43
|
-
{
|
|
44
|
-
name: 'enable-e2e',
|
|
45
|
-
description: 'inject test-suite for current project'
|
|
46
|
-
},
|
|
47
43
|
{
|
|
48
44
|
type: 'string',
|
|
49
45
|
name: 'devtool',
|
|
@@ -60,13 +56,36 @@ class UxBuilder {
|
|
|
60
56
|
defaultValue: false
|
|
61
57
|
},
|
|
62
58
|
{
|
|
59
|
+
type: 'confirm',
|
|
63
60
|
name: 'enable-protobuf',
|
|
64
61
|
description: 'enable protobuf',
|
|
62
|
+
defaultValue: false
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
65
|
type: 'confirm',
|
|
66
|
+
name: 'enable-e2e',
|
|
67
|
+
description: 'inject test-suite for current project',
|
|
66
68
|
defaultValue: false
|
|
67
69
|
}
|
|
68
70
|
];
|
|
69
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* 获取build的编译配置
|
|
74
|
+
* @param projectPath 项目路径
|
|
75
|
+
* @param options 命令参数
|
|
76
|
+
*/
|
|
77
|
+
getCompilerOption(projectPath, options) {
|
|
78
|
+
// 读取项目中文件的配置
|
|
79
|
+
const quickappConfig = this.readQuickAppConfig(projectPath);
|
|
80
|
+
const _a = quickappConfig || {}, { cli } = _a, otherConfig = __rest(_a, ["cli"]);
|
|
81
|
+
options = lodash_1.default.merge({}, options, cli);
|
|
82
|
+
// 项目配置
|
|
83
|
+
const uxProjectConfig = new UxConfig_1.default(projectPath);
|
|
84
|
+
// 编译配置
|
|
85
|
+
const compileMode = options.mode || CompileMode_1.default.DEVELOPMENT;
|
|
86
|
+
const compilerOption = lodash_1.default.merge(JavascriptDefaultCompileOption_1.default, Object.assign(Object.assign({}, options), { projectPath: path_1.default.join(projectPath, uxProjectConfig.output), mode: compileMode, disabledJSC: options.disabledJsc, enableProtobuf: options.enableProtobuf, devtool: UxBuilderUtils_1.default.getDevtoolValue(compileMode, options.devtool || false) }), otherConfig);
|
|
87
|
+
return compilerOption;
|
|
88
|
+
}
|
|
70
89
|
/**
|
|
71
90
|
* ux项目的build函数
|
|
72
91
|
* @param projectPath 项目路径
|
|
@@ -76,21 +95,10 @@ class UxBuilder {
|
|
|
76
95
|
build(projectPath, options) {
|
|
77
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
97
|
const watch = options.watch || false;
|
|
79
|
-
// 读取项目中文件的配置
|
|
80
|
-
const quickappConfig = this.readQuickAppConfig(projectPath);
|
|
81
|
-
const _a = quickappConfig || {}, { cli } = _a, otherConfig = __rest(_a, ["cli"]);
|
|
82
|
-
options = lodash_1.default.merge({}, options, cli);
|
|
83
98
|
// 项目配置
|
|
84
99
|
const uxProjectConfig = new UxConfig_1.default(projectPath);
|
|
85
100
|
// 编译配置
|
|
86
|
-
const
|
|
87
|
-
const compilerOption = lodash_1.default.merge({
|
|
88
|
-
projectPath: path_1.default.join(projectPath, uxProjectConfig.output),
|
|
89
|
-
mode: compileMode,
|
|
90
|
-
disabledJSC: options.disabledJsc,
|
|
91
|
-
enableProtobuf: options.enableProtobuf,
|
|
92
|
-
devtool: UxBuilderUtils_1.default.getDevtoolValue(compileMode, options.devtool || false)
|
|
93
|
-
}, JavascriptDefaultCompileOption_1.default, otherConfig);
|
|
101
|
+
const compilerOption = this.getCompilerOption(projectPath, options);
|
|
94
102
|
ColorConsole_1.default.info('start build: ', {
|
|
95
103
|
style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Info),
|
|
96
104
|
word: JSON.stringify({
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
export interface ISystemImagesVersionInfo {
|
|
2
|
-
release: string;
|
|
3
|
-
dev: string;
|
|
4
|
-
}
|
|
5
|
-
export type ISystemImagesType = keyof ISystemImagesVersionInfo;
|
|
6
1
|
export interface IGoldfishVersionInfo {
|
|
7
2
|
name: string;
|
|
8
3
|
emulator: string;
|
|
9
|
-
'system-images':
|
|
4
|
+
'system-images': string;
|
|
10
5
|
qa: string;
|
|
11
6
|
skins: string;
|
|
12
7
|
tools: string;
|
|
8
|
+
modem_simulator: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IVelaImageItem {
|
|
11
|
+
label: string;
|
|
12
|
+
value: string;
|
|
13
|
+
time: string | Date;
|
|
13
14
|
}
|
package/lib/starter/UxStarter.js
CHANGED
|
@@ -95,12 +95,14 @@ class UxStarter extends IStarter_1.default {
|
|
|
95
95
|
(0, JavascriptDefaultCompileOption_1.setServerPort)(serverPort);
|
|
96
96
|
}
|
|
97
97
|
// build
|
|
98
|
+
const compilerOption = this.builder.getCompilerOption(projectPath, options);
|
|
98
99
|
yield this.builder.build(projectPath, options);
|
|
99
100
|
// start
|
|
100
101
|
const params = {
|
|
101
102
|
sdkHome: path_1.default.resolve(os_1.default.homedir(), '.export'),
|
|
102
103
|
avdHome: path_1.default.resolve(os_1.default.homedir(), '.android/avd'),
|
|
103
|
-
projectPath
|
|
104
|
+
projectPath,
|
|
105
|
+
compilerOption
|
|
104
106
|
};
|
|
105
107
|
const goldfishInstance = (0, emulator_1.findInstance)(avdName, params);
|
|
106
108
|
if (!goldfishInstance)
|
|
@@ -25,21 +25,26 @@ declare class VelaAvdUtils {
|
|
|
25
25
|
static downloadAndUnzip(downloadUrl: string, targetDir: string): Promise<void>;
|
|
26
26
|
/** 根据host获取模拟器下载地址 */
|
|
27
27
|
static getEmulatorUrl(version?: string): string;
|
|
28
|
-
/**
|
|
28
|
+
/** 获取模拟器平台的名称,darwin-aarch64 linux-aarch64 windows-x86_64等 */
|
|
29
|
+
static getEmulatorPlatform(): string;
|
|
30
|
+
static getEmulatorEnvHome(resourceName: string): string;
|
|
31
|
+
/** vela镜像需要更新 */
|
|
32
|
+
static velaImageNeedUpdate(imageId: string): boolean;
|
|
33
|
+
/** vela镜像是否为zip包 */
|
|
34
|
+
static isZipInImageUrl(velaImage: string): boolean;
|
|
35
|
+
/** 获取vela镜像的下载地址 */
|
|
29
36
|
static getSystemImageUrl(version?: string): string;
|
|
37
|
+
/** 获取模拟器其他资源的下载地址 */
|
|
38
|
+
static getDownloadUrl(dir: string, version?: string, filename?: string): string;
|
|
30
39
|
/** 根据host获取ya-vm-file-server下载地址 */
|
|
31
40
|
static getv9fsToolUrl(version?: string): string;
|
|
32
|
-
/**
|
|
33
|
-
static
|
|
34
|
-
/**
|
|
35
|
-
* 判断vela镜像是release版还是dev版
|
|
36
|
-
* @param velaImage 镜像名称或者镜像路径
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
static isReleaseVelaImage(velaImage: string): boolean;
|
|
41
|
+
/** 获取镜像构建时间 */
|
|
42
|
+
static getImageBuildTime(imageId: string): string | Date | undefined;
|
|
40
43
|
/**
|
|
41
44
|
* 命令行访问方式创建模拟器
|
|
42
45
|
*/
|
|
43
46
|
static createVelaAvdByInquire(): Promise<void>;
|
|
47
|
+
/** 初始化/重置模拟器环境 */
|
|
48
|
+
static initEmulatorEnv(): Promise<void>;
|
|
44
49
|
}
|
|
45
50
|
export default VelaAvdUtils;
|
|
@@ -23,6 +23,7 @@ const cli_progress_1 = __importDefault(require("cli-progress"));
|
|
|
23
23
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
24
24
|
const os_1 = __importDefault(require("os"));
|
|
25
25
|
const path_1 = __importDefault(require("path"));
|
|
26
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
26
27
|
class VelaAvdUtils {
|
|
27
28
|
static validateAvdName(avdName) {
|
|
28
29
|
if (!avdName) {
|
|
@@ -108,13 +109,47 @@ class VelaAvdUtils {
|
|
|
108
109
|
let hostOs = systemOs === 'win32' ? 'windows' : systemOs;
|
|
109
110
|
return `${VelaAvdUtils.emulatorBaseUrl}/v${version}/${hostOs}-${hostArch}.zip`;
|
|
110
111
|
}
|
|
111
|
-
/**
|
|
112
|
+
/** 获取模拟器平台的名称,darwin-aarch64 linux-aarch64 windows-x86_64等 */
|
|
113
|
+
static getEmulatorPlatform() {
|
|
114
|
+
const systemOs = os_1.default.platform();
|
|
115
|
+
const hostArch = (0, utils_1.getSystemArch)();
|
|
116
|
+
const hostOs = systemOs === 'win32' ? 'windows' : systemOs;
|
|
117
|
+
return `${hostOs}-${hostArch}`;
|
|
118
|
+
}
|
|
119
|
+
static getEmulatorEnvHome(resourceName) {
|
|
120
|
+
return path_1.default.resolve(VelaAvdUtils.sdkHome, resourceName);
|
|
121
|
+
}
|
|
122
|
+
/** vela镜像需要更新 */
|
|
123
|
+
static velaImageNeedUpdate(imageId) {
|
|
124
|
+
// 兼容之前的version.json
|
|
125
|
+
if (typeof imageId !== 'string')
|
|
126
|
+
return true;
|
|
127
|
+
let avdImagePath = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', imageId, 'nuttx');
|
|
128
|
+
if (fs_extra_1.default.existsSync(avdImagePath) && VelaAvdUtils.isZipInImageUrl(imageId)) {
|
|
129
|
+
const stats = fs_extra_1.default.statSync(avdImagePath);
|
|
130
|
+
const version = constants_1.VelaImageVersionList.find((item) => item.value === imageId);
|
|
131
|
+
if (version && (0, dayjs_1.default)(version.time).isAfter(stats.mtime, 'day'))
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
/** vela镜像是否为zip包 */
|
|
137
|
+
static isZipInImageUrl(velaImage) {
|
|
138
|
+
return velaImage.indexOf('0.0.2') < 0;
|
|
139
|
+
}
|
|
140
|
+
/** 获取vela镜像的下载地址 */
|
|
112
141
|
static getSystemImageUrl(version = 'vela-release-4.0') {
|
|
113
|
-
if (
|
|
114
|
-
|
|
142
|
+
if (VelaAvdUtils.isZipInImageUrl(version)) {
|
|
143
|
+
const velaImage = constants_1.VelaImageVersionList.find((item) => item.value = version);
|
|
144
|
+
const dayOfTime = (0, dayjs_1.default)(velaImage === null || velaImage === void 0 ? void 0 : velaImage.time).format('YYYYMMDD');
|
|
145
|
+
return `${VelaAvdUtils.systemImageBaseUrl}/${version}/${dayOfTime}/${version}.zip`;
|
|
115
146
|
}
|
|
116
147
|
return `${VelaAvdUtils.systemImageBaseUrl}/${version}/nuttx`;
|
|
117
148
|
}
|
|
149
|
+
/** 获取模拟器其他资源的下载地址 */
|
|
150
|
+
static getDownloadUrl(dir, version = '0.0.1', filename = dir) {
|
|
151
|
+
return `${VelaAvdUtils.baseUrl}/${dir}/v${version}/${filename}.zip`;
|
|
152
|
+
}
|
|
118
153
|
/** 根据host获取ya-vm-file-server下载地址 */
|
|
119
154
|
static getv9fsToolUrl(version = '0.0.1') {
|
|
120
155
|
const systemOs = os_1.default.platform();
|
|
@@ -122,43 +157,64 @@ class VelaAvdUtils {
|
|
|
122
157
|
let v9fsTool = '';
|
|
123
158
|
switch (systemOs) {
|
|
124
159
|
case 'linux':
|
|
125
|
-
v9fsTool =
|
|
160
|
+
v9fsTool = 'ya-vm-file-server-linux-x86_64';
|
|
126
161
|
break;
|
|
127
162
|
case 'win32':
|
|
128
163
|
v9fsTool = 'ya-vm-file-server-windows.exe';
|
|
129
164
|
break;
|
|
130
165
|
case 'darwin':
|
|
131
166
|
v9fsTool = `ya-vm-file-server-darwin-${arch}`;
|
|
167
|
+
break;
|
|
132
168
|
default:
|
|
133
169
|
break;
|
|
134
170
|
}
|
|
135
171
|
return `${VelaAvdUtils.baseUrl}/tools/v${version}/${v9fsTool}`;
|
|
136
172
|
}
|
|
137
|
-
/**
|
|
138
|
-
static
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
173
|
+
/** 获取镜像构建时间 */
|
|
174
|
+
static getImageBuildTime(imageId) {
|
|
175
|
+
var _a;
|
|
176
|
+
if (!imageId)
|
|
177
|
+
return;
|
|
178
|
+
const imagePath = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', imageId, 'nuttx');
|
|
179
|
+
if (fs_extra_1.default.existsSync(imagePath)) {
|
|
180
|
+
if (VelaAvdUtils.isZipInImageUrl(imageId)) {
|
|
181
|
+
const stats = fs_extra_1.default.statSync(imagePath);
|
|
182
|
+
return stats.mtime;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
const time = (_a = constants_1.VelaImageVersionList.find((item) => item.value === imageId)) === null || _a === void 0 ? void 0 : _a.time;
|
|
186
|
+
return time;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return;
|
|
148
190
|
}
|
|
149
191
|
/**
|
|
150
192
|
* 命令行访问方式创建模拟器
|
|
151
193
|
*/
|
|
152
194
|
static createVelaAvdByInquire() {
|
|
153
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
const versionFile = path_1.default.resolve(VelaAvdUtils.sdkHome, 'versions.json');
|
|
197
|
+
const versionFileExist = fs_extra_1.default.existsSync(versionFile);
|
|
198
|
+
let currVersionInfo = {
|
|
199
|
+
name: '模拟器资源版本管理',
|
|
200
|
+
emulator: '',
|
|
201
|
+
qa: '',
|
|
202
|
+
skins: '',
|
|
203
|
+
'system-images': '',
|
|
204
|
+
tools: '',
|
|
205
|
+
modem_simulator: ''
|
|
206
|
+
};
|
|
207
|
+
if (versionFileExist) {
|
|
208
|
+
currVersionInfo = fs_extra_1.default.readJSONSync(versionFile);
|
|
209
|
+
}
|
|
210
|
+
const onlineVersionInfo = constants_1.EmulatorEnvVersion;
|
|
211
|
+
// 模拟器各项资源(除了镜像)是否存在
|
|
212
|
+
const emulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'emulator', VelaAvdUtils.getEmulatorPlatform()));
|
|
213
|
+
const qaExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'qa/font'));
|
|
214
|
+
const skinsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
|
|
215
|
+
const toolsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'tools'));
|
|
216
|
+
const modemSimulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'modem_simulator/modem_nvram.json'));
|
|
154
217
|
try {
|
|
155
|
-
const versionFile = path_1.default.resolve(VelaAvdUtils.sdkHome, 'versions.json');
|
|
156
|
-
const versionFileExist = fs_extra_1.default.existsSync(versionFile);
|
|
157
|
-
let versionInfo = undefined;
|
|
158
|
-
if (versionFileExist) {
|
|
159
|
-
versionInfo = fs_extra_1.default.readJSONSync(versionFile);
|
|
160
|
-
}
|
|
161
|
-
const onlineVersionInfo = constants_1.emulatorEnvVersion;
|
|
162
218
|
// avdName
|
|
163
219
|
const avdName = yield (0, prompts_1.input)({
|
|
164
220
|
message: 'avd name starting with Vela. (eg. Vela_Virtual_Device)',
|
|
@@ -167,66 +223,67 @@ class VelaAvdUtils {
|
|
|
167
223
|
return VelaAvdUtils.validateAvdName(value);
|
|
168
224
|
}
|
|
169
225
|
});
|
|
226
|
+
// 镜像
|
|
227
|
+
const velaImage = (yield (0, prompts_1.select)({
|
|
228
|
+
message: 'vela image.',
|
|
229
|
+
choices: constants_1.VelaImageVersionList.map((item) => {
|
|
230
|
+
return { value: item.value, name: item.label };
|
|
231
|
+
})
|
|
232
|
+
}));
|
|
170
233
|
// skin或者size
|
|
171
|
-
const needSkin = yield (0, prompts_1.confirm)({
|
|
172
|
-
message: 'need avd skin?',
|
|
173
|
-
default: true
|
|
174
|
-
});
|
|
175
|
-
const skinDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins');
|
|
176
|
-
const skinExists = fs_extra_1.default.existsSync(skinDir);
|
|
177
234
|
let avdSkin = '';
|
|
178
|
-
let avdWidth = '';
|
|
179
|
-
let avdHeight = '';
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
const skinList = VelaAvdUtils.velaAvdCls.getVelaSkinList();
|
|
187
|
-
avdSkin = yield (0, prompts_1.select)({
|
|
188
|
-
message: 'avd skin.',
|
|
189
|
-
choices: skinList.map((item) => {
|
|
190
|
-
return {
|
|
191
|
-
name: item,
|
|
192
|
-
value: item,
|
|
193
|
-
description: item
|
|
194
|
-
};
|
|
195
|
-
})
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
avdWidth = yield (0, prompts_1.input)({
|
|
200
|
-
message: 'avd width.',
|
|
201
|
-
default: '480'
|
|
202
|
-
});
|
|
203
|
-
avdHeight = yield (0, prompts_1.input)({
|
|
204
|
-
message: 'avd height.',
|
|
205
|
-
default: '480'
|
|
235
|
+
let avdWidth = '466';
|
|
236
|
+
let avdHeight = '466';
|
|
237
|
+
// vela4.0不允许自定义分辨率
|
|
238
|
+
if (velaImage.indexOf('vela-release') < 0) {
|
|
239
|
+
const needSkin = yield (0, prompts_1.confirm)({
|
|
240
|
+
message: 'need avd skin?',
|
|
241
|
+
default: true
|
|
206
242
|
});
|
|
243
|
+
if (needSkin) {
|
|
244
|
+
if (!skinsExist || (currVersionInfo && currVersionInfo.skins < onlineVersionInfo.skins)) {
|
|
245
|
+
const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', onlineVersionInfo.skins);
|
|
246
|
+
yield VelaAvdUtils.downloadAndUnzip(skinsUrl, path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
|
|
247
|
+
currVersionInfo.skins = constants_1.EmulatorEnvVersion.skins;
|
|
248
|
+
ColorConsole_1.default.success(`Download skins succeed.`);
|
|
249
|
+
}
|
|
250
|
+
const skinList = VelaAvdUtils.velaAvdCls.getVelaSkinList();
|
|
251
|
+
avdSkin = yield (0, prompts_1.select)({
|
|
252
|
+
message: 'avd skin.',
|
|
253
|
+
choices: skinList.map((item) => {
|
|
254
|
+
return {
|
|
255
|
+
name: item,
|
|
256
|
+
value: item,
|
|
257
|
+
description: item
|
|
258
|
+
};
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
avdWidth = yield (0, prompts_1.input)({
|
|
264
|
+
message: 'avd width.',
|
|
265
|
+
default: '466'
|
|
266
|
+
});
|
|
267
|
+
avdHeight = yield (0, prompts_1.input)({
|
|
268
|
+
message: 'avd height.',
|
|
269
|
+
default: '466'
|
|
270
|
+
});
|
|
271
|
+
}
|
|
207
272
|
}
|
|
208
|
-
// 镜像,TODO:后续需要考虑多种设备的镜像
|
|
209
|
-
const velaImage = (yield (0, prompts_1.select)({
|
|
210
|
-
message: 'vela image.',
|
|
211
|
-
choices: [
|
|
212
|
-
// { value: 'vela-release-4.0-pre', name: 'vela抢先版(4.0)' },
|
|
213
|
-
{ value: 'vela-dev-0.0.2', name: 'vela开发版(dev, 0.0.2)' }
|
|
214
|
-
]
|
|
215
|
-
}));
|
|
216
273
|
// 下载模拟器
|
|
217
|
-
|
|
218
|
-
const emulatorExists = fs_extra_1.default.existsSync(emulatorDir);
|
|
219
|
-
if (!emulatorExists || (versionInfo && versionInfo.emulator < onlineVersionInfo.emulator)) {
|
|
274
|
+
if (!emulatorExist || (currVersionInfo && currVersionInfo.emulator < onlineVersionInfo.emulator)) {
|
|
220
275
|
const emulatorDownloadUrl = VelaAvdUtils.getEmulatorUrl(onlineVersionInfo.emulator);
|
|
221
|
-
yield VelaAvdUtils.downloadAndUnzip(emulatorDownloadUrl,
|
|
276
|
+
yield VelaAvdUtils.downloadAndUnzip(emulatorDownloadUrl, VelaAvdUtils.getEmulatorEnvHome('emulator'));
|
|
277
|
+
currVersionInfo.emulator = constants_1.EmulatorEnvVersion.emulator;
|
|
222
278
|
ColorConsole_1.default.success(`Download emulator succeed.`);
|
|
223
279
|
}
|
|
224
280
|
// 下载镜像
|
|
225
281
|
const velaImageDownloadUrl = this.getSystemImageUrl(velaImage);
|
|
226
282
|
const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', velaImage);
|
|
227
283
|
const imageExists = fs_extra_1.default.existsSync(path_1.default.resolve(imageDir, 'nuttx'));
|
|
284
|
+
// 镜像不存在
|
|
228
285
|
if (!imageExists) {
|
|
229
|
-
if (
|
|
286
|
+
if (VelaAvdUtils.isZipInImageUrl(velaImage)) {
|
|
230
287
|
yield VelaAvdUtils.downloadAndUnzip(velaImageDownloadUrl, imageDir);
|
|
231
288
|
}
|
|
232
289
|
else {
|
|
@@ -234,30 +291,35 @@ class VelaAvdUtils {
|
|
|
234
291
|
}
|
|
235
292
|
ColorConsole_1.default.success(`Download vela image succeed.`);
|
|
236
293
|
}
|
|
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
|
+
}
|
|
237
301
|
// 下载快应用qa文件
|
|
238
|
-
|
|
239
|
-
const qaExists = fs_extra_1.default.existsSync(qaDir);
|
|
240
|
-
if (!qaExists || (versionInfo && versionInfo.qa < onlineVersionInfo.qa)) {
|
|
302
|
+
if (!qaExist || (currVersionInfo && currVersionInfo.qa < onlineVersionInfo.qa)) {
|
|
241
303
|
const qaUrl = VelaAvdUtils.getDownloadUrl('qa', onlineVersionInfo.qa);
|
|
242
|
-
yield VelaAvdUtils.downloadAndUnzip(qaUrl,
|
|
304
|
+
yield VelaAvdUtils.downloadAndUnzip(qaUrl, VelaAvdUtils.getEmulatorEnvHome('qa'));
|
|
305
|
+
currVersionInfo.qa = constants_1.EmulatorEnvVersion.qa;
|
|
243
306
|
ColorConsole_1.default.success(`Download quickapp font succeed.`);
|
|
244
307
|
}
|
|
245
308
|
// 下载tools
|
|
246
|
-
|
|
247
|
-
const toolsExists = fs_extra_1.default.existsSync(toolsDir);
|
|
248
|
-
if (!toolsExists || (versionInfo && versionInfo.tools < onlineVersionInfo.tools)) {
|
|
309
|
+
if (!toolsExist || (currVersionInfo && currVersionInfo.tools < onlineVersionInfo.tools)) {
|
|
249
310
|
const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl();
|
|
250
311
|
const filename = os_1.default.platform() === 'win32' ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
|
|
251
|
-
yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl,
|
|
252
|
-
|
|
253
|
-
// const imageUrl = VelaAvdUtils.getDownloadUrl('tools', onlineVersionInfo.tools, 'image')
|
|
254
|
-
// const imageDir = path.resolve(toolsDir, 'image')
|
|
255
|
-
// await VelaAvdUtils.downloadAndUnzip(imageUrl, imageDir)
|
|
312
|
+
yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, VelaAvdUtils.getEmulatorEnvHome('tools'), filename);
|
|
313
|
+
currVersionInfo.tools = constants_1.EmulatorEnvVersion.tools;
|
|
256
314
|
ColorConsole_1.default.success(`Download tools succeed.`);
|
|
257
315
|
}
|
|
258
|
-
//
|
|
259
|
-
|
|
260
|
-
|
|
316
|
+
// 下载modem_simulator
|
|
317
|
+
if (!modemSimulatorExist || currVersionInfo.modem_simulator < constants_1.EmulatorEnvVersion.modem_simulator) {
|
|
318
|
+
const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', constants_1.EmulatorEnvVersion.modem_simulator);
|
|
319
|
+
yield VelaAvdUtils.downloadAndUnzip(modemSimulatorUrl, VelaAvdUtils.getEmulatorEnvHome('modem_simulator'));
|
|
320
|
+
currVersionInfo.modem_simulator = constants_1.EmulatorEnvVersion.modem_simulator;
|
|
321
|
+
ColorConsole_1.default.success(`Download modem simulator succeed.`);
|
|
322
|
+
}
|
|
261
323
|
// 创建avd文本文件
|
|
262
324
|
const avdImagePath = imageDir;
|
|
263
325
|
const avdParams = { avdName, avdSkin, avdWidth, avdHeight, avdArch: emulator_1.IAvdArchType.arm, avdImagePath };
|
|
@@ -267,6 +329,92 @@ class VelaAvdUtils {
|
|
|
267
329
|
catch (e) {
|
|
268
330
|
ColorConsole_1.default.throw(`Create avd failed. Error: ${e.message}`);
|
|
269
331
|
}
|
|
332
|
+
finally {
|
|
333
|
+
// 写入versions.json
|
|
334
|
+
const versionJson = JSON.stringify(currVersionInfo, null, 2);
|
|
335
|
+
fs_extra_1.default.writeFileSync(versionFile, versionJson);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
/** 初始化/重置模拟器环境 */
|
|
340
|
+
static initEmulatorEnv() {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
const versionFile = path_1.default.resolve(VelaAvdUtils.sdkHome, 'versions.json');
|
|
343
|
+
const versionFileExist = fs_extra_1.default.existsSync(versionFile);
|
|
344
|
+
let currVersionInfo = {
|
|
345
|
+
name: '模拟器资源版本管理',
|
|
346
|
+
emulator: '',
|
|
347
|
+
qa: '',
|
|
348
|
+
skins: '',
|
|
349
|
+
'system-images': '',
|
|
350
|
+
tools: '',
|
|
351
|
+
modem_simulator: ''
|
|
352
|
+
};
|
|
353
|
+
if (versionFileExist) {
|
|
354
|
+
currVersionInfo = fs_extra_1.default.readJSONSync(versionFile);
|
|
355
|
+
}
|
|
356
|
+
// 模拟器的各项资源是否存在
|
|
357
|
+
const emulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'emulator', VelaAvdUtils.getEmulatorPlatform()));
|
|
358
|
+
const qaExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'qa/font'));
|
|
359
|
+
const skinsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'skins'));
|
|
360
|
+
const toolsExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'tools'));
|
|
361
|
+
const modemSimulatorExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'modem_simulator/modem_nvram.json'));
|
|
362
|
+
const systemImageExist = fs_extra_1.default.existsSync(path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', constants_1.VelaImageVersionList[0].value, 'nuttx'));
|
|
363
|
+
try {
|
|
364
|
+
// 下载皮肤
|
|
365
|
+
if (!skinsExist || currVersionInfo.skins < constants_1.EmulatorEnvVersion.skins) {
|
|
366
|
+
const skinsUrl = VelaAvdUtils.getDownloadUrl('skins', constants_1.EmulatorEnvVersion.skins);
|
|
367
|
+
yield VelaAvdUtils.downloadAndUnzip(skinsUrl, VelaAvdUtils.getEmulatorEnvHome('skins'));
|
|
368
|
+
currVersionInfo.skins = constants_1.EmulatorEnvVersion.skins;
|
|
369
|
+
ColorConsole_1.default.success(`Download skins succeed.`);
|
|
370
|
+
}
|
|
371
|
+
// 下载快应用font
|
|
372
|
+
if (!qaExist || currVersionInfo.qa < constants_1.EmulatorEnvVersion.qa) {
|
|
373
|
+
const qaUrl = VelaAvdUtils.getDownloadUrl('qa', constants_1.EmulatorEnvVersion.qa);
|
|
374
|
+
yield VelaAvdUtils.downloadAndUnzip(qaUrl, VelaAvdUtils.getEmulatorEnvHome('qa'));
|
|
375
|
+
currVersionInfo.qa = constants_1.EmulatorEnvVersion.qa;
|
|
376
|
+
ColorConsole_1.default.success(`Download quickapp font succeed.`);
|
|
377
|
+
}
|
|
378
|
+
// 下载工具
|
|
379
|
+
if (!toolsExist || currVersionInfo.tools < constants_1.EmulatorEnvVersion.tools) {
|
|
380
|
+
const v9fsToolUrl = VelaAvdUtils.getv9fsToolUrl(constants_1.EmulatorEnvVersion.tools);
|
|
381
|
+
const filename = (os_1.default.platform() === 'win32') ? 'ya-vm-file-server.exe' : 'ya-vm-file-server';
|
|
382
|
+
yield VelaAvdUtils.downloadFromCdn(v9fsToolUrl, VelaAvdUtils.getEmulatorEnvHome('tools'), filename);
|
|
383
|
+
currVersionInfo.tools = constants_1.EmulatorEnvVersion.tools;
|
|
384
|
+
ColorConsole_1.default.success(`Download tools succeed.`);
|
|
385
|
+
}
|
|
386
|
+
// 下载模拟器
|
|
387
|
+
if (!emulatorExist || currVersionInfo.emulator < constants_1.EmulatorEnvVersion.emulator) {
|
|
388
|
+
const emulatorUrl = VelaAvdUtils.getEmulatorUrl(constants_1.EmulatorEnvVersion.emulator);
|
|
389
|
+
yield VelaAvdUtils.downloadAndUnzip(emulatorUrl, VelaAvdUtils.getEmulatorEnvHome('emulator'));
|
|
390
|
+
currVersionInfo.emulator = constants_1.EmulatorEnvVersion.emulator;
|
|
391
|
+
ColorConsole_1.default.success(`Download emulator succeed.`);
|
|
392
|
+
}
|
|
393
|
+
// 下载modem_simultor
|
|
394
|
+
if (!modemSimulatorExist || currVersionInfo.modem_simulator < constants_1.EmulatorEnvVersion.modem_simulator) {
|
|
395
|
+
const modemSimulatorUrl = VelaAvdUtils.getDownloadUrl('modem_simulator', constants_1.EmulatorEnvVersion.modem_simulator);
|
|
396
|
+
yield VelaAvdUtils.downloadAndUnzip(modemSimulatorUrl, VelaAvdUtils.getEmulatorEnvHome('modem_simulator'));
|
|
397
|
+
currVersionInfo.modem_simulator = constants_1.EmulatorEnvVersion.modem_simulator;
|
|
398
|
+
ColorConsole_1.default.success(`Download modem simulator succeed.`);
|
|
399
|
+
}
|
|
400
|
+
// 下载vela镜像,默认只下载最新的vela正式版,dev版本需要创建模拟器的时候手动勾选
|
|
401
|
+
if (!systemImageExist || VelaAvdUtils.velaImageNeedUpdate(constants_1.VelaImageVersionList[0].value)) {
|
|
402
|
+
const systemImageUrl = VelaAvdUtils.getSystemImageUrl(constants_1.VelaImageVersionList[0].value);
|
|
403
|
+
const imageDir = path_1.default.resolve(VelaAvdUtils.sdkHome, 'system-images', constants_1.VelaImageVersionList[0].value);
|
|
404
|
+
yield VelaAvdUtils.downloadAndUnzip(systemImageUrl, imageDir);
|
|
405
|
+
currVersionInfo['system-images'] = constants_1.EmulatorEnvVersion['system-images'];
|
|
406
|
+
ColorConsole_1.default.success(`Download vela image succeed.`);
|
|
407
|
+
}
|
|
408
|
+
ColorConsole_1.default.success(`Create emulator environment succeed.`);
|
|
409
|
+
}
|
|
410
|
+
catch (e) {
|
|
411
|
+
ColorConsole_1.default.throw(`Create emulator environment failed. Error: ${e.message}`);
|
|
412
|
+
}
|
|
413
|
+
finally {
|
|
414
|
+
// 写入versions.json
|
|
415
|
+
const versionJson = JSON.stringify(currVersionInfo, null, 2);
|
|
416
|
+
fs_extra_1.default.writeFileSync(versionFile, versionJson);
|
|
417
|
+
}
|
|
270
418
|
});
|
|
271
419
|
}
|
|
272
420
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiot-toolkit",
|
|
3
|
-
"version": "2.0.2-beta.
|
|
3
|
+
"version": "2.0.2-beta.4",
|
|
4
4
|
"description": "Tools for creating, developing, and packaging aiot applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiot"
|
|
@@ -21,17 +21,18 @@
|
|
|
21
21
|
"test": "node ./__tests__/aiot-toolkit.test.js"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@aiot-toolkit/commander": "2.0.2-beta.
|
|
25
|
-
"@aiot-toolkit/emulator": "2.0.2-beta.
|
|
26
|
-
"@aiot-toolkit/shared-utils": "2.0.2-beta.
|
|
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",
|
|
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.
|
|
32
|
+
"create-aiot": "2.0.2-beta.4",
|
|
33
|
+
"dayjs": "^1.11.10",
|
|
33
34
|
"fast-glob": "^3.3.2",
|
|
34
|
-
"file-lane": "2.0.2-beta.
|
|
35
|
+
"file-lane": "2.0.2-beta.4",
|
|
35
36
|
"semver": "^7.6.0",
|
|
36
37
|
"ws": "^8.15.1"
|
|
37
38
|
},
|
|
@@ -40,5 +41,5 @@
|
|
|
40
41
|
"@types/semver": "^7.5.8",
|
|
41
42
|
"@types/ws": "^8.5.10"
|
|
42
43
|
},
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "656add8e64d8101b9f3886957c5b9ae23e2e854f"
|
|
44
45
|
}
|