add watcher and server to send change
This commit is contained in:
parent
99b900f2b6
commit
e367093a6a
5
doric-cli/package-lock.json
generated
5
doric-cli/package-lock.json
generated
@ -178,6 +178,11 @@
|
|||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nodejs-websocket": {
|
||||||
|
"version": "1.7.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/nodejs-websocket/-/nodejs-websocket-1.7.2.tgz",
|
||||||
|
"integrity": "sha512-PFX6ypJcCNDs7obRellR0DGTebfUhw1SXGKe2zpB+Ng1DQJhdzbzx1ob+AvJCLzy2TJF4r8cCDqMQqei1CZdPQ=="
|
||||||
|
},
|
||||||
"normalize-path": {
|
"normalize-path": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "http://registry.npm.taobao.org/normalize-path/download/normalize-path-3.0.0.tgz",
|
"resolved": "http://registry.npm.taobao.org/normalize-path/download/normalize-path-3.0.0.tgz",
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
"child_process": "^1.0.2",
|
"child_process": "^1.0.2",
|
||||||
"chokidar": "^3.0.2",
|
"chokidar": "^3.0.2",
|
||||||
"commander": "^2.20.0",
|
"commander": "^2.20.0",
|
||||||
|
"nodejs-websocket": "^1.7.2",
|
||||||
"rollup": "^1.18.0",
|
"rollup": "^1.18.0",
|
||||||
"shelljs": "^0.8.3",
|
"shelljs": "^0.8.3",
|
||||||
"typescript": "^3.5.3"
|
"typescript": "^3.5.3"
|
||||||
|
21
doric-cli/scripts/server.js
Normal file
21
doric-cli/scripts/server.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
const ws = require('nodejs-websocket')
|
||||||
|
|
||||||
|
const createServer = () => {
|
||||||
|
let server = ws.createServer(connection => {
|
||||||
|
connection.on('text', function (result) {
|
||||||
|
console.log('发送消息', result)
|
||||||
|
})
|
||||||
|
connection.on('connect', function (code) {
|
||||||
|
console.log('开启连接', code)
|
||||||
|
})
|
||||||
|
connection.on('close', function (code) {
|
||||||
|
console.log('关闭连接', code)
|
||||||
|
})
|
||||||
|
connection.on('error', function (code) {
|
||||||
|
console.log('异常关闭', code)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = createServer()
|
@ -1,10 +1,22 @@
|
|||||||
var chokidar = require('chokidar')
|
const chokidar = require('chokidar')
|
||||||
|
const ws = require('./server')
|
||||||
|
const fs = require("fs")
|
||||||
|
|
||||||
require('shelljs/global')
|
require('shelljs/global')
|
||||||
|
|
||||||
exec('npm run dev', () => {
|
exec('npm run dev', () => {
|
||||||
})
|
})
|
||||||
chokidar.watch(process.cwd() + "/build", {
|
ws.listen(7777)
|
||||||
|
chokidar.watch(process.cwd() + "/bundle", {
|
||||||
ignored: /(^|[\/\\])\../,
|
ignored: /(^|[\/\\])\../,
|
||||||
}).on('all', (event, path) => {
|
}).on('all', (event, path) => {
|
||||||
console.log(event, path)
|
console.log('path is ', path)
|
||||||
|
if (event === 'add' || event === 'change') {
|
||||||
|
fs.readFile(path, 'utf-8', (error, data) => {
|
||||||
|
console.log('send data ', data)
|
||||||
|
ws.connections.forEach(e => {
|
||||||
|
e.sendText(data)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user