1 | ;
|
2 |
|
3 | /**
|
4 | * Copyright (C) 2017, hapjs.org. All rights reserved.
|
5 | */
|
6 | const {
|
7 | launchServer,
|
8 | stopServer
|
9 | } = require('@hap-toolkit/server');
|
10 |
|
11 | const {
|
12 | compile,
|
13 | stopWatch
|
14 | } = require('./commands/compile');
|
15 | /**
|
16 | * 关闭开发服务及停止webpack watching
|
17 | *
|
18 | * @module stopAll
|
19 | * @returns {Promise} - 返回成功与否的信息
|
20 | */
|
21 |
|
22 |
|
23 | function stopAll() {
|
24 | return Promise.all([stopServer(), stopWatch()]).then(([stopServerData, stopWatchData]) => {
|
25 | const data = Object.assign({}, stopServerData, stopWatchData); // 得出布尔值
|
26 |
|
27 | data.error = !!(stopServerData.stopServerError || stopWatchData.stopWatchError);
|
28 | return data;
|
29 | });
|
30 | }
|
31 | /**
|
32 | * 启动开发服务及开启webpack watching
|
33 | *
|
34 | * @module launchWithWatch
|
35 | * @param {Object} options - 参数配置项
|
36 | * @param {String|Number} [options.port] - 服务端口
|
37 | * @param {Array<debugger|packager>} [options.modules] - 加载其他模块
|
38 | * @param {String} [options.chromePath] - 指定 chrome 的启动路径
|
39 | * @param {String} [options.disableADB] - 是否禁止启用adb
|
40 | * @param {String} [options.cwd] - 要运行的项目路径
|
41 | * @param {String} [options.openDebugger] - 是否打开调试窗口
|
42 | * @param {Writable} [options.log] - 日志输出流
|
43 | * @param {Function} [options.onerror] - compile 的错误回调函数
|
44 | * @param {requestCallback} [options.callback] - 回调函数,用以传递回一些数据给调用方
|
45 | * @returns {Promise} - 返回成功与否的信息
|
46 | */
|
47 |
|
48 | /**
|
49 | * launchWithWatch 传进来的回调函数
|
50 | * @callback requestCallback
|
51 | * @param {string} action - toolkit进行到的操作
|
52 | * @param {string} url - 调试页面的地址
|
53 | */
|
54 |
|
55 |
|
56 | function launchWithWatch(options) {
|
57 | const {
|
58 | cwd,
|
59 | log,
|
60 | onerror
|
61 | } = options;
|
62 | return Promise.all([launchServer(options), compile('native', 'dev', true, {
|
63 | cwd,
|
64 | log,
|
65 | onerror
|
66 | })]).then(([launchData, compileData]) => {
|
67 | const data = Object.assign({}, launchData, compileData); // 得出布尔值
|
68 |
|
69 | data.error = !!(launchData.launchError || compileData.compileError);
|
70 | return data;
|
71 | });
|
72 | }
|
73 |
|
74 | module.exports = {
|
75 | compile,
|
76 | stopWatch,
|
77 | launchServer,
|
78 | stopServer,
|
79 | launchWithWatch,
|
80 | stopAll
|
81 | };
|
82 | //# sourceMappingURL=index.js.map
|