@quicktvui/web-cli 1.0.0-beta.13 → 1.0.0-beta.15
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/bin/{qt-web-dev.js → qt-web-cli.js} +90 -7
- package/lib/entry-package.js +12 -10
- package/package.json +16 -8
|
@@ -23,17 +23,17 @@ const args = minimist(process.argv.slice(2), {
|
|
|
23
23
|
},
|
|
24
24
|
default: {
|
|
25
25
|
port: 39001,
|
|
26
|
-
open:
|
|
26
|
+
open: true,
|
|
27
27
|
},
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
// 显示帮助信息
|
|
31
31
|
if (args.help) {
|
|
32
32
|
console.log(`
|
|
33
|
-
QuickTVUI Web
|
|
33
|
+
QuickTVUI Web CLI
|
|
34
34
|
|
|
35
35
|
Usage:
|
|
36
|
-
qt-web-
|
|
36
|
+
qt-web-cli [options]
|
|
37
37
|
|
|
38
38
|
Options:
|
|
39
39
|
-p, --port <port> 开发服务器端口 (默认: 39001)
|
|
@@ -42,9 +42,9 @@ Options:
|
|
|
42
42
|
-h, --help 显示帮助信息
|
|
43
43
|
|
|
44
44
|
Examples:
|
|
45
|
-
qt-web-
|
|
46
|
-
qt-web-
|
|
47
|
-
qt-web-
|
|
45
|
+
qt-web-cli
|
|
46
|
+
qt-web-cli --port 8080
|
|
47
|
+
qt-web-cli --config ./my.webpack.js
|
|
48
48
|
|
|
49
49
|
特点:
|
|
50
50
|
- 自动检测项目入口,优先使用 webMain
|
|
@@ -122,13 +122,22 @@ async function main() {
|
|
|
122
122
|
|
|
123
123
|
// 构建 webpack 命令
|
|
124
124
|
const webpackArgs = ['serve', `--config "${webpackConfigPath}"`, `--port ${args.port}`, '--color']
|
|
125
|
-
if (args.open) webpackArgs.push('--open')
|
|
126
125
|
|
|
127
126
|
const envPrefix = nodeOptions ? `NODE_OPTIONS="${nodeOptions}" ` : ''
|
|
128
127
|
const webpackCmd = `${envPrefix}npx webpack ${webpackArgs.join(' ')}`
|
|
129
128
|
|
|
130
129
|
signale.pending(`执行: ${webpackCmd}`)
|
|
131
130
|
|
|
131
|
+
// 如果需要打开浏览器,等待服务器就绪后打开
|
|
132
|
+
if (args.open) {
|
|
133
|
+
const url = `http://localhost:${args.port}`
|
|
134
|
+
waitForServer(url, 30000).then(() => {
|
|
135
|
+
openOrRefreshBrowser(url)
|
|
136
|
+
}).catch((err) => {
|
|
137
|
+
signale.warn(`自动打开浏览器失败: ${err.message}`)
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
|
|
132
141
|
const result = exec(webpackCmd, { stdio: 'inherit' })
|
|
133
142
|
if (result.code !== 0) {
|
|
134
143
|
signale.error('启动开发服务器失败')
|
|
@@ -136,6 +145,80 @@ async function main() {
|
|
|
136
145
|
}
|
|
137
146
|
}
|
|
138
147
|
|
|
148
|
+
/**
|
|
149
|
+
* 等待服务器就绪
|
|
150
|
+
*/
|
|
151
|
+
function waitForServer(url, timeout = 30000) {
|
|
152
|
+
const http = require('http')
|
|
153
|
+
const startTime = Date.now()
|
|
154
|
+
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
function check() {
|
|
157
|
+
if (Date.now() - startTime > timeout) {
|
|
158
|
+
reject(new Error('等待服务器超时'))
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const req = http.get(url, (res) => {
|
|
163
|
+
if (res.statusCode === 200 || res.statusCode === 304) {
|
|
164
|
+
resolve()
|
|
165
|
+
} else {
|
|
166
|
+
setTimeout(check, 500)
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
req.on('error', () => {
|
|
171
|
+
setTimeout(check, 500)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
req.setTimeout(1000, () => {
|
|
175
|
+
req.destroy()
|
|
176
|
+
setTimeout(check, 500)
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
check()
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 打开或刷新浏览器(支持 macOS)
|
|
186
|
+
*/
|
|
187
|
+
function openOrRefreshBrowser(url) {
|
|
188
|
+
const platform = process.platform
|
|
189
|
+
|
|
190
|
+
if (platform === 'darwin') {
|
|
191
|
+
// macOS: 使用 AppleScript 检查并刷新已存在的标签页
|
|
192
|
+
const appleScript = `
|
|
193
|
+
tell application "Safari"
|
|
194
|
+
activate
|
|
195
|
+
set found to false
|
|
196
|
+
repeat with w in windows
|
|
197
|
+
repeat with t in tabs of w
|
|
198
|
+
if URL of t starts with "http://localhost:" then
|
|
199
|
+
set URL of t to "${url}"
|
|
200
|
+
set found to true
|
|
201
|
+
exit repeat
|
|
202
|
+
end if
|
|
203
|
+
end repeat
|
|
204
|
+
if found then exit repeat
|
|
205
|
+
end repeat
|
|
206
|
+
if not found then
|
|
207
|
+
open location "${url}"
|
|
208
|
+
end if
|
|
209
|
+
end tell
|
|
210
|
+
`
|
|
211
|
+
|
|
212
|
+
exec(`osascript -e '${appleScript.replace(/\n/g, ' ')}'`, { silent: true })
|
|
213
|
+
signale.success('已打开/刷新浏览器')
|
|
214
|
+
} else {
|
|
215
|
+
// 其他平台:直接打开 URL
|
|
216
|
+
const openCmd = platform === 'win32' ? 'start' : 'xdg-open'
|
|
217
|
+
exec(`${openCmd} "${url}"`, { silent: true })
|
|
218
|
+
signale.success('已打开浏览器')
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
139
222
|
function findProjectRoot(startDir = process.cwd()) {
|
|
140
223
|
let currentDir = startDir
|
|
141
224
|
while (currentDir !== path.dirname(currentDir)) {
|
package/lib/entry-package.js
CHANGED
|
@@ -51,13 +51,15 @@ console.log('[Web Renderer] Global CSS reset injected')
|
|
|
51
51
|
|
|
52
52
|
// 动态加载主入口,等待加载完成后再启动引擎
|
|
53
53
|
console.log('[Web Renderer] Importing main module...')
|
|
54
|
-
import(__QUICKTVUI_MAIN_ENTRY__)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
import(__QUICKTVUI_MAIN_ENTRY__)
|
|
55
|
+
.then(() => {
|
|
56
|
+
console.log('[Web Renderer] Main module loaded')
|
|
57
|
+
console.log('[Web Renderer] Starting engine...')
|
|
58
|
+
startWebEngine(engine, APP_NAME)
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
console.log('[Web Renderer] === Initialization complete ===')
|
|
61
|
+
}, 1000)
|
|
62
|
+
})
|
|
63
|
+
.catch((err) => {
|
|
64
|
+
console.error('[Web Renderer] Failed to load main module:', err)
|
|
65
|
+
})
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quicktvui/web-cli",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.15",
|
|
4
4
|
"description": "CLI tool for QuickTVUI web development - zero configuration",
|
|
5
5
|
"author": "QuickTVUI Team",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"bin": {
|
|
8
|
-
"qt-web-
|
|
8
|
+
"qt-web-cli": "./bin/qt-web-cli.js"
|
|
9
9
|
},
|
|
10
10
|
"main": "lib/index.js",
|
|
11
11
|
"files": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"minimist": "^1.2.8",
|
|
25
25
|
"shelljs": "^0.10.0",
|
|
26
26
|
"signale": "^1.4.0",
|
|
27
|
-
"@quicktvui/web-renderer": "^1.0.
|
|
27
|
+
"@quicktvui/web-renderer": "^1.0.6",
|
|
28
28
|
"scope-loader": "^1.0.3"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -41,12 +41,20 @@
|
|
|
41
41
|
"@extscreen/es3-vue": ">=3.0.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependenciesMeta": {
|
|
44
|
-
"less-loader": {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
44
|
+
"less-loader": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"sass-loader": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"sass": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"less": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
48
56
|
},
|
|
49
57
|
"engines": {
|
|
50
58
|
"node": ">=16.0.0"
|
|
51
59
|
}
|
|
52
|
-
}
|
|
60
|
+
}
|