doric-cli

This commit is contained in:
pengfei.zhou 2019-08-13 17:39:07 +08:00
parent f46ac2ae73
commit 99b843b33b
4 changed files with 30 additions and 7 deletions

View File

@ -170,6 +170,11 @@
"resolved": "http://registry.npm.taobao.org/is-number/download/is-number-7.0.0.tgz",
"integrity": "sha1-dTU0W4lnNNX4DE0GxQlVUnoU8Ss="
},
"keypress": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/keypress/-/keypress-0.2.1.tgz",
"integrity": "sha1-HoBFQlABjbrUw/6USX1uZ7YmnHc="
},
"minimatch": {
"version": "3.0.4",
"resolved": "http://registry.npm.taobao.org/minimatch/download/minimatch-3.0.4.tgz",

View File

@ -23,6 +23,7 @@
"child_process": "^1.0.2",
"chokidar": "^3.0.2",
"commander": "^2.20.0",
"keypress": "^0.2.1",
"nodejs-websocket": "^1.7.2",
"qrcode-terminal": "^0.12.0",
"rollup": "^1.18.0",

View File

@ -2,17 +2,18 @@ const ws = require('nodejs-websocket')
const createServer = () => {
let server = ws.createServer(connection => {
console.log('connected', connection.key)
connection.on('text', function (result) {
console.log('发送消息', result)
console.log('text', result)
})
connection.on('connect', function (code) {
console.log('开启连接', code)
console.log('connect', code)
})
connection.on('close', function (code) {
console.log('关闭连接', code)
console.log('close', code)
})
connection.on('error', function (code) {
console.log('异常关闭', code)
console.log('error', code)
})
})
return server

View File

@ -12,9 +12,8 @@ setTimeout(() => {
chokidar.watch(process.cwd() + "/bundle", {
ignored: /(^|[\/\\])\../,
}).on('change', (path) => {
console.log('path is ', path)
fs.readFile(path, 'utf-8', (error, data) => {
console.log('send data ', data)
console.log('File change:', path)
ws.connections.forEach(e => {
e.sendText(JSON.stringify({
script: data,
@ -44,8 +43,25 @@ function getIPAdress() {
const qrcode = require('qrcode-terminal');
const ips = getIPAdress()
console.log(`本机IP是${ips}`)
ips.forEach(e => {
console.log(`IP:${e}`)
qrcode.generate(e, { small: true });
})
const keypress = require('keypress');
keypress(process.stdin);
process.stdin.on('keypress', function (ch, key) {
if (key && key.ctrl && key.name == 'r') {
ips.forEach(e => {
console.log(`IP:${e}`)
qrcode.generate(e, { small: true });
})
}
if (key && key.ctrl && key.name == 'c') {
process.stdin.pause();
process.exit(0);
}
});
process.stdin.setRawMode(true);
process.stdin.resume();