aiot-toolkit 2.0.1-alpha.9 → 2.0.2-beta.10
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/README.md +32 -29
- package/lib/bin.js +102 -41
- package/lib/builder/IBuilder.js +0 -2
- package/lib/builder/UxBuilder.d.ts +9 -0
- package/lib/builder/UxBuilder.js +69 -23
- package/lib/builder/XtsBuilder.js +30 -12
- package/lib/interface/CommandInterface.js +0 -2
- package/lib/interface/VelaEmulatorInterface.d.ts +6 -0
- package/lib/interface/VelaEmulatorInterface.js +0 -2
- package/lib/starter/IStarter.d.ts +23 -0
- package/lib/starter/IStarter.js +39 -0
- package/lib/starter/UxStarter.d.ts +21 -0
- package/lib/starter/UxStarter.js +186 -0
- package/lib/starter/XtsStarter.d.ts +9 -0
- package/lib/starter/XtsStarter.js +19 -0
- package/lib/utils/AdbUtils.js +2 -11
- package/lib/utils/DeviceUtil.d.ts +1 -1
- package/lib/utils/DeviceUtil.js +22 -93
- package/lib/utils/RequestUtils.js +4 -19
- package/lib/utils/UxBuilderUtils.d.ts +8 -0
- package/lib/utils/UxBuilderUtils.js +51 -0
- package/lib/utils/VelaAvdUtils.d.ts +26 -4
- package/lib/utils/VelaAvdUtils.js +263 -134
- package/lib/waiter.js +0 -2
- package/package.json +17 -11
- package/lib/bin.js.map +0 -1
- package/lib/builder/IBuilder.js.map +0 -1
- package/lib/builder/UxBuilder.js.map +0 -1
- package/lib/builder/XtsBuilder.js.map +0 -1
- package/lib/interface/CommandInterface.js.map +0 -1
- package/lib/interface/VelaEmulatorInterface.js.map +0 -1
- package/lib/starter/GoldfishStarter.d.ts +0 -9
- package/lib/starter/GoldfishStarter.js +0 -108
- package/lib/starter/GoldfishStarter.js.map +0 -1
- package/lib/utils/AdbUtils.js.map +0 -1
- package/lib/utils/DeviceUtil.js.map +0 -1
- package/lib/utils/RequestUtils.js.map +0 -1
- package/lib/utils/VelaAvdUtils.js.map +0 -1
- package/lib/waiter.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 项目介绍
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
aiot-toolkit 2.0 是将 **源码项目** 转换为 **目标代码项目** 并生成 **目标代码应用** 的命令行工具,同时配备了 **模拟器** 相关功能供开发者使用。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
aiot-toolkit2.0目前支持的打包格式如下:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- ux:vela 平台下的应用,目前大量使用于小米手表、音箱等智能穿戴及物联网设备
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## 安装使用
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
- 全局安装
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
import ParamType from '@aiot-toolkit/commander/lib/interface/IParam'
|
|
15
|
-
import IBuild from './IBuild'
|
|
13
|
+
`npm i aiot-toolkit -g`
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
params: ParamType[] = []
|
|
19
|
-
build(projectPath: string, options: any): void {
|
|
20
|
-
throw new Error('Method not implemented.')
|
|
21
|
-
}
|
|
22
|
-
match(projectPath: string): boolean {
|
|
23
|
-
throw new Error('Method not implemented.')
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export default XBuilder
|
|
15
|
+
`npm i create-aiot -g`
|
|
27
16
|
|
|
28
|
-
|
|
17
|
+
- 创建项目
|
|
29
18
|
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
1. `create-aiot ux`
|
|
20
|
+
2. 在项目根目录执行:`npm i`
|
|
32
21
|
|
|
33
|
-
|
|
34
|
-
static readonly PROJECT_TYPE = '项目类型的名称'
|
|
35
|
-
```
|
|
22
|
+
- 本机运行项目
|
|
36
23
|
|
|
37
|
-
|
|
24
|
+
在项目根目录执行 `aiot start`,此会启动模拟器,并运行项目
|
|
38
25
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
* 打包项目
|
|
27
|
+
|
|
28
|
+
在项目根目录执行 `aiot release`
|
|
29
|
+
|
|
30
|
+
## 常用命令
|
|
31
|
+
|
|
32
|
+
| 命令 | 说明 |
|
|
33
|
+
| ------------------------ | ------------------------ |
|
|
34
|
+
| npm create aiot | 创建并手动选择项目 |
|
|
35
|
+
| npm create aiot xts | 创建xts项目 |
|
|
36
|
+
| npm create aiot ux | 创建ux项目 |
|
|
37
|
+
| aiot build | 构建项目 |
|
|
38
|
+
| aiot release | 构建项目-release模式 |
|
|
39
|
+
| aiot start | 构建项目并运行到模拟器 |
|
|
40
|
+
| aiot getConnectedDevices | 获取已连接设备列表 |
|
|
41
|
+
| aiot getPlatforms | 获取设置平台 |
|
|
42
|
+
| aiot installDbgAndMkp | 在真机上安装快应用调试器 |
|
|
43
|
+
| aiot createVelaAvd | 创建 vela 模拟器 |
|
|
44
|
+
| aiot deleteVelaAvd | 删除 vela 模拟器 |
|
package/lib/bin.js
CHANGED
|
@@ -13,22 +13,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const
|
|
17
|
-
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
|
+
const semver_1 = __importDefault(require("semver"));
|
|
18
17
|
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
19
|
-
|
|
18
|
+
// 支持的最低node版本
|
|
19
|
+
const NODE_MINIMUM_VERSION = '16.0.0';
|
|
20
|
+
checkVersion();
|
|
21
|
+
const CompileMode_1 = __importDefault(require("@aiot-toolkit/aiotpack/lib/compiler/enum/CompileMode"));
|
|
22
|
+
const commander_1 = require("@aiot-toolkit/commander");
|
|
23
|
+
const fs_1 = __importDefault(require("fs"));
|
|
24
|
+
const path_1 = __importDefault(require("path"));
|
|
25
|
+
const UxBuilder_1 = __importDefault(require("./builder/UxBuilder"));
|
|
20
26
|
const XtsBuilder_1 = __importDefault(require("./builder/XtsBuilder"));
|
|
21
|
-
const
|
|
27
|
+
const UxStarter_1 = __importDefault(require("./starter/UxStarter"));
|
|
28
|
+
const XtsStarter_1 = __importDefault(require("./starter/XtsStarter"));
|
|
22
29
|
const DeviceUtil_1 = __importDefault(require("./utils/DeviceUtil"));
|
|
23
30
|
const VelaAvdUtils_1 = __importDefault(require("./utils/VelaAvdUtils"));
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
// 校验当前环境中的node
|
|
32
|
+
function checkVersion() {
|
|
33
|
+
const currentVersion = process.versions.node;
|
|
34
|
+
if (semver_1.default.lt(currentVersion, NODE_MINIMUM_VERSION)) {
|
|
35
|
+
ColorConsole_1.default.throw('It is detected that the current NodeJS version ', { word: currentVersion }, ' is too low, please upgrade to NodeJS version higher than ', { word: NODE_MINIMUM_VERSION });
|
|
36
|
+
process.exit();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// 配置支持的 builder 类型,新增的项目类型,需在此处加上类型
|
|
40
|
+
const projectMapper = {
|
|
41
|
+
ux: {
|
|
42
|
+
builder: UxBuilder_1.default,
|
|
43
|
+
starter: UxStarter_1.default
|
|
44
|
+
},
|
|
45
|
+
xts: {
|
|
46
|
+
builder: XtsBuilder_1.default,
|
|
47
|
+
starter: XtsStarter_1.default
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function findBuilder() {
|
|
51
|
+
const projectType = getProjectType();
|
|
52
|
+
return new projectMapper[projectType].builder();
|
|
28
53
|
}
|
|
29
54
|
function build(command, description) {
|
|
30
|
-
const
|
|
31
|
-
const builder = findBuilder(projectPath);
|
|
55
|
+
const builder = findBuilder();
|
|
32
56
|
const paramList = builder === null || builder === void 0 ? void 0 : builder.params;
|
|
33
57
|
return {
|
|
34
58
|
name: command,
|
|
@@ -36,48 +60,60 @@ function build(command, description) {
|
|
|
36
60
|
paramList,
|
|
37
61
|
action: (option) => __awaiter(this, void 0, void 0, function* () {
|
|
38
62
|
// 获取对应的 build;如果存在,执行 build 函数,不存在,提示
|
|
63
|
+
option.mode = command === 'release' ? CompileMode_1.default.PRODUCTION : CompileMode_1.default.DEVELOPMENT;
|
|
39
64
|
const projectPath = process.cwd();
|
|
40
|
-
|
|
41
|
-
if (builder) {
|
|
42
|
-
const { watch } = option;
|
|
43
|
-
yield builder.build(projectPath, option);
|
|
44
|
-
if (watch) {
|
|
45
|
-
waiter_1.default.describe();
|
|
46
|
-
waiter_1.default.start();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
ColorConsole_1.default.log({
|
|
51
|
-
message: `This type of project is not currently supported. The supported projects : xts`,
|
|
52
|
-
level: shared_utils_1.LOG_LEVEL.Error,
|
|
53
|
-
isOnlyPrintError: true
|
|
54
|
-
});
|
|
55
|
-
}
|
|
65
|
+
yield builder.build(projectPath, option);
|
|
56
66
|
})
|
|
57
67
|
};
|
|
58
68
|
}
|
|
69
|
+
function getProjectType() {
|
|
70
|
+
const projectPath = process.cwd();
|
|
71
|
+
const isXts = fs_1.default.existsSync(path_1.default.resolve(projectPath, 'app/app.xts'));
|
|
72
|
+
const isUx = fs_1.default.existsSync(path_1.default.resolve(projectPath, 'src/app.ux'));
|
|
73
|
+
if (isUx) {
|
|
74
|
+
return "ux" /* ProjectType.UX */;
|
|
75
|
+
}
|
|
76
|
+
else if (isXts) {
|
|
77
|
+
return "xts" /* ProjectType.XTS */;
|
|
78
|
+
}
|
|
79
|
+
return "ux" /* ProjectType.UX */;
|
|
80
|
+
}
|
|
81
|
+
function findStarter(command, description) {
|
|
82
|
+
const projectType = getProjectType();
|
|
83
|
+
return new projectMapper[projectType].starter(command, description);
|
|
84
|
+
}
|
|
59
85
|
function main() {
|
|
60
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
const aiotCreate = yield (0, create_aiot_1.getAiotCreateCommand)();
|
|
62
87
|
const config = {
|
|
63
88
|
name: 'aiot-toolkit',
|
|
64
89
|
description: 'contains build, dev, release, etc. commands for aiot toolkit',
|
|
65
|
-
version: '
|
|
90
|
+
version: require('../package.json').version,
|
|
66
91
|
commandList: [
|
|
67
92
|
build('build', 'build project'),
|
|
68
|
-
|
|
93
|
+
build('release', 'release the project'),
|
|
94
|
+
findStarter('start', 'start project').getCommond(),
|
|
95
|
+
{
|
|
96
|
+
name: 'watch',
|
|
97
|
+
description: 'recompile project while file changes',
|
|
98
|
+
action: (option) => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const projectPath = process.cwd();
|
|
100
|
+
const builder = findBuilder();
|
|
101
|
+
option.watch = true;
|
|
102
|
+
yield builder.build(projectPath, option);
|
|
103
|
+
// waiter.describe()
|
|
104
|
+
// waiter.start()
|
|
105
|
+
})
|
|
106
|
+
},
|
|
69
107
|
{
|
|
70
108
|
name: 'getConnectedDevices',
|
|
71
109
|
description: 'get all connected devices',
|
|
72
|
-
action: (
|
|
110
|
+
action: () => __awaiter(this, void 0, void 0, function* () {
|
|
73
111
|
try {
|
|
74
112
|
const connectedDevices = yield DeviceUtil_1.default.getAllConnectedDevices();
|
|
75
|
-
ColorConsole_1.default.
|
|
76
|
-
message: `The connected devices are: ${connectedDevices ? connectedDevices.join(', ') : 'null'}`
|
|
77
|
-
});
|
|
113
|
+
ColorConsole_1.default.info(`The connected devices are: ${connectedDevices ? connectedDevices.join(', ') : 'null'}`);
|
|
78
114
|
}
|
|
79
115
|
catch (error) {
|
|
80
|
-
ColorConsole_1.default.
|
|
116
|
+
ColorConsole_1.default.throw(`Error: getConnectedDevices failed`);
|
|
81
117
|
}
|
|
82
118
|
})
|
|
83
119
|
},
|
|
@@ -126,26 +162,51 @@ function main() {
|
|
|
126
162
|
action: (option) => __awaiter(this, void 0, void 0, function* () {
|
|
127
163
|
try {
|
|
128
164
|
const successMessage = yield DeviceUtil_1.default.installDbgAndMkp(option);
|
|
129
|
-
ColorConsole_1.default.
|
|
165
|
+
ColorConsole_1.default.success(`${successMessage}`);
|
|
130
166
|
}
|
|
131
167
|
catch (error) {
|
|
132
|
-
ColorConsole_1.default.
|
|
168
|
+
ColorConsole_1.default.throw(`installDbgAndMkp failed, errorMessage: ${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}'}`);
|
|
133
169
|
}
|
|
134
170
|
})
|
|
135
171
|
},
|
|
136
172
|
{
|
|
137
|
-
name: '
|
|
138
|
-
description: 'create a vela
|
|
173
|
+
name: 'createVVD',
|
|
174
|
+
description: 'create a vela virtual device',
|
|
139
175
|
action: () => __awaiter(this, void 0, void 0, function* () {
|
|
140
176
|
VelaAvdUtils_1.default.createVelaAvdByInquire();
|
|
141
177
|
})
|
|
142
178
|
},
|
|
143
|
-
|
|
179
|
+
{
|
|
180
|
+
name: 'deleteVVD',
|
|
181
|
+
description: 'delete vela virtual device(s)',
|
|
182
|
+
paramList: [
|
|
183
|
+
{
|
|
184
|
+
name: 'avdNames',
|
|
185
|
+
description: 'avd names to delete',
|
|
186
|
+
enableInquirer: true,
|
|
187
|
+
type: 'checkbox',
|
|
188
|
+
choices: VelaAvdUtils_1.default.velaAvdCls.getVelaAvdList().map((item) => {
|
|
189
|
+
return { name: item.avdName, value: item.avdName };
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
action: (option) => __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
const { avdNames } = option;
|
|
195
|
+
avdNames.forEach((avdName) => {
|
|
196
|
+
VelaAvdUtils_1.default.velaAvdCls.deleteVelaAvd(avdName);
|
|
197
|
+
});
|
|
198
|
+
})
|
|
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
|
+
},
|
|
144
207
|
]
|
|
145
208
|
};
|
|
146
209
|
commander_1.Command.registeProgram(config);
|
|
147
210
|
});
|
|
148
211
|
}
|
|
149
212
|
main();
|
|
150
|
-
|
|
151
|
-
//# sourceMappingURL=bin.js.map
|
package/lib/builder/IBuilder.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
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';
|
|
5
6
|
interface IUxBuilderOption extends Dictionary {
|
|
6
7
|
watch?: boolean;
|
|
7
8
|
mode: CompileMode;
|
|
9
|
+
disabledJsc: boolean;
|
|
10
|
+
enableE2e?: boolean;
|
|
8
11
|
}
|
|
9
12
|
/**
|
|
10
13
|
* UxBuilder
|
|
11
14
|
*/
|
|
12
15
|
declare class UxBuilder implements IBuilder<IUxBuilderOption> {
|
|
13
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>;
|
|
14
23
|
/**
|
|
15
24
|
* ux项目的build函数
|
|
16
25
|
* @param projectPath 项目路径
|
package/lib/builder/UxBuilder.js
CHANGED
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -15,11 +26,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
26
|
const CompileMode_1 = __importDefault(require("@aiot-toolkit/aiotpack/lib/compiler/enum/CompileMode"));
|
|
16
27
|
const JavascriptDefaultCompileOption_1 = __importDefault(require("@aiot-toolkit/aiotpack/lib/compiler/javascript/JavascriptDefaultCompileOption"));
|
|
17
28
|
const UxConfig_1 = __importDefault(require("@aiot-toolkit/aiotpack/lib/config/UxConfig"));
|
|
18
|
-
const
|
|
29
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
30
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
19
31
|
const file_lane_1 = require("file-lane");
|
|
20
32
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
21
33
|
const lodash_1 = __importDefault(require("lodash"));
|
|
22
34
|
const path_1 = __importDefault(require("path"));
|
|
35
|
+
const UxBuilderUtils_1 = __importDefault(require("../utils/UxBuilderUtils"));
|
|
23
36
|
/**
|
|
24
37
|
* UxBuilder
|
|
25
38
|
*/
|
|
@@ -28,10 +41,7 @@ class UxBuilder {
|
|
|
28
41
|
this.QUICKAPP_CONFIG = 'quickapp.config.js';
|
|
29
42
|
this.params = [
|
|
30
43
|
{
|
|
31
|
-
|
|
32
|
-
description: 'inject test-suite for current project'
|
|
33
|
-
},
|
|
34
|
-
{
|
|
44
|
+
type: 'string',
|
|
35
45
|
name: 'devtool',
|
|
36
46
|
description: 'source map config'
|
|
37
47
|
},
|
|
@@ -43,11 +53,51 @@ class UxBuilder {
|
|
|
43
53
|
type: 'confirm',
|
|
44
54
|
name: 'disabled-jsc',
|
|
45
55
|
description: 'disabled jsc bundle',
|
|
46
|
-
defaultValue:
|
|
47
|
-
|
|
56
|
+
defaultValue: false
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'confirm',
|
|
60
|
+
name: 'enable-protobuf',
|
|
61
|
+
description: 'enable protobuf',
|
|
62
|
+
defaultValue: false
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'confirm',
|
|
66
|
+
name: 'enable-e2e',
|
|
67
|
+
description: 'inject test-suite for current project',
|
|
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
|
|
48
81
|
}
|
|
49
82
|
];
|
|
50
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* 获取build的编译配置
|
|
86
|
+
* @param projectPath 项目路径
|
|
87
|
+
* @param options 命令参数
|
|
88
|
+
*/
|
|
89
|
+
getCompilerOption(projectPath, options) {
|
|
90
|
+
// 读取项目中文件的配置
|
|
91
|
+
const quickappConfig = this.readQuickAppConfig(projectPath);
|
|
92
|
+
const _a = quickappConfig || {}, { cli } = _a, otherConfig = __rest(_a, ["cli"]);
|
|
93
|
+
options = lodash_1.default.merge({}, options, cli);
|
|
94
|
+
// 项目配置
|
|
95
|
+
const uxProjectConfig = new UxConfig_1.default(projectPath);
|
|
96
|
+
// 编译配置
|
|
97
|
+
const compileMode = options.mode || CompileMode_1.default.DEVELOPMENT;
|
|
98
|
+
const compilerOption = lodash_1.default.merge(JavascriptDefaultCompileOption_1.default, Object.assign(Object.assign({}, options), { projectPath: path_1.default.join(projectPath, uxProjectConfig.output), mode: compileMode, enableProtobuf: options.enableProtobuf, devtool: UxBuilderUtils_1.default.getDevtoolValue(compileMode, options.devtool || false) }), otherConfig);
|
|
99
|
+
return compilerOption;
|
|
100
|
+
}
|
|
51
101
|
/**
|
|
52
102
|
* ux项目的build函数
|
|
53
103
|
* @param projectPath 项目路径
|
|
@@ -56,24 +106,21 @@ class UxBuilder {
|
|
|
56
106
|
*/
|
|
57
107
|
build(projectPath, options) {
|
|
58
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const
|
|
60
|
-
// 读取项目中文件的配置
|
|
61
|
-
const quickappConfig = this.readQuickAppConfig(projectPath);
|
|
62
|
-
options = lodash_1.default.merge({}, options, quickappConfig === null || quickappConfig === void 0 ? void 0 : quickappConfig.cli);
|
|
109
|
+
const watch = options.watch || false;
|
|
63
110
|
// 项目配置
|
|
64
111
|
const uxProjectConfig = new UxConfig_1.default(projectPath);
|
|
65
112
|
// 编译配置
|
|
66
|
-
const compilerOption =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
disabledJSC: options.disabledJsc
|
|
70
|
-
}, JavascriptDefaultCompileOption_1.default, quickappConfig === null || quickappConfig === void 0 ? void 0 : quickappConfig.webpack);
|
|
71
|
-
ColorConsole2_1.default.info({
|
|
113
|
+
const compilerOption = this.getCompilerOption(projectPath, options);
|
|
114
|
+
ColorConsole_1.default.info('start build: ', {
|
|
115
|
+
style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Info),
|
|
72
116
|
word: JSON.stringify({
|
|
73
|
-
step: 'build ux',
|
|
74
117
|
projectPath,
|
|
75
118
|
options,
|
|
76
|
-
watch
|
|
119
|
+
watch,
|
|
120
|
+
node: process.version,
|
|
121
|
+
platform: process.platform,
|
|
122
|
+
arch: process.arch,
|
|
123
|
+
toolkit: require('../../package.json').version
|
|
77
124
|
}, null, 2)
|
|
78
125
|
});
|
|
79
126
|
// 开始编译项目
|
|
@@ -84,10 +131,11 @@ class UxBuilder {
|
|
|
84
131
|
const path = path_1.default.join(projectPath, this.QUICKAPP_CONFIG);
|
|
85
132
|
if (fs_extra_1.default.existsSync(path)) {
|
|
86
133
|
try {
|
|
87
|
-
|
|
134
|
+
const data = require(path);
|
|
135
|
+
return data;
|
|
88
136
|
}
|
|
89
137
|
catch (error) {
|
|
90
|
-
|
|
138
|
+
ColorConsole_1.default.throw((error === null || error === void 0 ? void 0 : error.toString()) || '');
|
|
91
139
|
}
|
|
92
140
|
}
|
|
93
141
|
return;
|
|
@@ -98,5 +146,3 @@ class UxBuilder {
|
|
|
98
146
|
}
|
|
99
147
|
UxBuilder.PROJECT_TYPE = 'ux quick app';
|
|
100
148
|
exports.default = UxBuilder;
|
|
101
|
-
|
|
102
|
-
//# sourceMappingURL=UxBuilder.js.map
|
|
@@ -18,6 +18,7 @@ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
|
18
18
|
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
19
19
|
const StringUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/StringUtil"));
|
|
20
20
|
const file_lane_1 = require("file-lane");
|
|
21
|
+
const FileLaneUtil_1 = __importDefault(require("file-lane/lib/utils/FileLaneUtil"));
|
|
21
22
|
const fs_1 = __importDefault(require("fs"));
|
|
22
23
|
const path_1 = __importDefault(require("path"));
|
|
23
24
|
/**
|
|
@@ -29,7 +30,7 @@ class XtsBuilder {
|
|
|
29
30
|
{
|
|
30
31
|
name: 'skip',
|
|
31
32
|
type: 'string',
|
|
32
|
-
description:
|
|
33
|
+
description: `Can configure skip steps, comma separated, optional values: ${ICompileOptions_1.skipList.join(',')}`,
|
|
33
34
|
validate(value) {
|
|
34
35
|
// TODO: validate 不起作用
|
|
35
36
|
const res = StringUtil_1.default.string2arrayByComma(value);
|
|
@@ -49,24 +50,41 @@ class XtsBuilder {
|
|
|
49
50
|
return fs_1.default.existsSync(path_1.default.resolve(projectPath, 'app/app.xts'));
|
|
50
51
|
}
|
|
51
52
|
build(projectPath, options) {
|
|
53
|
+
var _a;
|
|
52
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const
|
|
54
|
-
ColorConsole_1.default.
|
|
55
|
-
message: JSON.stringify({
|
|
56
|
-
projectPath,
|
|
57
|
-
options
|
|
58
|
-
}, undefined, 2),
|
|
59
|
-
level: shared_utils_1.LOG_LEVEL.Success
|
|
60
|
-
});
|
|
55
|
+
const watch = options.watch || false;
|
|
56
|
+
ColorConsole_1.default.success('Start build...\n', { word: 'ProjectPath: ', style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Success) }, projectPath, '\n', { word: 'buildOptions: ', style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Success) }, JSON.stringify(options));
|
|
61
57
|
const compilerOptions = {
|
|
62
58
|
skip: StringUtil_1.default.string2arrayByComma(options.skip)
|
|
63
59
|
};
|
|
64
60
|
const config = new aiotpack_1.XtsConfig();
|
|
65
|
-
|
|
61
|
+
if ((_a = compilerOptions.skip) === null || _a === void 0 ? void 0 : _a.includes('xts2ts')) {
|
|
62
|
+
ColorConsole_1.default.info("### skip compile xts to ts due to --skip ${compilerOptions?.skip.join(',')}");
|
|
63
|
+
const context = FileLaneUtil_1.default.createContext(config.output, projectPath);
|
|
64
|
+
const preWorks = config.preWorks || [];
|
|
65
|
+
for (let item of preWorks) {
|
|
66
|
+
try {
|
|
67
|
+
yield item(context, [], config, compilerOptions);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// 报错 prework的item error
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const follWorks = config.followWorks || [];
|
|
74
|
+
for (let item of follWorks) {
|
|
75
|
+
try {
|
|
76
|
+
yield item.worker(context, config, compilerOptions);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
// 报错 prework的item error
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return new file_lane_1.FileLane(config, projectPath, compilerOptions).start({ watch });
|
|
85
|
+
}
|
|
66
86
|
});
|
|
67
87
|
}
|
|
68
88
|
}
|
|
69
89
|
XtsBuilder.PROJECT_TYPE = 'xts quick app';
|
|
70
90
|
exports.default = XtsBuilder;
|
|
71
|
-
|
|
72
|
-
//# sourceMappingURL=XtsBuilder.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ICommand, IParam } from '@aiot-toolkit/commander';
|
|
2
|
+
/**
|
|
3
|
+
* IStarter
|
|
4
|
+
*/
|
|
5
|
+
export default abstract class IStarter<O = any> {
|
|
6
|
+
protected name: string;
|
|
7
|
+
protected description: string;
|
|
8
|
+
/**
|
|
9
|
+
* start 的参数列表
|
|
10
|
+
*/
|
|
11
|
+
readonly params: IParam[];
|
|
12
|
+
constructor(name: string, description: string);
|
|
13
|
+
/**
|
|
14
|
+
* start 的命令
|
|
15
|
+
*/
|
|
16
|
+
getCommond(): ICommand;
|
|
17
|
+
/**
|
|
18
|
+
* 运行项目
|
|
19
|
+
* @param projectPath 项目路径
|
|
20
|
+
* @param options 命令参数
|
|
21
|
+
*/
|
|
22
|
+
abstract start(projectPath: string, options: O): void | Promise<void>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
/**
|
|
13
|
+
* IStarter
|
|
14
|
+
*/
|
|
15
|
+
class IStarter {
|
|
16
|
+
constructor(name, description) {
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.description = description;
|
|
19
|
+
/**
|
|
20
|
+
* start 的参数列表
|
|
21
|
+
*/
|
|
22
|
+
this.params = [];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* start 的命令
|
|
26
|
+
*/
|
|
27
|
+
getCommond() {
|
|
28
|
+
return {
|
|
29
|
+
name: this.name,
|
|
30
|
+
description: this.description,
|
|
31
|
+
paramList: this.params,
|
|
32
|
+
action: (option) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const projectPath = process.cwd();
|
|
34
|
+
this.start(projectPath, option);
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.default = IStarter;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import ParamType from '@aiot-toolkit/commander/lib/interface/IParam';
|
|
2
|
+
import { IStartOptions } from '@aiot-toolkit/emulator';
|
|
3
|
+
import UxBuilder from '../builder/UxBuilder';
|
|
4
|
+
import IStarter from './IStarter';
|
|
5
|
+
/**
|
|
6
|
+
* UxStarter
|
|
7
|
+
* ux快应用启动器
|
|
8
|
+
*/
|
|
9
|
+
declare class UxStarter extends IStarter<IStartOptions> {
|
|
10
|
+
builder: UxBuilder;
|
|
11
|
+
params: ParamType[];
|
|
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;
|
|
20
|
+
}
|
|
21
|
+
export default UxStarter;
|