doric-cli
This commit is contained in:
parent
f46ac2ae73
commit
99b843b33b
5
doric-cli/package-lock.json
generated
5
doric-cli/package-lock.json
generated
@ -170,6 +170,11 @@
|
|||||||
"resolved": "http://registry.npm.taobao.org/is-number/download/is-number-7.0.0.tgz",
|
"resolved": "http://registry.npm.taobao.org/is-number/download/is-number-7.0.0.tgz",
|
||||||
"integrity": "sha1-dTU0W4lnNNX4DE0GxQlVUnoU8Ss="
|
"integrity": "sha1-dTU0W4lnNNX4DE0GxQlVUnoU8Ss="
|
||||||
},
|
},
|
||||||
|
"keypress": {
|
||||||
|
"version": "0.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/keypress/-/keypress-0.2.1.tgz",
|
||||||
|
"integrity": "sha1-HoBFQlABjbrUw/6USX1uZ7YmnHc="
|
||||||
|
},
|
||||||
"minimatch": {
|
"minimatch": {
|
||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"resolved": "http://registry.npm.taobao.org/minimatch/download/minimatch-3.0.4.tgz",
|
"resolved": "http://registry.npm.taobao.org/minimatch/download/minimatch-3.0.4.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",
|
||||||
|
"keypress": "^0.2.1",
|
||||||
"nodejs-websocket": "^1.7.2",
|
"nodejs-websocket": "^1.7.2",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"rollup": "^1.18.0",
|
"rollup": "^1.18.0",
|
||||||
|
@ -2,17 +2,18 @@ const ws = require('nodejs-websocket')
|
|||||||
|
|
||||||
const createServer = () => {
|
const createServer = () => {
|
||||||
let server = ws.createServer(connection => {
|
let server = ws.createServer(connection => {
|
||||||
|
console.log('connected', connection.key)
|
||||||
connection.on('text', function (result) {
|
connection.on('text', function (result) {
|
||||||
console.log('发送消息', result)
|
console.log('text', result)
|
||||||
})
|
})
|
||||||
connection.on('connect', function (code) {
|
connection.on('connect', function (code) {
|
||||||
console.log('开启连接', code)
|
console.log('connect', code)
|
||||||
})
|
})
|
||||||
connection.on('close', function (code) {
|
connection.on('close', function (code) {
|
||||||
console.log('关闭连接', code)
|
console.log('close', code)
|
||||||
})
|
})
|
||||||
connection.on('error', function (code) {
|
connection.on('error', function (code) {
|
||||||
console.log('异常关闭', code)
|
console.log('error', code)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return server
|
return server
|
||||||
|
@ -12,9 +12,8 @@ setTimeout(() => {
|
|||||||
chokidar.watch(process.cwd() + "/bundle", {
|
chokidar.watch(process.cwd() + "/bundle", {
|
||||||
ignored: /(^|[\/\\])\../,
|
ignored: /(^|[\/\\])\../,
|
||||||
}).on('change', (path) => {
|
}).on('change', (path) => {
|
||||||
console.log('path is ', path)
|
|
||||||
fs.readFile(path, 'utf-8', (error, data) => {
|
fs.readFile(path, 'utf-8', (error, data) => {
|
||||||
console.log('send data ', data)
|
console.log('File change:', path)
|
||||||
ws.connections.forEach(e => {
|
ws.connections.forEach(e => {
|
||||||
e.sendText(JSON.stringify({
|
e.sendText(JSON.stringify({
|
||||||
script: data,
|
script: data,
|
||||||
@ -44,8 +43,25 @@ function getIPAdress() {
|
|||||||
|
|
||||||
const qrcode = require('qrcode-terminal');
|
const qrcode = require('qrcode-terminal');
|
||||||
const ips = getIPAdress()
|
const ips = getIPAdress()
|
||||||
console.log(`本机IP是${ips}`)
|
|
||||||
ips.forEach(e => {
|
ips.forEach(e => {
|
||||||
console.log(`IP:${e}`)
|
console.log(`IP:${e}`)
|
||||||
qrcode.generate(e, { small: true });
|
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();
|
Reference in New Issue
Block a user