aiot-toolkit 2.0.3-beta.7 → 2.0.3-beta.9

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/index.js CHANGED
@@ -1,14 +1,49 @@
1
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
- exports.CompileMode = exports.FileLaneTriggerType = exports.AndroidUxBuilder = exports.VelaUxBuilder = void 0;
7
- const VelaUxBuilder_1 = __importDefault(require("./builder/VelaUxBuilder"));
8
- exports.VelaUxBuilder = VelaUxBuilder_1.default;
9
- const AndroidUxBuilder_1 = __importDefault(require("./builder/AndroidUxBuilder"));
10
- exports.AndroidUxBuilder = AndroidUxBuilder_1.default;
11
- const FileLaneTriggerType_1 = __importDefault(require("file-lane/lib/enum/FileLaneTriggerType"));
12
- exports.FileLaneTriggerType = FileLaneTriggerType_1.default;
13
- const aiotpack_1 = require("@aiot-toolkit/aiotpack");
14
- Object.defineProperty(exports, "CompileMode", { enumerable: true, get: function () { return aiotpack_1.CompileMode; } });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "AndroidUxBuilder", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _AndroidUxBuilder.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "CompileMode", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _aiotpack.CompileMode;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "FileLaneTriggerType", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _FileLaneTriggerType.default;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "IFileLaneEvents", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _IFileLaneEvents.default;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "IFileLaneSuccessData", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _IFileLaneEvents.IFileLaneSuccessData;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "VelaUxBuilder", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _VelaUxBuilder.default;
40
+ }
41
+ });
42
+ var _VelaUxBuilder = _interopRequireDefault(require("./builder/VelaUxBuilder"));
43
+ var _AndroidUxBuilder = _interopRequireDefault(require("./builder/AndroidUxBuilder"));
44
+ var _FileLaneTriggerType = _interopRequireDefault(require("file-lane/lib/enum/FileLaneTriggerType"));
45
+ var _aiotpack = require("@aiot-toolkit/aiotpack");
46
+ var _IFileLaneEvents = _interopRequireWildcard(require("file-lane/lib/interface/IFileLaneEvents"));
47
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
48
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
49
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -1,2 +1,5 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1,2 +1,5 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1,171 +1,171 @@
1
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 commander_1 = require("@aiot-toolkit/commander");
17
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
18
- const fs_extra_1 = __importDefault(require("fs-extra"));
19
- const http_1 = __importDefault(require("http"));
20
- const path_1 = __importDefault(require("path"));
21
- const AndroidUxBuilder_1 = __importDefault(require("../builder/AndroidUxBuilder"));
22
- const IStarter_1 = __importDefault(require("./IStarter"));
23
- const PackageRouter_1 = __importDefault(require("./androidRouter/PackageRouter"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _aiotpack = require("@aiot-toolkit/aiotpack");
8
+ var _commander = require("@aiot-toolkit/commander");
9
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
10
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
+ var _http = _interopRequireDefault(require("http"));
12
+ var _path = _interopRequireDefault(require("path"));
13
+ var _AndroidUxBuilder = _interopRequireDefault(require("../builder/AndroidUxBuilder"));
14
+ var _IStarter = _interopRequireDefault(require("./IStarter"));
15
+ var _PackageRouter = _interopRequireDefault(require("./androidRouter/PackageRouter"));
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
17
  /**
25
18
  * AndroidUxStart
26
19
  *
27
20
  * 1. 启动本机开发者http服务器,并提供二维码,以下载 rpk
28
21
  * 2. 打包 rpk,并监听文件变化,重新打包
29
22
  */
30
- class AndroidUxStart extends IStarter_1.default {
31
- constructor() {
32
- super(...arguments);
33
- this.builder = new AndroidUxBuilder_1.default();
34
- this.projectPath = '';
35
- this.params = [...this.builder.params];
36
- }
37
- get waiter() {
38
- return new commander_1.PersistentCommand({
39
- description: 'you can press follow keys to do something',
40
- options: [
41
- {
42
- key: 'q',
43
- description: 'show qrcode',
44
- action: () => {
45
- this.showAddress();
46
- }
47
- },
48
- {
49
- key: '?',
50
- description: 'show waiter desc',
51
- action: () => {
52
- this.waiter.clearLog();
53
- this.waiter.describe();
54
- }
55
- }
56
- ]
57
- });
58
- }
59
- /**
60
- * 启动
61
- * 1. build 项目
62
- * 2. build 成功,则创建http服务器
63
- */
64
- start(projectPath, options) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- this.projectPath = projectPath;
67
- const buildOption = Object.assign(Object.assign({}, aiotpack_1.JavascriptDefaultCompileOption), options);
68
- yield this.build(projectPath, buildOption);
69
- yield this.createServer(buildOption);
70
- });
71
- }
72
- /**
73
- * 创建服务器
74
- *
75
- * 1. 使用 koa 创建服务器
76
- * 2. 显示服务器地址和二维码
77
- * @returns
78
- */
79
- createServer(options) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
82
- const routeConfigList = [
83
- new PackageRouter_1.default({
84
- projectPath: this.projectPath,
85
- options
86
- })
87
- ];
88
- const data = yield shared_utils_1.NetworkUtil.createHttpServer({
89
- wantPort: options.server.port,
90
- routeConfigList,
91
- staticFolder: path_1.default.join(__dirname, './androidRouter/h5'),
92
- events: {
93
- onSuccess: () => {
94
- this.server = data.server;
95
- this.port = data.port;
96
- this.showAddress();
97
- resolve(data);
98
- }
99
- }
100
- });
101
- }));
102
- });
103
- }
104
- showAddress() {
105
- const ip = shared_utils_1.NetworkUtil.getIPv4IPAddress();
106
- const { port } = this;
107
- if (!ip) {
108
- const localUrl = `http://localhost:${port}`;
109
- shared_utils_1.ColorConsole.warn(`devServer`, localUrl);
23
+ class AndroidUxStart extends _IStarter.default {
24
+ builder = (() => new _AndroidUxBuilder.default())();
25
+ projectPath = '';
26
+ params = (() => [...this.builder.params])();
27
+ get waiter() {
28
+ return new _commander.PersistentCommand({
29
+ description: 'you can press follow keys to do something',
30
+ options: [{
31
+ key: 'q',
32
+ description: 'show qrcode',
33
+ action: () => {
34
+ this.showAddress();
110
35
  }
111
- else {
112
- const lanUrl = `http://${ip}:${port}`;
113
- // 显示二维码
114
- shared_utils_1.ColorConsole.info(`devServer`, lanUrl);
115
- shared_utils_1.CommonUtil.outputQRCodeOnTerminal(lanUrl);
36
+ }, {
37
+ key: '?',
38
+ description: 'show waiter desc',
39
+ action: () => {
40
+ this.waiter.clearLog();
41
+ this.waiter.describe();
116
42
  }
43
+ }]
44
+ });
45
+ }
46
+
47
+ /**
48
+ * 启动
49
+ * 1. build 项目
50
+ * 2. build 成功,则创建http服务器
51
+ */
52
+ async start(projectPath, options) {
53
+ this.projectPath = projectPath;
54
+ const buildOption = {
55
+ ..._aiotpack.JavascriptDefaultCompileOption,
56
+ ...options
57
+ };
58
+ await this.build(projectPath, buildOption);
59
+ await this.createServer(buildOption);
60
+ }
61
+
62
+ /**
63
+ * 创建服务器
64
+ *
65
+ * 1. 使用 koa 创建服务器
66
+ * 2. 显示服务器地址和二维码
67
+ * @returns
68
+ */
69
+ async createServer(options) {
70
+ return new Promise(async resolve => {
71
+ const routeConfigList = [new _PackageRouter.default({
72
+ projectPath: this.projectPath,
73
+ options
74
+ })];
75
+ const data = await _sharedUtils.NetworkUtil.createHttpServer({
76
+ wantPort: options.server.port,
77
+ routeConfigList,
78
+ staticFolder: _path.default.join(__dirname, './androidRouter/h5'),
79
+ events: {
80
+ onSuccess: () => {
81
+ this.server = data.server;
82
+ this.port = data.port;
83
+ this.showAddress();
84
+ resolve(data);
85
+ }
86
+ }
87
+ });
88
+ });
89
+ }
90
+ showAddress() {
91
+ const ip = _sharedUtils.NetworkUtil.getIPv4IPAddress();
92
+ const {
93
+ port
94
+ } = this;
95
+ if (!ip) {
96
+ const localUrl = `http://localhost:${port}`;
97
+ _sharedUtils.ColorConsole.warn(`devServer`, localUrl);
98
+ } else {
99
+ const lanUrl = `http://${ip}:${port}`;
100
+ // 显示二维码
101
+ _sharedUtils.ColorConsole.info(`devServer`, lanUrl);
102
+ _sharedUtils.CommonUtil.outputQRCodeOnTerminal(lanUrl);
117
103
  }
118
- build(projectPath, options) {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- this.builder.events = {
121
- onBuildSuccess: (data) => {
122
- shared_utils_1.ColorConsole.info(`build time: ${data.costTime}ms`);
123
- this.noticeDeviceListUpdate(projectPath, options);
124
- }
125
- };
126
- yield this.builder.build(projectPath, Object.assign(Object.assign({}, options), { watch: true }));
127
- });
128
- }
129
- dispose() {
130
- var _a;
131
- (_a = this.server) === null || _a === void 0 ? void 0 : _a.close();
132
- }
133
- /**
134
- * 通知已知的设备,应用有更新
135
- * @param projectPath
136
- * @param options
137
- */
138
- noticeDeviceListUpdate(projectPath, options) {
139
- var _a;
140
- const { clientRecordPath } = options;
141
- const json = fs_extra_1.default.readJSONSync(clientRecordPath, { throws: false });
142
- const deviceList = (_a = json === null || json === void 0 ? void 0 : json.records) === null || _a === void 0 ? void 0 : _a[projectPath];
143
- if (deviceList) {
144
- deviceList.forEach((item) => {
145
- const { ip, port } = item;
146
- if (!ip) {
147
- return;
148
- }
149
- const url = `http://${ip}:${port}/update`;
150
- const requestOption = { host: ip, port, path: '/update', timeout: 3000 };
151
- http_1.default
152
- .request(requestOption, () => {
153
- shared_utils_1.ColorConsole.success(`Notify the phone to update the rpk file success`, {
154
- word: url
155
- });
156
- })
157
- .on('error', (error) => {
158
- shared_utils_1.ColorConsole.warn(`Notify the phone to update the rpk file`, { word: 'error: ' }, {
159
- word: error.message
160
- });
161
- })
162
- .on('timeout', () => {
163
- shared_utils_1.ColorConsole.warn(`Notify the phone to update the rpk file`, { word: 'timeout: ' }, {
164
- word: url
165
- });
166
- });
167
- });
104
+ }
105
+ async build(projectPath, options) {
106
+ this.builder.events = {
107
+ onBuildSuccess: data => {
108
+ _sharedUtils.ColorConsole.info(`build time: ${data.costTime}ms`);
109
+ this.noticeDeviceListUpdate(projectPath, options);
110
+ }
111
+ };
112
+ await this.builder.build(projectPath, {
113
+ ...options,
114
+ watch: true
115
+ });
116
+ }
117
+ dispose() {
118
+ this.server?.close();
119
+ }
120
+
121
+ /**
122
+ * 通知已知的设备,应用有更新
123
+ * @param projectPath
124
+ * @param options
125
+ */
126
+ noticeDeviceListUpdate(projectPath, options) {
127
+ const {
128
+ clientRecordPath
129
+ } = options;
130
+ const json = _fsExtra.default.readJSONSync(clientRecordPath, {
131
+ throws: false
132
+ });
133
+ const deviceList = json?.records?.[projectPath];
134
+ if (deviceList) {
135
+ deviceList.forEach(item => {
136
+ const {
137
+ ip,
138
+ port
139
+ } = item;
140
+ if (!ip) {
141
+ return;
168
142
  }
143
+ const url = `http://${ip}:${port}/update`;
144
+ const requestOption = {
145
+ host: ip,
146
+ port,
147
+ path: '/update',
148
+ timeout: 3000
149
+ };
150
+ _http.default.request(requestOption, () => {
151
+ _sharedUtils.ColorConsole.success(`Notify the phone to update the rpk file success`, {
152
+ word: url
153
+ });
154
+ }).on('error', error => {
155
+ _sharedUtils.ColorConsole.warn(`Notify the phone to update the rpk file`, {
156
+ word: 'error: '
157
+ }, {
158
+ word: error.message
159
+ });
160
+ }).on('timeout', () => {
161
+ _sharedUtils.ColorConsole.warn(`Notify the phone to update the rpk file`, {
162
+ word: 'timeout: '
163
+ }, {
164
+ word: url
165
+ });
166
+ });
167
+ });
169
168
  }
169
+ }
170
170
  }
171
- exports.default = AndroidUxStart;
171
+ var _default = exports.default = AndroidUxStart;
@@ -1,43 +1,45 @@
1
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 });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
12
7
  /**
13
8
  * IStarter
14
9
  */
15
10
  class IStarter {
16
- constructor(name, description) {
17
- this.name = name;
18
- this.description = description;
19
- /**
20
- * start 的参数列表
21
- */
22
- this.params = [];
23
- }
24
- get waiter() {
25
- return;
26
- }
27
- /**
28
- * start 的命令
29
- */
30
- getCommond() {
31
- return {
32
- name: this.name,
33
- description: this.description,
34
- paramList: this.params,
35
- waiter: this.waiter,
36
- action: (option) => __awaiter(this, void 0, void 0, function* () {
37
- const projectPath = process.cwd();
38
- return this.start(projectPath, option);
39
- })
40
- };
41
- }
11
+ /**
12
+ * start 的参数列表
13
+ */
14
+ params = [];
15
+ constructor(name, description) {
16
+ this.name = name;
17
+ this.description = description;
18
+ }
19
+ get waiter() {
20
+ return;
21
+ }
22
+
23
+ /**
24
+ * start 的命令
25
+ */
26
+ getCommond() {
27
+ return {
28
+ name: this.name,
29
+ description: this.description,
30
+ paramList: this.params,
31
+ waiter: this.waiter,
32
+ action: async option => {
33
+ const projectPath = process.cwd();
34
+ return this.start(projectPath, option);
35
+ }
36
+ };
37
+ }
38
+
39
+ /**
40
+ * 运行项目
41
+ * @param projectPath 项目路径
42
+ * @param options 命令参数
43
+ */
42
44
  }
43
- exports.default = IStarter;
45
+ exports.default = IStarter;
@@ -1,15 +1,20 @@
1
1
  import { IParam } from '@aiot-toolkit/commander';
2
- import { IStartOptions, GoldfishInstance, MiwearInstance, OldGoldfishInstance } from '@aiot-toolkit/emulator';
2
+ import { IStartOptions, CommonInstance } from '@aiot-toolkit/emulator';
3
3
  import VelaUxBuilder from '../builder/VelaUxBuilder';
4
4
  import IStarter from './IStarter';
5
+ import Event from 'events';
5
6
  /**
6
7
  * VelaUxStarter
7
8
  * ux快应用启动器
8
9
  */
9
10
  declare class VelaUxStarter extends IStarter<IStartOptions> {
10
- private ws;
11
- currentGoldfishInstance: GoldfishInstance | MiwearInstance | OldGoldfishInstance | undefined;
11
+ protected name: string;
12
+ protected description: string;
13
+ emulatorInstance?: CommonInstance;
12
14
  builder: VelaUxBuilder;
15
+ event: Event;
16
+ lastRpk?: string;
17
+ constructor(name: string, description: string);
13
18
  params: IParam[];
14
19
  start(projectPath: string, options: any): Promise<void>;
15
20
  /**