scripting-cli 1.0.3 → 1.0.5
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/build.js +67 -1
- package/dist/config/AppJsonPlugin.js +57 -26
- package/dist/config/webpack.config.js +85 -69
- package/dist/createApp.js +67 -27
- package/dist/index.js +0 -1
- package/dist/startDevServer.js +34 -18
- package/package.json +7 -3
- package/public/assets.d.ts +40 -0
- package/public/logo.svg +4 -0
- package/public/scripting.d.ts +598 -805
- package/src/build.ts +80 -1
- package/src/config/AppJsonPlugin.ts +80 -39
- package/src/config/webpack.config.ts +97 -69
- package/src/createApp.ts +97 -30
- package/src/index.ts +0 -1
- package/src/startDevServer.ts +28 -12
package/src/startDevServer.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import http from 'node:http'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
+
import { readFile, } from 'node:fs/promises'
|
|
3
4
|
import chalk from 'chalk'
|
|
4
5
|
import express from 'express'
|
|
5
6
|
import minimist from 'minimist'
|
|
7
|
+
import qrcode from 'qrcode-terminal'
|
|
6
8
|
|
|
7
9
|
import { Server, Socket } from 'socket.io'
|
|
8
10
|
|
|
9
11
|
import * as utils from './utils'
|
|
10
12
|
|
|
11
13
|
import Webpack from "webpack"
|
|
12
|
-
import
|
|
14
|
+
import getConfig from './config/webpack.config'
|
|
13
15
|
|
|
14
16
|
export function startDevServer() {
|
|
15
17
|
const args = minimist(process.argv.slice(2))
|
|
@@ -21,9 +23,12 @@ export function startDevServer() {
|
|
|
21
23
|
const server = http.createServer(app)
|
|
22
24
|
const io = new Server(server)
|
|
23
25
|
|
|
26
|
+
|
|
24
27
|
let isStarted = false
|
|
25
28
|
let connectedSockets: Socket[] = []
|
|
26
29
|
|
|
30
|
+
const webpackConfig = getConfig()
|
|
31
|
+
|
|
27
32
|
webpackConfig.mode = 'development'
|
|
28
33
|
|
|
29
34
|
const compiler = Webpack(webpackConfig)
|
|
@@ -40,7 +45,7 @@ export function startDevServer() {
|
|
|
40
45
|
utils.clearConsole()
|
|
41
46
|
if (err) {
|
|
42
47
|
console.log(
|
|
43
|
-
chalk.red('
|
|
48
|
+
chalk.red(' ✖️ webpack compile error: \n') + err
|
|
44
49
|
)
|
|
45
50
|
} else {
|
|
46
51
|
console.log(stats?.toString({
|
|
@@ -55,15 +60,25 @@ export function startDevServer() {
|
|
|
55
60
|
}
|
|
56
61
|
)
|
|
57
62
|
|
|
58
|
-
function onCompileDone() {
|
|
63
|
+
async function onCompileDone() {
|
|
59
64
|
if (isStarted) {
|
|
60
65
|
printDevServerAddress()
|
|
66
|
+
|
|
61
67
|
console.log(
|
|
62
|
-
chalk.gray(`
|
|
68
|
+
chalk.gray(` ~ Sent update event to ${connectedSockets.length} client(s)`)
|
|
63
69
|
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
|
|
71
|
+
const appJson = await readFile(
|
|
72
|
+
path.resolve(
|
|
73
|
+
process.cwd(),
|
|
74
|
+
'build/app.json'
|
|
75
|
+
),
|
|
76
|
+
'utf-8'
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
for (const socket of connectedSockets) {
|
|
80
|
+
socket.emit('update', appJson)
|
|
81
|
+
}
|
|
67
82
|
} else {
|
|
68
83
|
start()
|
|
69
84
|
}
|
|
@@ -75,6 +90,8 @@ export function startDevServer() {
|
|
|
75
90
|
`http://${ipAddress}:${port}`
|
|
76
91
|
),
|
|
77
92
|
)}`)
|
|
93
|
+
console.log(`Use the Scripting app to scan the QR code below:`)
|
|
94
|
+
qrcode.generate(`http://${ipAddress}:${port}`, { small: true })
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
function start() {
|
|
@@ -85,7 +102,6 @@ export function startDevServer() {
|
|
|
85
102
|
app.all('*', function (req, res, next) {
|
|
86
103
|
res.header('Access-Control-Allow-Origin', '*')
|
|
87
104
|
res.header('Access-Control-Allow-Headers', '*')
|
|
88
|
-
// res.header('Content-Type', 'application/jsoncharset=utf-8')
|
|
89
105
|
res.header('Access-Control-Allow-Methods', 'GET, POST, PATCH, OPTIONS, PUT, DELETE')
|
|
90
106
|
next()
|
|
91
107
|
})
|
|
@@ -93,7 +109,7 @@ export function startDevServer() {
|
|
|
93
109
|
app.use(
|
|
94
110
|
'/',
|
|
95
111
|
express.static(
|
|
96
|
-
path.resolve(process.cwd(), '
|
|
112
|
+
path.resolve(process.cwd(), 'build')
|
|
97
113
|
)
|
|
98
114
|
)
|
|
99
115
|
|
|
@@ -101,7 +117,7 @@ export function startDevServer() {
|
|
|
101
117
|
io.on('connection', function (socket) {
|
|
102
118
|
console.log(
|
|
103
119
|
chalk.green(
|
|
104
|
-
|
|
120
|
+
` + A client(${socket.id}) connected.`
|
|
105
121
|
)
|
|
106
122
|
)
|
|
107
123
|
connectedSockets.push(socket)
|
|
@@ -109,7 +125,7 @@ export function startDevServer() {
|
|
|
109
125
|
socket.on('error', function (err) {
|
|
110
126
|
console.log(
|
|
111
127
|
chalk.red(
|
|
112
|
-
'
|
|
128
|
+
' ✖️ Server Error: ', err
|
|
113
129
|
)
|
|
114
130
|
)
|
|
115
131
|
})
|
|
@@ -120,7 +136,7 @@ export function startDevServer() {
|
|
|
120
136
|
connectedSockets.splice(index, 1)
|
|
121
137
|
console.log(
|
|
122
138
|
chalk.gray(
|
|
123
|
-
|
|
139
|
+
` - A client(${socket.id}) disconnected.`
|
|
124
140
|
)
|
|
125
141
|
)
|
|
126
142
|
}
|