2019-08-03 10:19:56 +08:00
|
|
|
const chokidar = require('chokidar')
|
|
|
|
const ws = require('./server')
|
|
|
|
const fs = require("fs")
|
|
|
|
|
2019-08-03 02:03:56 +08:00
|
|
|
require('shelljs/global')
|
|
|
|
|
2019-08-13 17:22:56 +08:00
|
|
|
exec('npm run dev >/dev/null 2>&1', { async: true })
|
|
|
|
console.warn('Waiting ...')
|
|
|
|
setTimeout(() => {
|
|
|
|
console.warn('Start watching')
|
|
|
|
ws.listen(7777)
|
|
|
|
chokidar.watch(process.cwd() + "/bundle", {
|
|
|
|
ignored: /(^|[\/\\])\../,
|
|
|
|
}).on('change', (path) => {
|
2019-08-03 10:19:56 +08:00
|
|
|
fs.readFile(path, 'utf-8', (error, data) => {
|
2019-08-13 17:39:07 +08:00
|
|
|
console.log('File change:', path)
|
2019-08-03 10:19:56 +08:00
|
|
|
ws.connections.forEach(e => {
|
2019-08-13 17:22:56 +08:00
|
|
|
e.sendText(JSON.stringify({
|
|
|
|
script: data,
|
|
|
|
source: path.match(/[^/\\]*$/)[0],
|
|
|
|
}))
|
2019-08-03 10:19:56 +08:00
|
|
|
})
|
|
|
|
})
|
2019-08-13 17:22:56 +08:00
|
|
|
});
|
|
|
|
}, 3000);
|
|
|
|
const os = require('os');
|
|
|
|
|
|
|
|
function getIPAdress() {
|
|
|
|
const ret = []
|
|
|
|
var interfaces = os.networkInterfaces();
|
|
|
|
for (var devName in interfaces) {
|
|
|
|
var iface = interfaces[devName];
|
|
|
|
for (var i = 0; i < iface.length; i++) {
|
|
|
|
var alias = iface[i];
|
|
|
|
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
|
|
|
|
ret.push(alias.address);
|
|
|
|
}
|
|
|
|
}
|
2019-08-03 10:19:56 +08:00
|
|
|
}
|
2019-08-13 17:22:56 +08:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const qrcode = require('qrcode-terminal');
|
|
|
|
const ips = getIPAdress()
|
|
|
|
ips.forEach(e => {
|
|
|
|
console.log(`IP:${e}`)
|
|
|
|
qrcode.generate(e, { small: true });
|
|
|
|
})
|
2019-08-13 17:39:07 +08:00
|
|
|
|
|
|
|
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();
|