aiot-toolkit 2.0.2-beta.10 → 2.0.2-beta.11
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 +21 -29
- package/lib/builder/UxBuilder.d.ts +12 -5
- package/lib/builder/UxBuilder.js +22 -15
- package/lib/builder/XtsBuilder.js +9 -12
- package/lib/starter/AndroidUxStart.d.ts +39 -0
- package/lib/starter/AndroidUxStart.js +170 -0
- package/lib/starter/IStarter.d.ts +2 -1
- package/lib/starter/IStarter.js +5 -1
- package/lib/starter/UxStarter.d.ts +3 -2
- package/lib/starter/UxStarter.js +50 -46
- package/lib/starter/XtsStarter.d.ts +2 -2
- package/lib/starter/androidRouter/LinkMode.d.ts +9 -0
- package/lib/starter/androidRouter/LinkMode.js +12 -0
- package/lib/starter/androidRouter/PackageRouter.d.ts +55 -0
- package/lib/starter/androidRouter/PackageRouter.js +152 -0
- package/lib/starter/androidRouter/h5/index.css +167 -0
- package/lib/starter/androidRouter/h5/index.html +58 -0
- package/lib/starter/androidRouter/h5/index.js +66 -0
- package/lib/utils/AdbUtils.js +3 -3
- package/lib/utils/DeviceUtil.js +37 -24
- package/lib/utils/RequestUtils.js +5 -5
- package/lib/utils/VelaAvdUtils.js +70 -62
- package/package.json +13 -8
- package/lib/utils/UxBuilderUtils.d.ts +0 -8
- package/lib/utils/UxBuilderUtils.js +0 -51
package/lib/bin.js
CHANGED
|
@@ -13,17 +13,17 @@ 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 shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
17
|
const semver_1 = __importDefault(require("semver"));
|
|
17
|
-
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
18
18
|
// 支持的最低node版本
|
|
19
19
|
const NODE_MINIMUM_VERSION = '16.0.0';
|
|
20
20
|
checkVersion();
|
|
21
|
-
const
|
|
21
|
+
const aiotpack_1 = require("@aiot-toolkit/aiotpack");
|
|
22
22
|
const commander_1 = require("@aiot-toolkit/commander");
|
|
23
|
-
const
|
|
24
|
-
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const shared_utils_2 = require("@aiot-toolkit/shared-utils");
|
|
25
24
|
const UxBuilder_1 = __importDefault(require("./builder/UxBuilder"));
|
|
26
25
|
const XtsBuilder_1 = __importDefault(require("./builder/XtsBuilder"));
|
|
26
|
+
const AndroidUxStart_1 = __importDefault(require("./starter/AndroidUxStart"));
|
|
27
27
|
const UxStarter_1 = __importDefault(require("./starter/UxStarter"));
|
|
28
28
|
const XtsStarter_1 = __importDefault(require("./starter/XtsStarter"));
|
|
29
29
|
const DeviceUtil_1 = __importDefault(require("./utils/DeviceUtil"));
|
|
@@ -32,23 +32,27 @@ const VelaAvdUtils_1 = __importDefault(require("./utils/VelaAvdUtils"));
|
|
|
32
32
|
function checkVersion() {
|
|
33
33
|
const currentVersion = process.versions.node;
|
|
34
34
|
if (semver_1.default.lt(currentVersion, NODE_MINIMUM_VERSION)) {
|
|
35
|
-
|
|
35
|
+
shared_utils_1.ColorConsole.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
36
|
process.exit();
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
// 配置支持的 builder 类型,新增的项目类型,需在此处加上类型
|
|
40
40
|
const projectMapper = {
|
|
41
|
-
|
|
41
|
+
[shared_utils_2.ProjectType.VELA_UX]: {
|
|
42
42
|
builder: UxBuilder_1.default,
|
|
43
43
|
starter: UxStarter_1.default
|
|
44
44
|
},
|
|
45
|
-
|
|
45
|
+
[shared_utils_2.ProjectType.VELA_XTS]: {
|
|
46
46
|
builder: XtsBuilder_1.default,
|
|
47
47
|
starter: XtsStarter_1.default
|
|
48
|
+
},
|
|
49
|
+
[shared_utils_2.ProjectType.ANDDROID_UX]: {
|
|
50
|
+
builder: UxBuilder_1.default,
|
|
51
|
+
starter: AndroidUxStart_1.default
|
|
48
52
|
}
|
|
49
53
|
};
|
|
50
54
|
function findBuilder() {
|
|
51
|
-
const projectType = getProjectType();
|
|
55
|
+
const projectType = shared_utils_2.ProjectType.getProjectType(process.cwd());
|
|
52
56
|
return new projectMapper[projectType].builder();
|
|
53
57
|
}
|
|
54
58
|
function build(command, description) {
|
|
@@ -60,26 +64,14 @@ function build(command, description) {
|
|
|
60
64
|
paramList,
|
|
61
65
|
action: (option) => __awaiter(this, void 0, void 0, function* () {
|
|
62
66
|
// 获取对应的 build;如果存在,执行 build 函数,不存在,提示
|
|
63
|
-
option.mode = command === 'release' ?
|
|
67
|
+
option.mode = command === 'release' ? aiotpack_1.CompileMode.PRODUCTION : aiotpack_1.CompileMode.DEVELOPMENT;
|
|
64
68
|
const projectPath = process.cwd();
|
|
65
69
|
yield builder.build(projectPath, option);
|
|
66
70
|
})
|
|
67
71
|
};
|
|
68
72
|
}
|
|
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
73
|
function findStarter(command, description) {
|
|
82
|
-
const projectType = getProjectType();
|
|
74
|
+
const projectType = shared_utils_2.ProjectType.getProjectType(process.cwd());
|
|
83
75
|
return new projectMapper[projectType].starter(command, description);
|
|
84
76
|
}
|
|
85
77
|
function main() {
|
|
@@ -100,8 +92,6 @@ function main() {
|
|
|
100
92
|
const builder = findBuilder();
|
|
101
93
|
option.watch = true;
|
|
102
94
|
yield builder.build(projectPath, option);
|
|
103
|
-
// waiter.describe()
|
|
104
|
-
// waiter.start()
|
|
105
95
|
})
|
|
106
96
|
},
|
|
107
97
|
{
|
|
@@ -110,10 +100,10 @@ function main() {
|
|
|
110
100
|
action: () => __awaiter(this, void 0, void 0, function* () {
|
|
111
101
|
try {
|
|
112
102
|
const connectedDevices = yield DeviceUtil_1.default.getAllConnectedDevices();
|
|
113
|
-
|
|
103
|
+
shared_utils_1.ColorConsole.info(`The connected devices are: ${connectedDevices ? connectedDevices.join(', ') : 'null'}`);
|
|
114
104
|
}
|
|
115
105
|
catch (error) {
|
|
116
|
-
|
|
106
|
+
shared_utils_1.ColorConsole.throw(`Error: getConnectedDevices failed`);
|
|
117
107
|
}
|
|
118
108
|
})
|
|
119
109
|
},
|
|
@@ -162,10 +152,12 @@ function main() {
|
|
|
162
152
|
action: (option) => __awaiter(this, void 0, void 0, function* () {
|
|
163
153
|
try {
|
|
164
154
|
const successMessage = yield DeviceUtil_1.default.installDbgAndMkp(option);
|
|
165
|
-
|
|
155
|
+
shared_utils_1.ColorConsole.success(`${successMessage}`);
|
|
166
156
|
}
|
|
167
157
|
catch (error) {
|
|
168
|
-
|
|
158
|
+
shared_utils_1.ColorConsole.throw(`installDbgAndMkp failed, errorMessage:'}`, {
|
|
159
|
+
word: (error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'
|
|
160
|
+
});
|
|
169
161
|
}
|
|
170
162
|
})
|
|
171
163
|
},
|
|
@@ -203,7 +195,7 @@ function main() {
|
|
|
203
195
|
action: () => __awaiter(this, void 0, void 0, function* () {
|
|
204
196
|
VelaAvdUtils_1.default.initEmulatorEnv();
|
|
205
197
|
})
|
|
206
|
-
}
|
|
198
|
+
}
|
|
207
199
|
]
|
|
208
200
|
};
|
|
209
201
|
commander_1.Command.registeProgram(config);
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import CompileMode from '@aiot-toolkit/aiotpack
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
|
|
1
|
+
import { CompileMode, IJavascriptCompileOption } from '@aiot-toolkit/aiotpack';
|
|
2
|
+
import { IParam } from '@aiot-toolkit/commander';
|
|
3
|
+
import { Dictionary } from '@aiot-toolkit/shared-utils';
|
|
5
4
|
import IBuilder from './IBuilder';
|
|
6
5
|
interface IUxBuilderOption extends Dictionary {
|
|
7
6
|
watch?: boolean;
|
|
8
7
|
mode: CompileMode;
|
|
9
8
|
disabledJsc: boolean;
|
|
10
9
|
enableE2e?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 是否自动补全 manifest.json 中的 features 配置
|
|
12
|
+
*/
|
|
13
|
+
completeFeature?: boolean;
|
|
11
14
|
}
|
|
12
15
|
/**
|
|
13
16
|
* UxBuilder
|
|
14
17
|
*/
|
|
15
18
|
declare class UxBuilder implements IBuilder<IUxBuilderOption> {
|
|
19
|
+
private readonly events?;
|
|
16
20
|
readonly QUICKAPP_CONFIG = "quickapp.config.js";
|
|
21
|
+
constructor(events?: {
|
|
22
|
+
onBuildSuccess?: (() => void) | undefined;
|
|
23
|
+
} | undefined);
|
|
17
24
|
/**
|
|
18
25
|
* 获取build的编译配置
|
|
19
26
|
* @param projectPath 项目路径
|
|
@@ -29,7 +36,7 @@ declare class UxBuilder implements IBuilder<IUxBuilderOption> {
|
|
|
29
36
|
build(projectPath: string, options: IUxBuilderOption): Promise<void>;
|
|
30
37
|
private readQuickAppConfig;
|
|
31
38
|
static readonly PROJECT_TYPE = "ux quick app";
|
|
32
|
-
params:
|
|
39
|
+
params: IParam[];
|
|
33
40
|
match(projectPath: string): boolean;
|
|
34
41
|
}
|
|
35
42
|
export default UxBuilder;
|
package/lib/builder/UxBuilder.js
CHANGED
|
@@ -23,21 +23,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const
|
|
27
|
-
const JavascriptDefaultCompileOption_1 = __importDefault(require("@aiot-toolkit/aiotpack/lib/compiler/javascript/JavascriptDefaultCompileOption"));
|
|
28
|
-
const UxConfig_1 = __importDefault(require("@aiot-toolkit/aiotpack/lib/config/UxConfig"));
|
|
26
|
+
const aiotpack_1 = require("@aiot-toolkit/aiotpack");
|
|
29
27
|
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
30
|
-
const
|
|
28
|
+
const shared_utils_2 = require("@aiot-toolkit/shared-utils");
|
|
31
29
|
const file_lane_1 = require("file-lane");
|
|
32
30
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
33
31
|
const lodash_1 = __importDefault(require("lodash"));
|
|
34
32
|
const path_1 = __importDefault(require("path"));
|
|
35
|
-
const
|
|
33
|
+
const fs_1 = __importDefault(require("fs"));
|
|
34
|
+
const path_2 = __importDefault(require("path"));
|
|
36
35
|
/**
|
|
37
36
|
* UxBuilder
|
|
38
37
|
*/
|
|
39
38
|
class UxBuilder {
|
|
40
|
-
constructor() {
|
|
39
|
+
constructor(events) {
|
|
40
|
+
this.events = events;
|
|
41
41
|
this.QUICKAPP_CONFIG = 'quickapp.config.js';
|
|
42
42
|
this.params = [
|
|
43
43
|
{
|
|
@@ -78,6 +78,12 @@ class UxBuilder {
|
|
|
78
78
|
name: 'optimize-css-attr',
|
|
79
79
|
description: 'optimize css attr',
|
|
80
80
|
defaultValue: false
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: 'confirm',
|
|
84
|
+
name: 'complete-feature',
|
|
85
|
+
description: 'auto complete the features are used in the code into the features field of the manifest.json file',
|
|
86
|
+
defaultValue: false
|
|
81
87
|
}
|
|
82
88
|
];
|
|
83
89
|
}
|
|
@@ -92,10 +98,10 @@ class UxBuilder {
|
|
|
92
98
|
const _a = quickappConfig || {}, { cli } = _a, otherConfig = __rest(_a, ["cli"]);
|
|
93
99
|
options = lodash_1.default.merge({}, options, cli);
|
|
94
100
|
// 项目配置
|
|
95
|
-
const uxProjectConfig = new
|
|
101
|
+
const uxProjectConfig = new aiotpack_1.UxConfig(projectPath);
|
|
96
102
|
// 编译配置
|
|
97
|
-
const compileMode = options.mode ||
|
|
98
|
-
const compilerOption = lodash_1.default.merge(
|
|
103
|
+
const compileMode = options.mode || aiotpack_1.CompileMode.DEVELOPMENT;
|
|
104
|
+
const compilerOption = lodash_1.default.merge(aiotpack_1.JavascriptDefaultCompileOption, Object.assign(Object.assign({}, options), { projectPath: path_1.default.join(projectPath, uxProjectConfig.output), mode: compileMode, enableProtobuf: options.enableProtobuf }), otherConfig);
|
|
99
105
|
return compilerOption;
|
|
100
106
|
}
|
|
101
107
|
/**
|
|
@@ -108,11 +114,11 @@ class UxBuilder {
|
|
|
108
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
115
|
const watch = options.watch || false;
|
|
110
116
|
// 项目配置
|
|
111
|
-
const uxProjectConfig = new
|
|
117
|
+
const uxProjectConfig = new aiotpack_1.UxConfig(projectPath);
|
|
112
118
|
// 编译配置
|
|
113
119
|
const compilerOption = this.getCompilerOption(projectPath, options);
|
|
114
|
-
|
|
115
|
-
style:
|
|
120
|
+
shared_utils_2.ColorConsole.info('start build: ', {
|
|
121
|
+
style: shared_utils_2.ColorConsole.getStyle(shared_utils_1.Loglevel.INFO),
|
|
116
122
|
word: JSON.stringify({
|
|
117
123
|
projectPath,
|
|
118
124
|
options,
|
|
@@ -124,7 +130,7 @@ class UxBuilder {
|
|
|
124
130
|
}, null, 2)
|
|
125
131
|
});
|
|
126
132
|
// 开始编译项目
|
|
127
|
-
yield new file_lane_1.FileLane(uxProjectConfig, projectPath, compilerOption).start({ watch });
|
|
133
|
+
yield new file_lane_1.FileLane(uxProjectConfig, projectPath, compilerOption, this.events).start({ watch });
|
|
128
134
|
});
|
|
129
135
|
}
|
|
130
136
|
readQuickAppConfig(projectPath) {
|
|
@@ -135,13 +141,14 @@ class UxBuilder {
|
|
|
135
141
|
return data;
|
|
136
142
|
}
|
|
137
143
|
catch (error) {
|
|
138
|
-
|
|
144
|
+
shared_utils_2.ColorConsole.throw((error === null || error === void 0 ? void 0 : error.toString()) || '');
|
|
139
145
|
}
|
|
140
146
|
}
|
|
141
147
|
return;
|
|
142
148
|
}
|
|
143
149
|
match(projectPath) {
|
|
144
|
-
|
|
150
|
+
// src/app.ux 存在视为ux项目
|
|
151
|
+
return fs_1.default.existsSync(path_2.default.resolve(projectPath, 'src/app.ux'));
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
UxBuilder.PROJECT_TYPE = 'ux quick app';
|
|
@@ -13,12 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const aiotpack_1 = require("@aiot-toolkit/aiotpack");
|
|
16
|
-
const
|
|
16
|
+
const aiotpack_2 = require("@aiot-toolkit/aiotpack");
|
|
17
17
|
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
18
|
-
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
19
|
-
const StringUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/StringUtil"));
|
|
20
18
|
const file_lane_1 = require("file-lane");
|
|
21
|
-
const FileLaneUtil_1 = __importDefault(require("file-lane/lib/utils/FileLaneUtil"));
|
|
22
19
|
const fs_1 = __importDefault(require("fs"));
|
|
23
20
|
const path_1 = __importDefault(require("path"));
|
|
24
21
|
/**
|
|
@@ -30,15 +27,15 @@ class XtsBuilder {
|
|
|
30
27
|
{
|
|
31
28
|
name: 'skip',
|
|
32
29
|
type: 'string',
|
|
33
|
-
description: `Can configure skip steps, comma separated, optional values: ${
|
|
30
|
+
description: `Can configure skip steps, comma separated, optional values: ${aiotpack_2.skipList.join(',')}`,
|
|
34
31
|
validate(value) {
|
|
35
32
|
// TODO: validate 不起作用
|
|
36
|
-
const res =
|
|
33
|
+
const res = shared_utils_1.StringUtil.string2arrayByComma(value);
|
|
37
34
|
const unValid = res.find((r) => {
|
|
38
|
-
return !
|
|
35
|
+
return !aiotpack_2.skipList.includes(r);
|
|
39
36
|
});
|
|
40
37
|
if (unValid) {
|
|
41
|
-
return `${unValid} is unvalidate, validate value are ${
|
|
38
|
+
return `${unValid} is unvalidate, validate value are ${aiotpack_2.skipList.join(',')}, Multiple values separated by commas`;
|
|
42
39
|
}
|
|
43
40
|
return true;
|
|
44
41
|
}
|
|
@@ -53,14 +50,14 @@ class XtsBuilder {
|
|
|
53
50
|
var _a;
|
|
54
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
52
|
const watch = options.watch || false;
|
|
56
|
-
|
|
53
|
+
shared_utils_1.ColorConsole.success('Start build...\n', { word: 'ProjectPath: ', style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.SUCCESS) }, projectPath, '\n', { word: 'buildOptions: ', style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.SUCCESS) }, JSON.stringify(options));
|
|
57
54
|
const compilerOptions = {
|
|
58
|
-
skip:
|
|
55
|
+
skip: shared_utils_1.StringUtil.string2arrayByComma(options.skip)
|
|
59
56
|
};
|
|
60
57
|
const config = new aiotpack_1.XtsConfig();
|
|
61
58
|
if ((_a = compilerOptions.skip) === null || _a === void 0 ? void 0 : _a.includes('xts2ts')) {
|
|
62
|
-
|
|
63
|
-
const context =
|
|
59
|
+
shared_utils_1.ColorConsole.info("### skip compile xts to ts due to --skip ${compilerOptions?.skip.join(',')}");
|
|
60
|
+
const context = file_lane_1.FileLaneUtil.createContext(config.output, projectPath);
|
|
64
61
|
const preWorks = config.preWorks || [];
|
|
65
62
|
for (let item of preWorks) {
|
|
66
63
|
try {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import IStarter from './IStarter';
|
|
2
|
+
import { PersistentCommand } from '@aiot-toolkit/commander';
|
|
3
|
+
/**
|
|
4
|
+
* AndroidUxStart
|
|
5
|
+
*
|
|
6
|
+
* 1. 启动本机开发者http服务器,并提供二维码,以下载 rpk
|
|
7
|
+
* 2. 打包 rpk,并监听文件变化,重新打包
|
|
8
|
+
*/
|
|
9
|
+
declare class AndroidUxStart extends IStarter {
|
|
10
|
+
private server?;
|
|
11
|
+
private port?;
|
|
12
|
+
private builder?;
|
|
13
|
+
private projectPath;
|
|
14
|
+
get waiter(): PersistentCommand;
|
|
15
|
+
/**
|
|
16
|
+
* 启动
|
|
17
|
+
* 1. build 项目
|
|
18
|
+
* 2. build 成功,则创建http服务器
|
|
19
|
+
*/
|
|
20
|
+
start(projectPath: string, options: any): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* 创建服务器
|
|
23
|
+
*
|
|
24
|
+
* 1. 使用 koa 创建服务器
|
|
25
|
+
* 2. 显示服务器地址和二维码
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
private createServer;
|
|
29
|
+
private showAddress;
|
|
30
|
+
private build;
|
|
31
|
+
dispose(): void;
|
|
32
|
+
/**
|
|
33
|
+
* 通知已知的设备,应用有更新
|
|
34
|
+
* @param projectPath
|
|
35
|
+
* @param options
|
|
36
|
+
*/
|
|
37
|
+
private noticeDeviceListUpdate;
|
|
38
|
+
}
|
|
39
|
+
export default AndroidUxStart;
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const aiotpack_1 = require("@aiot-toolkit/aiotpack");
|
|
16
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
const http_1 = __importDefault(require("http"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const UxBuilder_1 = __importDefault(require("../builder/UxBuilder"));
|
|
21
|
+
const IStarter_1 = __importDefault(require("./IStarter"));
|
|
22
|
+
const PackageRouter_1 = __importDefault(require("./androidRouter/PackageRouter"));
|
|
23
|
+
const commander_1 = require("@aiot-toolkit/commander");
|
|
24
|
+
/**
|
|
25
|
+
* AndroidUxStart
|
|
26
|
+
*
|
|
27
|
+
* 1. 启动本机开发者http服务器,并提供二维码,以下载 rpk
|
|
28
|
+
* 2. 打包 rpk,并监听文件变化,重新打包
|
|
29
|
+
*/
|
|
30
|
+
class AndroidUxStart extends IStarter_1.default {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
this.projectPath = '';
|
|
34
|
+
}
|
|
35
|
+
get waiter() {
|
|
36
|
+
return new commander_1.PersistentCommand({
|
|
37
|
+
description: 'you can press follow keys to do something',
|
|
38
|
+
options: [
|
|
39
|
+
{
|
|
40
|
+
key: 'q',
|
|
41
|
+
description: 'show qrcode',
|
|
42
|
+
action: () => {
|
|
43
|
+
this.showAddress();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
key: '?',
|
|
48
|
+
description: 'show waiter desc',
|
|
49
|
+
action: () => {
|
|
50
|
+
this.waiter.clearLog();
|
|
51
|
+
this.waiter.describe();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 启动
|
|
59
|
+
* 1. build 项目
|
|
60
|
+
* 2. build 成功,则创建http服务器
|
|
61
|
+
*/
|
|
62
|
+
start(projectPath, options) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
this.projectPath = projectPath;
|
|
65
|
+
const buildOption = Object.assign(Object.assign({}, aiotpack_1.JavascriptDefaultCompileOption), options);
|
|
66
|
+
yield this.build(projectPath, buildOption);
|
|
67
|
+
yield this.createServer(buildOption);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 创建服务器
|
|
72
|
+
*
|
|
73
|
+
* 1. 使用 koa 创建服务器
|
|
74
|
+
* 2. 显示服务器地址和二维码
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
createServer(options) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const routeConfigList = [
|
|
81
|
+
new PackageRouter_1.default({
|
|
82
|
+
projectPath: this.projectPath,
|
|
83
|
+
options
|
|
84
|
+
})
|
|
85
|
+
];
|
|
86
|
+
const data = yield shared_utils_1.NetworkUtil.createHttpServer({
|
|
87
|
+
wantPort: options.server.port,
|
|
88
|
+
routeConfigList,
|
|
89
|
+
staticFolder: path_1.default.join(__dirname, './androidRouter/h5'),
|
|
90
|
+
events: {
|
|
91
|
+
onSuccess: () => {
|
|
92
|
+
this.server = data.server;
|
|
93
|
+
this.port = data.port;
|
|
94
|
+
this.showAddress();
|
|
95
|
+
resolve(data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
showAddress() {
|
|
103
|
+
const ip = shared_utils_1.NetworkUtil.getIPv4IPAddress();
|
|
104
|
+
const { port } = this;
|
|
105
|
+
if (!ip) {
|
|
106
|
+
const localUrl = `http://localhost:${port}`;
|
|
107
|
+
shared_utils_1.ColorConsole.warn(`devServer`, localUrl);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const lanUrl = `http://${ip}:${port}`;
|
|
111
|
+
// 显示二维码
|
|
112
|
+
shared_utils_1.ColorConsole.info(`devServer`, lanUrl);
|
|
113
|
+
shared_utils_1.CommonUtil.outputQRCodeOnTerminal(lanUrl);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
build(projectPath, options) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
if (!this.builder) {
|
|
119
|
+
this.builder = new UxBuilder_1.default({
|
|
120
|
+
onBuildSuccess: () => {
|
|
121
|
+
this.noticeDeviceListUpdate(projectPath, options);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
yield this.builder.build(projectPath, Object.assign(Object.assign({}, options), { watch: true }));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
dispose() {
|
|
129
|
+
var _a;
|
|
130
|
+
(_a = this.server) === null || _a === void 0 ? void 0 : _a.close();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 通知已知的设备,应用有更新
|
|
134
|
+
* @param projectPath
|
|
135
|
+
* @param options
|
|
136
|
+
*/
|
|
137
|
+
noticeDeviceListUpdate(projectPath, options) {
|
|
138
|
+
var _a;
|
|
139
|
+
const { clientRecordPath } = options;
|
|
140
|
+
const json = fs_extra_1.default.readJSONSync(clientRecordPath, { throws: false });
|
|
141
|
+
const deviceList = (_a = json === null || json === void 0 ? void 0 : json.records) === null || _a === void 0 ? void 0 : _a[projectPath];
|
|
142
|
+
if (deviceList) {
|
|
143
|
+
deviceList.forEach((item) => {
|
|
144
|
+
const { ip, port } = item;
|
|
145
|
+
if (!ip) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const url = `http://${ip}:${port}/update`;
|
|
149
|
+
const requestOption = { host: ip, port, path: '/update', timeout: 3000 };
|
|
150
|
+
http_1.default
|
|
151
|
+
.request(requestOption, () => {
|
|
152
|
+
shared_utils_1.ColorConsole.success(`Notify the phone to update the rpk file success`, {
|
|
153
|
+
word: url
|
|
154
|
+
});
|
|
155
|
+
})
|
|
156
|
+
.on('error', (error) => {
|
|
157
|
+
shared_utils_1.ColorConsole.warn(`Notify the phone to update the rpk file`, { word: 'error: ' }, {
|
|
158
|
+
word: error.message
|
|
159
|
+
});
|
|
160
|
+
})
|
|
161
|
+
.on('timeout', () => {
|
|
162
|
+
shared_utils_1.ColorConsole.warn(`Notify the phone to update the rpk file`, { word: 'timeout: ' }, {
|
|
163
|
+
word: url
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.default = AndroidUxStart;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICommand, IParam } from '@aiot-toolkit/commander';
|
|
1
|
+
import { ICommand, IParam, PersistentCommand } from '@aiot-toolkit/commander';
|
|
2
2
|
/**
|
|
3
3
|
* IStarter
|
|
4
4
|
*/
|
|
@@ -10,6 +10,7 @@ export default abstract class IStarter<O = any> {
|
|
|
10
10
|
*/
|
|
11
11
|
readonly params: IParam[];
|
|
12
12
|
constructor(name: string, description: string);
|
|
13
|
+
get waiter(): PersistentCommand | undefined;
|
|
13
14
|
/**
|
|
14
15
|
* start 的命令
|
|
15
16
|
*/
|
package/lib/starter/IStarter.js
CHANGED
|
@@ -21,6 +21,9 @@ class IStarter {
|
|
|
21
21
|
*/
|
|
22
22
|
this.params = [];
|
|
23
23
|
}
|
|
24
|
+
get waiter() {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
24
27
|
/**
|
|
25
28
|
* start 的命令
|
|
26
29
|
*/
|
|
@@ -29,9 +32,10 @@ class IStarter {
|
|
|
29
32
|
name: this.name,
|
|
30
33
|
description: this.description,
|
|
31
34
|
paramList: this.params,
|
|
35
|
+
waiter: this.waiter,
|
|
32
36
|
action: (option) => __awaiter(this, void 0, void 0, function* () {
|
|
33
37
|
const projectPath = process.cwd();
|
|
34
|
-
this.start(projectPath, option);
|
|
38
|
+
return this.start(projectPath, option);
|
|
35
39
|
})
|
|
36
40
|
};
|
|
37
41
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IParam } from '@aiot-toolkit/commander';
|
|
2
2
|
import { IStartOptions } from '@aiot-toolkit/emulator';
|
|
3
3
|
import UxBuilder from '../builder/UxBuilder';
|
|
4
4
|
import IStarter from './IStarter';
|
|
@@ -7,8 +7,9 @@ import IStarter from './IStarter';
|
|
|
7
7
|
* ux快应用启动器
|
|
8
8
|
*/
|
|
9
9
|
declare class UxStarter extends IStarter<IStartOptions> {
|
|
10
|
+
private ws;
|
|
10
11
|
builder: UxBuilder;
|
|
11
|
-
params:
|
|
12
|
+
params: IParam[];
|
|
12
13
|
start(projectPath: string, options: any): Promise<void>;
|
|
13
14
|
/**
|
|
14
15
|
* 检查选择的模拟器在当前环境下是否可以使用
|