-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const path = require('path')
const WebSocket = require('ws')
/**
* 分析js,打包view
*/
function analyse(combineTool, ws, cwd) {
const _cwd = cwd || process.cwd()
return function* combine(next) {
yield next
let body
try {
body = this.body.toString()
} catch (error) { }
if (body == 'Not Found' || !body) {
throw new Error('路径:' + this.path + ' 对应的文件没有找到')
}
try {
body = yield combineTool.processContent(path.join(_cwd, this.path), '', body)
} catch (err) {
//多窗口多客户端同时发送信息
ws.clients.forEach(client => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify({
message: err.message,
type: 'error'
}));
}
})
}
this.body = body.content;
}
}
module.exports = analyse