@dcloudio/uni-vue-devtools 3.0.0-3061320221209001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime.es.js +130 -0
- package/dist/uni.compiler.js +84 -0
- package/lib/app/backend.js +10934 -0
- package/lib/app/hook.js +3963 -0
- package/lib/front/app.html +60 -0
- package/lib/front/devtools.js +118049 -0
- package/lib/front/icons/128.png +0 -0
- package/lib/front/icons/favicon.ico +0 -0
- package/lib/front/server.js +111 -0
- package/lib/mp/backend.js +11001 -0
- package/lib/mp/hook.js +3962 -0
- package/lib/web/backend.js +10958 -0
- package/lib/web/hook.js +3958 -0
- package/package.json +31 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-globals */
|
|
2
|
+
const _detectPort = require('detect-port');
|
|
3
|
+
const os = require('os')
|
|
4
|
+
const { createServer } = require('http')
|
|
5
|
+
const { Server } = require('socket.io')
|
|
6
|
+
const express = require('express')
|
|
7
|
+
const app = express()
|
|
8
|
+
const path = require('path')
|
|
9
|
+
const fs = require('fs')
|
|
10
|
+
const colors = require('picocolors')
|
|
11
|
+
const open = require('open')
|
|
12
|
+
|
|
13
|
+
exports.initDevtoolsServer = async () => {
|
|
14
|
+
const network = getNetwork()
|
|
15
|
+
const socketHost = process.env.__VUE_DEVTOOLS_HOST__ || network
|
|
16
|
+
const socketPort = await detectPort(process.env.__VUE_DEVTOOLS_PORT__ || 8098)
|
|
17
|
+
initSocketServer(socketHost, socketPort)
|
|
18
|
+
|
|
19
|
+
const devtoolsPort = await detectPort(9098)
|
|
20
|
+
initFrontServer(socketHost, socketPort, network, devtoolsPort)
|
|
21
|
+
|
|
22
|
+
return { socketHost, socketPort }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getNetwork() {
|
|
26
|
+
const networks = Object.values(os.networkInterfaces())
|
|
27
|
+
.flatMap((nInterface) => nInterface ?? [])
|
|
28
|
+
.filter(
|
|
29
|
+
(detail) =>
|
|
30
|
+
detail &&
|
|
31
|
+
detail.address &&
|
|
32
|
+
// Node < v18
|
|
33
|
+
((typeof detail.family === 'string' && detail.family === 'IPv4') ||
|
|
34
|
+
// Node >= v18
|
|
35
|
+
(typeof detail.family === 'number' && detail.family === 4))
|
|
36
|
+
)
|
|
37
|
+
for (let network of networks) {
|
|
38
|
+
if (!network.address.includes('127.0.0.1')) {
|
|
39
|
+
return network.address
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function detectPort(port) {
|
|
45
|
+
return _detectPort(port)
|
|
46
|
+
.then(_port => {
|
|
47
|
+
return port == _port ? port : detectPort(_port)
|
|
48
|
+
})
|
|
49
|
+
.catch(err => {
|
|
50
|
+
console.log(colors.red(err))
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function initFrontServer(socketHost, socketPort, network, devtoolsPort) {
|
|
55
|
+
app.use(express.static(__dirname))
|
|
56
|
+
|
|
57
|
+
app.get('/', (_, res) => {
|
|
58
|
+
res.send(fs.readFileSync(path.resolve(__dirname, `./app.html`)).toString())
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
app.get('/env', (_, res) => {
|
|
62
|
+
res.send(
|
|
63
|
+
`window.process = {
|
|
64
|
+
env: {
|
|
65
|
+
HOST: '${socketHost}',
|
|
66
|
+
PORT: '${socketPort}',
|
|
67
|
+
}
|
|
68
|
+
} `
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
app.listen(devtoolsPort, 'localhost', () => {
|
|
73
|
+
const colorUrl = (url) => colors.cyan(url.replace(/:(\d+)\//, (_, port) => `:${colors.bold(port)}/`))
|
|
74
|
+
const networkUrl = `http://${network}:${devtoolsPort}`
|
|
75
|
+
|
|
76
|
+
console.log(`\n${colors.cyan('uni-vue-devtools')} ${colors.green('server running at:')}\n ${colors.green('➜')} ${colorUrl(networkUrl)}\n`)
|
|
77
|
+
|
|
78
|
+
open(`http:localhost:${devtoolsPort}`)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function initSocketServer(host, port) {
|
|
84
|
+
const httpServer = createServer(app)
|
|
85
|
+
const io = new Server(httpServer, {
|
|
86
|
+
cors: {
|
|
87
|
+
origin: true,
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
// Middleman
|
|
91
|
+
io.on('connection', function (socket) {
|
|
92
|
+
// Disconnect any previously connected apps
|
|
93
|
+
socket.broadcast.emit('vue-devtools-disconnect-backend')
|
|
94
|
+
|
|
95
|
+
socket.on('vue-devtools-init', () => {
|
|
96
|
+
socket.broadcast.emit('vue-devtools-init')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
socket.on('disconnect', (reason) => {
|
|
100
|
+
if (reason.indexOf('client')) {
|
|
101
|
+
socket.broadcast.emit('vue-devtools-disconnect-devtools')
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
socket.on('vue-message', data => {
|
|
106
|
+
socket.broadcast.emit('vue-message', data)
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
httpServer.listen(port, host)
|
|
111
|
+
}
|