debug by pass reload

This commit is contained in:
王劲鹏 2019-12-11 15:14:29 +08:00
parent 7981ff0851
commit 063bfa79c2
2 changed files with 10 additions and 3 deletions

View File

@ -2,18 +2,18 @@ const ws = require('nodejs-websocket')
const { exec, spawn } = require('child_process') const { exec, spawn } = require('child_process')
const fs = require('fs') const fs = require('fs')
var server
var contextId = null var contextId = null
var clientConnection = null var clientConnection = null
var debuggerConnection = null var debuggerConnection = null
const createServer = () => { const createServer = () => {
let server = ws.createServer(connection => { server = ws.createServer(connection => {
console.log('connected', connection.headers.host) console.log('connected', connection.headers.host)
if (connection.headers.host.startsWith("localhost")) { if (connection.headers.host.startsWith("localhost")) {
console.log("debugger " + connection.key + " attached to dev kit") console.log("debugger " + connection.key + " attached to dev kit")
debuggerConnection = connection debuggerConnection = connection
clientConnection.sendText(JSON.stringify({ clientConnection.sendText(JSON.stringify({
cmd: 'SWITCH_TO_DEBUG', cmd: 'SWITCH_TO_DEBUG',
contextId: contextId contextId: contextId
@ -30,7 +30,8 @@ const createServer = () => {
switch(resultObject.cmd) { switch(resultObject.cmd) {
case 'DEBUG': case 'DEBUG':
clientConnection = connection clientConnection = connection
server.debugging = true
console.log("enter debugging")
contextId = resultObject.data.contextId contextId = resultObject.data.contextId
let projectHome = '.' let projectHome = '.'
@ -56,6 +57,8 @@ const createServer = () => {
}) })
connection.on('close', function (code) { connection.on('close', function (code) {
console.log('close: code = ' + code, connection.key) console.log('close: code = ' + code, connection.key)
console.log("quit debugging")
server.debugging = false
}) })
connection.on('error', function (code) { connection.on('error', function (code) {
console.log('error', code) console.log('error', code)

View File

@ -13,6 +13,10 @@ setTimeout(() => {
chokidar.watch(process.cwd() + "/bundle", { chokidar.watch(process.cwd() + "/bundle", {
ignored: /(^|[\/\\])\../, ignored: /(^|[\/\\])\../,
}).on('change', (path) => { }).on('change', (path) => {
if (ws.debugging) {
console.log("debugging, hot reload by pass")
return
}
fs.readFile(path, 'utf-8', (error, data) => { fs.readFile(path, 'utf-8', (error, data) => {
if (!path.endsWith('.map')) { if (!path.endsWith('.map')) {
console.log('File change:', path) console.log('File change:', path)