@wwkit/opm 1.0.4 → 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/package.json +2 -2
- package/src/cli/groups/ping.js +2 -0
- package/src/managers/npm.js +28 -0
- package/src/tools/share/index.js +35 -35
- package/src/tools/share/server.js +3 -3
- package/src/tools/share/server.php +1 -1
- package/src/tools/webwork/index.js +165 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwkit/opm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"author": "bluesliu <langcai163@163.com>",
|
|
5
5
|
"description": "Unified CLI — package management (npm/pip/dnf/apt) + config view + opencode maintenance",
|
|
6
6
|
"type": "module",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"basic-ftp": "^6.2.1",
|
|
36
36
|
"extract-zip": "^2.0.1",
|
|
37
37
|
"systeminformation": "^5.23.0",
|
|
38
|
-
"@wwkit/shared": "1.0.
|
|
38
|
+
"@wwkit/shared": "1.0.8"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"registry": "https://registry.npmjs.org/",
|
package/src/cli/groups/ping.js
CHANGED
|
@@ -250,6 +250,8 @@ async function checkReachability(address, tool, count, proxy) {
|
|
|
250
250
|
return { reachable: false, sent: 0, received: 0, loss: 0, lossPercent: 0, rttMin: '', rttAvg: '', rttMax: '', raw: 'No tool available' }
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
+
export { checkReachability, extractHostPort }
|
|
254
|
+
|
|
253
255
|
export class PingGroup {
|
|
254
256
|
constructor() {
|
|
255
257
|
this.name = 'ping'
|
package/src/managers/npm.js
CHANGED
|
@@ -437,12 +437,39 @@ export class NpmManager extends PackageManager {
|
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
+
/**
|
|
441
|
+
* 查询 npm 主版本号(缓存),用于判断是否支持 --allow-scripts(npm >= 11)
|
|
442
|
+
* @returns {number}
|
|
443
|
+
* @private
|
|
444
|
+
*/
|
|
445
|
+
_npmMajor() {
|
|
446
|
+
if (this._npmMajorCache !== undefined) return this._npmMajorCache
|
|
447
|
+
try {
|
|
448
|
+
const v = this._exec(['--version'], { allowNonZero: true }).trim()
|
|
449
|
+
this._npmMajorCache = parseInt(v.split('.')[0], 10) || 0
|
|
450
|
+
} catch {
|
|
451
|
+
this._npmMajorCache = 0
|
|
452
|
+
}
|
|
453
|
+
return this._npmMajorCache
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* 构造 --allow-scripts 参数(仅 npm >= 11 支持)
|
|
458
|
+
* @param {string} name - 包名
|
|
459
|
+
* @returns {string[]}
|
|
460
|
+
* @private
|
|
461
|
+
*/
|
|
462
|
+
_allowScriptsArgs(name) {
|
|
463
|
+
return this._npmMajor() >= 11 ? [`--allow-scripts=${name}`] : []
|
|
464
|
+
}
|
|
465
|
+
|
|
440
466
|
async install(name, version, opts = {}) {
|
|
441
467
|
const spec = version ? `${name}@${version}` : name
|
|
442
468
|
const args = ['install', spec]
|
|
443
469
|
if (opts.global) args.push('-g')
|
|
444
470
|
args.push(...this._proxyArgs(opts.proxy))
|
|
445
471
|
args.push(...this._registryArgs())
|
|
472
|
+
if (opts.allowScripts) args.push(...this._allowScriptsArgs(name))
|
|
446
473
|
|
|
447
474
|
this._execInherit(args)
|
|
448
475
|
return { name, version: version || 'latest', action: 'installed' }
|
|
@@ -461,6 +488,7 @@ export class NpmManager extends PackageManager {
|
|
|
461
488
|
if (opts.global) args.push('-g')
|
|
462
489
|
args.push(...this._proxyArgs(opts.proxy))
|
|
463
490
|
args.push(...this._registryArgs())
|
|
491
|
+
if (opts.allowScripts) args.push(...this._allowScriptsArgs(name))
|
|
464
492
|
|
|
465
493
|
this._execInherit(args)
|
|
466
494
|
return { name, version: 'latest', action: 'upgraded' }
|
package/src/tools/share/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* opm share 命令组 — 文本分享服务
|
|
3
3
|
*
|
|
4
|
-
* 命令:upload / zip / get / view / open / list / delete / clear / config /
|
|
4
|
+
* 命令:upload / zip / get / view / open / list / delete / clear / config / server / help
|
|
5
5
|
* 服务地址由 config.share.server.active 解析(不支持命令行 -s 参数)。
|
|
6
6
|
* 需要服务调用的命令执行前先 ping 验证可达性;
|
|
7
7
|
* 若 active=local 且服务未启动,自动后台启动后再执行。
|
|
8
|
-
*
|
|
8
|
+
* server 子命令:start(后台启动)/ stop(停止)/ status(查询状态)。
|
|
9
9
|
* zip 上传文件/文件夹(压缩为 zip 后 base64 上传),get -d 下载并解压。
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -65,7 +65,7 @@ function openBrowser(url) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* 获取
|
|
68
|
+
* 获取 server 状态文件路径
|
|
69
69
|
* @returns {string}
|
|
70
70
|
*/
|
|
71
71
|
function getServePidFile() {
|
|
@@ -73,7 +73,7 @@ function getServePidFile() {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* 读取
|
|
76
|
+
* 读取 server PID 文件
|
|
77
77
|
* @returns {{pid: number, url: string, host: string, port: number, dataDir: string, started: string}|null}
|
|
78
78
|
*/
|
|
79
79
|
function readServePid() {
|
|
@@ -111,14 +111,14 @@ const ACTIONS = {
|
|
|
111
111
|
delete: { desc: 'Delete a share by id' },
|
|
112
112
|
clear: { desc: 'Clean up shares by days and/or keep count' },
|
|
113
113
|
config: { desc: 'Show current share config section' },
|
|
114
|
-
|
|
114
|
+
server: { desc: 'Manage local server (start/stop/status)' },
|
|
115
115
|
help: { desc: 'Show this help' },
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
export class ShareGroup {
|
|
119
119
|
constructor() {
|
|
120
120
|
this.name = 'share'
|
|
121
|
-
this.desc = 'Text sharing service (upload/get/open/list/
|
|
121
|
+
this.desc = 'Text sharing service (upload/get/open/list/server)'
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
async run(argv) {
|
|
@@ -150,8 +150,8 @@ export class ShareGroup {
|
|
|
150
150
|
return this._clear(parsed)
|
|
151
151
|
case 'config':
|
|
152
152
|
return this._config(parsed)
|
|
153
|
-
case '
|
|
154
|
-
return this.
|
|
153
|
+
case 'server':
|
|
154
|
+
return this._server(parsed)
|
|
155
155
|
default:
|
|
156
156
|
return this._upload(parseFlags([action, ...rest]))
|
|
157
157
|
}
|
|
@@ -228,7 +228,7 @@ export class ShareGroup {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
console.error(`[opm share] Failed to start local server. Run "opm share
|
|
231
|
+
console.error(`[opm share] Failed to start local server. Run "opm share server status" to check.`)
|
|
232
232
|
process.exit(1)
|
|
233
233
|
}
|
|
234
234
|
|
|
@@ -498,31 +498,31 @@ export class ShareGroup {
|
|
|
498
498
|
output(cfg)
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
-
async
|
|
501
|
+
async _server(parsed) {
|
|
502
502
|
const [sub] = parsed.positional
|
|
503
503
|
|
|
504
504
|
if (sub === 'start') {
|
|
505
|
-
return this.
|
|
505
|
+
return this._serverrStart()
|
|
506
506
|
}
|
|
507
507
|
if (sub === 'stop') {
|
|
508
|
-
return this.
|
|
508
|
+
return this._serverrStop()
|
|
509
509
|
}
|
|
510
510
|
if (sub === 'status' || !sub) {
|
|
511
|
-
return this.
|
|
511
|
+
return this._serverrStatus()
|
|
512
512
|
}
|
|
513
513
|
if (sub === 'help' || sub === '-h' || sub === '--help') {
|
|
514
|
-
this.
|
|
514
|
+
this._serverrHelp()
|
|
515
515
|
return
|
|
516
516
|
}
|
|
517
517
|
|
|
518
|
-
console.error(`Unknown
|
|
519
|
-
console.error('Usage: opm share
|
|
518
|
+
console.error(`Unknown server subcommand: ${sub}`)
|
|
519
|
+
console.error('Usage: opm share server [start|stop|status|help]')
|
|
520
520
|
process.exit(1)
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
|
|
523
|
+
_serverrHelp() {
|
|
524
524
|
console.log(`
|
|
525
|
-
Usage: opm share
|
|
525
|
+
Usage: opm share server <subcommand>
|
|
526
526
|
|
|
527
527
|
Subcommands:
|
|
528
528
|
start Start local server (background, reads host/port/dataDir from config)
|
|
@@ -531,9 +531,9 @@ Subcommands:
|
|
|
531
531
|
help Show this help
|
|
532
532
|
|
|
533
533
|
Local development:
|
|
534
|
-
opm share
|
|
535
|
-
opm share
|
|
536
|
-
opm share
|
|
534
|
+
opm share server start Start in background (reads config)
|
|
535
|
+
opm share server status Check status
|
|
536
|
+
opm share server stop Stop server
|
|
537
537
|
opm share config Show current config (host/port/dataDir)
|
|
538
538
|
|
|
539
539
|
# Or run server.js directly (foreground):
|
|
@@ -549,7 +549,7 @@ Deploy to server:
|
|
|
549
549
|
# share.server.active = "official" # or a custom URL
|
|
550
550
|
|
|
551
551
|
# 3. Start the server (foreground or via process manager)
|
|
552
|
-
opm share
|
|
552
|
+
opm share server start
|
|
553
553
|
# Or with custom env:
|
|
554
554
|
OPM_SHARE_HOST=0.0.0.0 OPM_SHARE_PORT=80 OPM_SHARE_DATA_DIR=/var/lib/opm/share node src/tools/share/server.js
|
|
555
555
|
|
|
@@ -587,7 +587,7 @@ Environment variables (for server.js direct execution):
|
|
|
587
587
|
`)
|
|
588
588
|
}
|
|
589
589
|
|
|
590
|
-
|
|
590
|
+
_serverrStart() {
|
|
591
591
|
const existing = readServePid()
|
|
592
592
|
if (existing && isProcessAlive(existing.pid)) {
|
|
593
593
|
output({ running: true, pid: existing.pid, url: existing.url, host: existing.host, port: existing.port, dataDir: existing.dataDir, started: existing.started, message: 'Server already running' })
|
|
@@ -595,7 +595,7 @@ Environment variables (for server.js direct execution):
|
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
this._startBackground()
|
|
598
|
-
output({ started: true, message: 'Server started in background. Run "opm share
|
|
598
|
+
output({ started: true, message: 'Server started in background. Run "opm share server status" to check.' })
|
|
599
599
|
}
|
|
600
600
|
|
|
601
601
|
_startBackground() {
|
|
@@ -628,10 +628,10 @@ Environment variables (for server.js direct execution):
|
|
|
628
628
|
fs.writeFileSync(pidFile, JSON.stringify(pidInfo, null, 2), 'utf8')
|
|
629
629
|
}
|
|
630
630
|
|
|
631
|
-
|
|
631
|
+
_serverrStop() {
|
|
632
632
|
const pidInfo = readServePid()
|
|
633
633
|
if (!pidInfo) {
|
|
634
|
-
output({ stopped: true, message: 'No
|
|
634
|
+
output({ stopped: true, message: 'No server process found (pid file missing)' })
|
|
635
635
|
return
|
|
636
636
|
}
|
|
637
637
|
|
|
@@ -650,10 +650,10 @@ Environment variables (for server.js direct execution):
|
|
|
650
650
|
output({ stopped: true, pid: pidInfo.pid, url: pidInfo.url, message: 'Server stopped' })
|
|
651
651
|
}
|
|
652
652
|
|
|
653
|
-
|
|
653
|
+
_serverrStatus() {
|
|
654
654
|
const pidInfo = readServePid()
|
|
655
655
|
if (!pidInfo) {
|
|
656
|
-
output({ running: false, message: 'No
|
|
656
|
+
output({ running: false, message: 'No server process found' })
|
|
657
657
|
return
|
|
658
658
|
}
|
|
659
659
|
|
|
@@ -678,10 +678,10 @@ Usage: opm share <action> [args] [options]
|
|
|
678
678
|
Actions:
|
|
679
679
|
${actionLines}
|
|
680
680
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
681
|
+
Server subcommands:
|
|
682
|
+
server start Start local server (background)
|
|
683
|
+
server stop Stop local server
|
|
684
|
+
server status Check local server status
|
|
685
685
|
|
|
686
686
|
Shorthand:
|
|
687
687
|
opm share "<content>" [-t title] Upload (without "upload" keyword)
|
|
@@ -704,9 +704,9 @@ Server config (config.json5):
|
|
|
704
704
|
|
|
705
705
|
Examples:
|
|
706
706
|
opm share config Show current share config
|
|
707
|
-
opm share
|
|
708
|
-
opm share
|
|
709
|
-
opm share
|
|
707
|
+
opm share server start Start local server (background)
|
|
708
|
+
opm share server status Check if server is running
|
|
709
|
+
opm share server stop Stop local server
|
|
710
710
|
opm share "hello world" -t test Upload text
|
|
711
711
|
opm share "hello world" -i myid Upload text with custom id "myid"
|
|
712
712
|
opm share "hello world" -p 1234 Upload text with password override
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
* pm2 save && pm2 startup
|
|
16
16
|
*
|
|
17
17
|
* 方式三:opm 内置管理
|
|
18
|
-
* opm share
|
|
19
|
-
* opm share
|
|
20
|
-
* opm share
|
|
18
|
+
* opm share server start # 后台启动(读取 config.json5 中 share.serve 配置)
|
|
19
|
+
* opm share server stop
|
|
20
|
+
* opm share server status
|
|
21
21
|
*
|
|
22
22
|
* ──────────────────────────────────────────────────────────────
|
|
23
23
|
* 可配置常量(集中在此,按需修改)
|
|
@@ -44,7 +44,7 @@ $LISTEN_PORT = 8787;
|
|
|
44
44
|
// 以下为服务实现,通常无需修改
|
|
45
45
|
// ──────────────────────────────────────────────────────────────
|
|
46
46
|
|
|
47
|
-
// 环境变量优先于常量(兼容 opm share
|
|
47
|
+
// 环境变量优先于常量(兼容 opm share server 后台启动注入的场景)
|
|
48
48
|
|
|
49
49
|
function resolveDataDir() {
|
|
50
50
|
global $DATA_DIR;
|
|
@@ -10,19 +10,27 @@
|
|
|
10
10
|
* 6. harness(npm 全局安装 @wwkit/harness,已安装则跳过)
|
|
11
11
|
* 7. sshproxy(npm 全局安装 @wwkit/sshproxy,已安装则跳过)
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* install 流程:镜像可达检查 → 安装组件 → 初始化 → 验证
|
|
14
|
+
* init 流程:ww config init → ww webdriver init → ww opencode init → ww sqlite init
|
|
15
|
+
* verify 流程:ww sqlite debug → ww run debug → ww web status → ww webdriver debug
|
|
16
|
+
*
|
|
17
|
+
* 命令: version / versions / installed / install / init / verify / uninstall / upgrade / help
|
|
14
18
|
*/
|
|
15
19
|
|
|
16
20
|
import { execSync } from 'node:child_process'
|
|
17
21
|
|
|
22
|
+
import { Shell } from '@wwkit/shared'
|
|
18
23
|
import { parseFlags } from '../../cli/helpers/args.js'
|
|
19
24
|
import { output } from '../../formatter.js'
|
|
20
|
-
import { getActiveProxy, getConfig } from '../../config.js'
|
|
25
|
+
import { getActiveProxy, getConfig, getActiveRegistry } from '../../config.js'
|
|
21
26
|
import { NpmManager } from '../../managers/npm.js'
|
|
22
27
|
import { PipManager } from '../../managers/pip.js'
|
|
23
28
|
import { PythonManager, isUvInstalled, installUv } from '../../managers/python.js'
|
|
24
29
|
import { NodeManager, isNvmInstalled, installNvm } from '../../managers/node.js'
|
|
25
30
|
import { CftGroup } from '../../binaries/cft/index.js'
|
|
31
|
+
import { checkReachability } from '../../cli/groups/ping.js'
|
|
32
|
+
|
|
33
|
+
const shell = new Shell()
|
|
26
34
|
|
|
27
35
|
const COMPONENTS = [
|
|
28
36
|
{ key: 'python', label: 'Python' },
|
|
@@ -44,8 +52,10 @@ const ACTIONS = {
|
|
|
44
52
|
version: { desc: 'Show installed version of each component' },
|
|
45
53
|
versions: { desc: 'Show latest available version of each component (remote)' },
|
|
46
54
|
installed: { desc: 'Show install status (true/false) of each component' },
|
|
47
|
-
install: { desc: 'Install all components
|
|
48
|
-
|
|
55
|
+
install: { desc: 'Install all components + init + verify' },
|
|
56
|
+
init: { desc: 'Initialize runtime (config/webdriver/opencode/sqlite)' },
|
|
57
|
+
verify: { desc: 'Verify installation (sqlite/run/web/webdriver)' },
|
|
58
|
+
uninstall: { desc: 'Uninstall all components in reverse order' },
|
|
49
59
|
upgrade: { desc: 'Upgrade all components to latest' },
|
|
50
60
|
help: { desc: 'Show this help' },
|
|
51
61
|
}
|
|
@@ -75,6 +85,10 @@ export class WebworkGroup {
|
|
|
75
85
|
return this._installed()
|
|
76
86
|
case 'install':
|
|
77
87
|
return this._install(parsed)
|
|
88
|
+
case 'init':
|
|
89
|
+
return this._init(parsed)
|
|
90
|
+
case 'verify':
|
|
91
|
+
return this._verify(parsed)
|
|
78
92
|
case 'uninstall':
|
|
79
93
|
return this._uninstall(parsed)
|
|
80
94
|
case 'upgrade':
|
|
@@ -183,7 +197,16 @@ export class WebworkGroup {
|
|
|
183
197
|
|
|
184
198
|
async _install(parsed) {
|
|
185
199
|
const proxy = this._resolveProxy(parsed)
|
|
200
|
+
|
|
201
|
+
console.log('\n========== 步骤 1/3: 检查镜像可达性 ==========')
|
|
202
|
+
await this._checkMirrors(proxy)
|
|
203
|
+
|
|
204
|
+
console.log('\n========== 步骤 2/3: 安装组件 ==========')
|
|
186
205
|
await this._runBatch('install', COMPONENTS, proxy, (key, p) => this._installComponent(key, p))
|
|
206
|
+
|
|
207
|
+
console.log('\n========== 步骤 3/3: 初始化 + 验证 ==========')
|
|
208
|
+
await this._init(parsed)
|
|
209
|
+
await this._verify(parsed)
|
|
187
210
|
}
|
|
188
211
|
|
|
189
212
|
async _uninstall(parsed) {
|
|
@@ -197,6 +220,139 @@ export class WebworkGroup {
|
|
|
197
220
|
await this._runBatch('upgrade', COMPONENTS, proxy, (key, p) => this._upgradeComponent(key, p))
|
|
198
221
|
}
|
|
199
222
|
|
|
223
|
+
/**
|
|
224
|
+
* 检查所有镜像可达性(HEAD 请求,不可达则抛错)
|
|
225
|
+
* @param {string} proxy
|
|
226
|
+
*/
|
|
227
|
+
async _checkMirrors(proxy) {
|
|
228
|
+
const tool = shell.getNetProbeTool()
|
|
229
|
+
if (!tool) {
|
|
230
|
+
console.log(' [WARN] No network probe tool (ping/curl/wget), skipping mirror check')
|
|
231
|
+
return
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const checks = [
|
|
235
|
+
{ name: 'npm', url: getActiveRegistry('npm') },
|
|
236
|
+
{ name: 'pip', url: getActiveRegistry('pip') },
|
|
237
|
+
]
|
|
238
|
+
|
|
239
|
+
if (!isNvmInstalled()) {
|
|
240
|
+
checks.push({ name: 'nvm', url: getActiveRegistry('nvm') })
|
|
241
|
+
checks.push({ name: 'node', url: getActiveRegistry('node') })
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const tool2 = new CftGroup()
|
|
245
|
+
if (tool2._listInstalled().length === 0) {
|
|
246
|
+
const config = getConfig()
|
|
247
|
+
const cftUrl = config.cft?.registry?.active || config.cft?.registry?.npmmirror || ''
|
|
248
|
+
if (cftUrl) checks.push({ name: 'cft', url: cftUrl })
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
let allOk = true
|
|
252
|
+
for (const { name, url } of checks) {
|
|
253
|
+
if (!url) {
|
|
254
|
+
console.log(` [SKIP] ${name}: no active registry`)
|
|
255
|
+
continue
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const result = await checkReachability(url, tool, 1, proxy)
|
|
259
|
+
if (result.reachable) {
|
|
260
|
+
console.log(` [OK] ${name}: ${url}`)
|
|
261
|
+
} else {
|
|
262
|
+
console.error(` [FAIL] ${name}: ${url} (${result.raw})`)
|
|
263
|
+
allOk = false
|
|
264
|
+
}
|
|
265
|
+
} catch (err) {
|
|
266
|
+
console.error(` [FAIL] ${name}: ${err.message}`)
|
|
267
|
+
allOk = false
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (!allOk) {
|
|
272
|
+
throw new Error('Some mirrors unreachable, aborting. Check network or set proxy with -p')
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* 运行时初始化(依赖 blues-lib 已安装)
|
|
278
|
+
* @param {object} parsed
|
|
279
|
+
*/
|
|
280
|
+
async _init(parsed) {
|
|
281
|
+
const steps = [
|
|
282
|
+
{ name: 'config', cmd: 'ww config init', required: true },
|
|
283
|
+
{ name: 'webdriver', cmd: 'ww webdriver init', required: true, hint: 'Downloads Chrome for Testing (~200MB)' },
|
|
284
|
+
{ name: 'opencode', cmd: 'ww opencode init', required: true },
|
|
285
|
+
{ name: 'sqlite', cmd: 'ww sqlite init', required: true },
|
|
286
|
+
]
|
|
287
|
+
|
|
288
|
+
for (const step of steps) {
|
|
289
|
+
console.log(` [INIT] ${step.name}...`)
|
|
290
|
+
try {
|
|
291
|
+
execSync(step.cmd, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] })
|
|
292
|
+
console.log(` [OK] ${step.name}`)
|
|
293
|
+
} catch (err) {
|
|
294
|
+
if (step.required) {
|
|
295
|
+
throw new Error(`${step.name} init failed: ${err.message}`)
|
|
296
|
+
}
|
|
297
|
+
console.error(` [WARN] ${step.name}: ${err.message}`)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 验证安装结果
|
|
304
|
+
* @param {object} parsed
|
|
305
|
+
*/
|
|
306
|
+
async _verify(parsed) {
|
|
307
|
+
const checks = [
|
|
308
|
+
{ name: 'sqlite', cmd: 'ww sqlite debug', pattern: /访问成功|ok|success/i },
|
|
309
|
+
{ name: 'run', cmd: 'ww run debug', pattern: /run debug/i },
|
|
310
|
+
{ name: 'web', cmd: 'ww web status', pattern: /running/i, optional: true },
|
|
311
|
+
]
|
|
312
|
+
|
|
313
|
+
for (const check of checks) {
|
|
314
|
+
console.log(` [VERIFY] ${check.name}...`)
|
|
315
|
+
try {
|
|
316
|
+
const out = execSync(check.cmd, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] })
|
|
317
|
+
if (check.pattern.test(out)) {
|
|
318
|
+
console.log(` [OK] ${check.name}`)
|
|
319
|
+
} else {
|
|
320
|
+
if (check.optional) {
|
|
321
|
+
console.log(` [WARN] ${check.name}: not running (optional)`)
|
|
322
|
+
} else {
|
|
323
|
+
console.error(` [FAIL] ${check.name}: output doesn't match expected pattern`)
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} catch (err) {
|
|
327
|
+
if (check.optional) {
|
|
328
|
+
console.log(` [WARN] ${check.name}: ${err.message}`)
|
|
329
|
+
} else {
|
|
330
|
+
console.error(` [FAIL] ${check.name}: ${err.message}`)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
try {
|
|
336
|
+
const staticIndex = execSync(
|
|
337
|
+
`python3 -c "import os, blues_lib.web; print(os.path.join(os.path.dirname(blues_lib.web.__file__), 'static', 'index.html'))"`,
|
|
338
|
+
{ encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }
|
|
339
|
+
).trim()
|
|
340
|
+
if (staticIndex) {
|
|
341
|
+
console.log(` [VERIFY] webdriver...`)
|
|
342
|
+
const out = execSync(`ww webdriver debug -u file://${staticIndex} --headless`, {
|
|
343
|
+
encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 60000
|
|
344
|
+
})
|
|
345
|
+
if (/webwork/i.test(out)) {
|
|
346
|
+
console.log(` [OK] webdriver`)
|
|
347
|
+
} else {
|
|
348
|
+
console.error(` [FAIL] webdriver: output doesn't contain 'webwork'`)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
} catch (err) {
|
|
352
|
+
console.error(` [WARN] webdriver: ${err.message}`)
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
200
356
|
async _installComponent(key, proxy) {
|
|
201
357
|
switch (key) {
|
|
202
358
|
case 'python':
|
|
@@ -516,12 +672,12 @@ export class WebworkGroup {
|
|
|
516
672
|
if (existing.installed) {
|
|
517
673
|
return { action: 'skipped', reason: `${name} ${existing.version} already installed`, version: existing.version }
|
|
518
674
|
}
|
|
519
|
-
return npm.install(name, null, { global: true, proxy })
|
|
675
|
+
return npm.install(name, null, { global: true, proxy, allowScripts: name.startsWith('@wwkit/') })
|
|
520
676
|
}
|
|
521
677
|
|
|
522
678
|
async _upgradeNpmPackage(name, proxy) {
|
|
523
679
|
const npm = new NpmManager()
|
|
524
|
-
return npm.upgrade(name, { global: true, proxy })
|
|
680
|
+
return npm.upgrade(name, { global: true, proxy, allowScripts: name.startsWith('@wwkit/') })
|
|
525
681
|
}
|
|
526
682
|
|
|
527
683
|
async _uninstallNpmPackage(name) {
|
|
@@ -550,7 +706,9 @@ Examples:
|
|
|
550
706
|
opm webwork version Show installed versions of all components
|
|
551
707
|
opm webwork versions Show latest available versions (remote)
|
|
552
708
|
opm webwork installed Show install status of all components
|
|
553
|
-
opm webwork install
|
|
709
|
+
opm webwork install Full install (mirror check + components + init + verify)
|
|
710
|
+
opm webwork init Initialize runtime only (config/webdriver/opencode/sqlite)
|
|
711
|
+
opm webwork verify Verify installation only
|
|
554
712
|
opm webwork uninstall Uninstall all components in reverse order
|
|
555
713
|
opm webwork upgrade Upgrade all components to latest
|
|
556
714
|
`)
|