@wwkit/opm 1.0.1 → 1.0.2
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 -1
- package/src/cli/groups/docker.js +116 -0
- package/src/cli/groups/wsl.js +220 -0
- package/src/cli/index.js +6 -0
- package/src/config.json5 +15 -0
- package/src/index.js +15 -0
- package/src/managers/docker.js +295 -0
- package/src/managers/wsl.js +258 -0
- package/src/tools/ftp/client.js +214 -0
- package/src/tools/ftp/index.js +271 -0
- package/src/tools/ftp/util.js +174 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwkit/opm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"basic-ftp": "^6.2.1",
|
|
35
36
|
"extract-zip": "^2.0.1",
|
|
36
37
|
"@wwkit/shared": "1.0.5"
|
|
37
38
|
},
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* docker 命令组 — 管理 Docker 自身与 daemon
|
|
3
|
+
*
|
|
4
|
+
* 继承 ToolManagerGroup 复用 version/installed/install/upgrade/uninstall/dir,
|
|
5
|
+
* 额外增加 status/start/stop/restart/open。
|
|
6
|
+
* 跨平台:Linux 用便捷脚本,macOS 用 brew cask,Windows 走 WSL2。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ToolManagerGroup } from './version-manager.js'
|
|
10
|
+
import { parseFlags } from '../helpers/args.js'
|
|
11
|
+
import { output } from '../../formatter.js'
|
|
12
|
+
import {
|
|
13
|
+
isDockerInstalled,
|
|
14
|
+
getDockerVersion,
|
|
15
|
+
installDocker,
|
|
16
|
+
upgradeDocker,
|
|
17
|
+
uninstallDocker,
|
|
18
|
+
getDockerDir,
|
|
19
|
+
getDockerStatus,
|
|
20
|
+
startDocker,
|
|
21
|
+
stopDocker,
|
|
22
|
+
restartDocker,
|
|
23
|
+
openDocker,
|
|
24
|
+
} from '../../managers/docker.js'
|
|
25
|
+
|
|
26
|
+
export class DockerGroup extends ToolManagerGroup {
|
|
27
|
+
constructor() {
|
|
28
|
+
super({
|
|
29
|
+
name: 'docker',
|
|
30
|
+
desc: 'Docker manager (install/upgrade/start/stop/open)',
|
|
31
|
+
hasRegistry: false,
|
|
32
|
+
isInstalled: () => isDockerInstalled(),
|
|
33
|
+
getPath: () => getDockerDir(),
|
|
34
|
+
versionCmd: () => 'docker --version',
|
|
35
|
+
parseVersion: (out) => {
|
|
36
|
+
const m = out.match(/Docker version\s+(\S+)/)
|
|
37
|
+
return m ? m[1] : out.trim()
|
|
38
|
+
},
|
|
39
|
+
install: () => installDocker(),
|
|
40
|
+
upgrade: () => upgradeDocker(),
|
|
41
|
+
uninstall: () => uninstallDocker(),
|
|
42
|
+
usage: 'opm docker <action> [options]',
|
|
43
|
+
actions: [
|
|
44
|
+
['version', 'Show Docker version'],
|
|
45
|
+
['installed', 'Check if Docker is installed'],
|
|
46
|
+
['install', 'Install Docker (Linux: get.docker.com, macOS: brew cask, Windows: WSL2)'],
|
|
47
|
+
['upgrade', 'Upgrade Docker'],
|
|
48
|
+
['uninstall', 'Uninstall Docker'],
|
|
49
|
+
['dir', 'Show Docker data directory'],
|
|
50
|
+
['status', 'Show Docker daemon status'],
|
|
51
|
+
['start', 'Start Docker daemon'],
|
|
52
|
+
['stop', 'Stop Docker daemon'],
|
|
53
|
+
['restart', 'Restart Docker daemon'],
|
|
54
|
+
['open', 'Open terminal with Docker ready'],
|
|
55
|
+
['help', 'Show this help'],
|
|
56
|
+
],
|
|
57
|
+
examples: [
|
|
58
|
+
'opm docker version',
|
|
59
|
+
'opm docker installed',
|
|
60
|
+
'opm docker install',
|
|
61
|
+
'opm docker upgrade',
|
|
62
|
+
'opm docker status',
|
|
63
|
+
'opm docker start',
|
|
64
|
+
'opm docker stop',
|
|
65
|
+
'opm docker restart',
|
|
66
|
+
'opm docker open',
|
|
67
|
+
'opm docker dir',
|
|
68
|
+
'opm docker uninstall',
|
|
69
|
+
],
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async run(argv) {
|
|
74
|
+
const [action, ...rest] = argv
|
|
75
|
+
|
|
76
|
+
if (!action || action === '-h' || action === '--help' || action === 'help') {
|
|
77
|
+
this.printHelp()
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
switch (action) {
|
|
82
|
+
case 'status':
|
|
83
|
+
return this._status()
|
|
84
|
+
case 'start':
|
|
85
|
+
return this._start()
|
|
86
|
+
case 'stop':
|
|
87
|
+
return this._stop()
|
|
88
|
+
case 'restart':
|
|
89
|
+
return this._restart()
|
|
90
|
+
case 'open':
|
|
91
|
+
return this._open()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return super.run(argv)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_status() {
|
|
98
|
+
output(getDockerStatus())
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
_start() {
|
|
102
|
+
output(startDocker())
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_stop() {
|
|
106
|
+
output(stopDocker())
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_restart() {
|
|
110
|
+
output(restartDocker())
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_open() {
|
|
114
|
+
output(openDocker())
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wsl 命令组 — 管理 WSL2 自身与发行版
|
|
3
|
+
*
|
|
4
|
+
* 继承 ToolManagerGroup 复用 version/installed/upgrade/uninstall/dir,
|
|
5
|
+
* 额外增加发行版管理动作(list/available/remove/start/stop/stop-all/
|
|
6
|
+
* set-default/default/status/open)与带可选参数的 install。
|
|
7
|
+
* 仅 Windows 可用;wsl.exe 输出为 UTF-16LE,需 override _version/_installed。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { execSync } from 'node:child_process'
|
|
11
|
+
import { ToolManagerGroup } from './version-manager.js'
|
|
12
|
+
import { parseFlags } from '../helpers/args.js'
|
|
13
|
+
import { output } from '../../formatter.js'
|
|
14
|
+
import {
|
|
15
|
+
isWslInstalled,
|
|
16
|
+
getWslVersion,
|
|
17
|
+
installWsl,
|
|
18
|
+
updateWsl,
|
|
19
|
+
uninstallWsl,
|
|
20
|
+
getWslDir,
|
|
21
|
+
listDistros,
|
|
22
|
+
listAvailable,
|
|
23
|
+
installDistro,
|
|
24
|
+
removeDistro,
|
|
25
|
+
startDistro,
|
|
26
|
+
stopDistro,
|
|
27
|
+
stopAll,
|
|
28
|
+
setDefaultDistro,
|
|
29
|
+
getDefaultDistro,
|
|
30
|
+
getWslStatus,
|
|
31
|
+
openWsl,
|
|
32
|
+
} from '../../managers/wsl.js'
|
|
33
|
+
|
|
34
|
+
export class WslGroup extends ToolManagerGroup {
|
|
35
|
+
constructor() {
|
|
36
|
+
super({
|
|
37
|
+
name: 'wsl',
|
|
38
|
+
desc: 'WSL2 manager (install/upgrade/list/open distros)',
|
|
39
|
+
hasRegistry: false,
|
|
40
|
+
isInstalled: () => isWslInstalled(),
|
|
41
|
+
getPath: () => getWslDir(),
|
|
42
|
+
versionCmd: () => 'wsl.exe --version',
|
|
43
|
+
parseVersion: (out) => out.trim().split('\n')[0].trim(),
|
|
44
|
+
install: () => installWsl(),
|
|
45
|
+
upgrade: () => updateWsl(),
|
|
46
|
+
uninstall: () => uninstallWsl(),
|
|
47
|
+
usage: 'opm wsl <action> [args] [options]',
|
|
48
|
+
actions: [
|
|
49
|
+
['version', 'Show WSL version'],
|
|
50
|
+
['installed', 'Check if WSL is installed'],
|
|
51
|
+
['install [distro]', 'Install WSL2 (or a specific distribution)'],
|
|
52
|
+
['upgrade', 'Update WSL kernel (wsl --update)'],
|
|
53
|
+
['uninstall', 'Show uninstall instructions'],
|
|
54
|
+
['dir', 'Show WSL data directory'],
|
|
55
|
+
['list', 'List installed distributions'],
|
|
56
|
+
['available', 'List available distributions'],
|
|
57
|
+
['remove <distro>', 'Remove a distribution'],
|
|
58
|
+
['start [distro]', 'Start a distribution in current terminal'],
|
|
59
|
+
['stop <distro>', 'Stop a distribution'],
|
|
60
|
+
['stop-all', 'Stop all distributions'],
|
|
61
|
+
['set-default <distro>', 'Set default distribution'],
|
|
62
|
+
['default', 'Show default distribution'],
|
|
63
|
+
['status', 'Show WSL status'],
|
|
64
|
+
['open [distro]', 'Open PowerShell window and enter WSL'],
|
|
65
|
+
['help', 'Show this help'],
|
|
66
|
+
],
|
|
67
|
+
examples: [
|
|
68
|
+
'opm wsl version',
|
|
69
|
+
'opm wsl installed',
|
|
70
|
+
'opm wsl install',
|
|
71
|
+
'opm wsl install Ubuntu',
|
|
72
|
+
'opm wsl list',
|
|
73
|
+
'opm wsl available',
|
|
74
|
+
'opm wsl open',
|
|
75
|
+
'opm wsl open Ubuntu',
|
|
76
|
+
'opm wsl start Ubuntu',
|
|
77
|
+
'opm wsl stop Ubuntu',
|
|
78
|
+
'opm wsl stop-all',
|
|
79
|
+
'opm wsl set-default Ubuntu',
|
|
80
|
+
'opm wsl default',
|
|
81
|
+
'opm wsl status',
|
|
82
|
+
'opm wsl dir',
|
|
83
|
+
],
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async run(argv) {
|
|
88
|
+
const [action, ...rest] = argv
|
|
89
|
+
|
|
90
|
+
if (!action || action === '-h' || action === '--help' || action === 'help') {
|
|
91
|
+
this.printHelp()
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
switch (action) {
|
|
96
|
+
case 'list':
|
|
97
|
+
return this._list()
|
|
98
|
+
case 'available':
|
|
99
|
+
return this._available()
|
|
100
|
+
case 'remove':
|
|
101
|
+
return this._remove(parseFlags(rest))
|
|
102
|
+
case 'start':
|
|
103
|
+
return this._start(parseFlags(rest))
|
|
104
|
+
case 'stop':
|
|
105
|
+
return this._stop(parseFlags(rest))
|
|
106
|
+
case 'stop-all':
|
|
107
|
+
return this._stopAll()
|
|
108
|
+
case 'set-default':
|
|
109
|
+
return this._setDefault(parseFlags(rest))
|
|
110
|
+
case 'default':
|
|
111
|
+
return this._default()
|
|
112
|
+
case 'status':
|
|
113
|
+
return this._status()
|
|
114
|
+
case 'open':
|
|
115
|
+
return this._open(parseFlags(rest))
|
|
116
|
+
case 'install':
|
|
117
|
+
return this._installDistro(parseFlags(rest))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return super.run(argv)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
_version() {
|
|
124
|
+
if (!isWslInstalled()) {
|
|
125
|
+
output('')
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
output(getWslVersion())
|
|
130
|
+
} catch {
|
|
131
|
+
output('')
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_installed() {
|
|
136
|
+
const installed = isWslInstalled()
|
|
137
|
+
const result = { name: 'wsl', installed }
|
|
138
|
+
if (installed) {
|
|
139
|
+
result.path = getWslDir()
|
|
140
|
+
try {
|
|
141
|
+
result.version = getWslVersion()
|
|
142
|
+
} catch {}
|
|
143
|
+
}
|
|
144
|
+
output(result)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_installDistro(parsed) {
|
|
148
|
+
const distro = parsed.positional[0]
|
|
149
|
+
if (distro) {
|
|
150
|
+
output(installDistro(distro))
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
if (isWslInstalled()) {
|
|
154
|
+
output({ name: 'wsl', installed: true, hint: 'WSL already installed, use "opm wsl install <distro>" to install a distribution' })
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
output(installWsl())
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_list() {
|
|
161
|
+
output(listDistros())
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_available() {
|
|
165
|
+
output(listAvailable().map((name) => ({ name })))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
_remove(parsed) {
|
|
169
|
+
const distro = parsed.positional[0]
|
|
170
|
+
if (!distro) {
|
|
171
|
+
console.error('Usage: opm wsl remove <distro>')
|
|
172
|
+
process.exit(1)
|
|
173
|
+
}
|
|
174
|
+
output(removeDistro(distro))
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
_start(parsed) {
|
|
178
|
+
const distro = parsed.positional[0] || getDefaultDistro()
|
|
179
|
+
if (!distro) {
|
|
180
|
+
console.error('Usage: opm wsl start [distro]')
|
|
181
|
+
process.exit(1)
|
|
182
|
+
}
|
|
183
|
+
output(startDistro(distro))
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
_stop(parsed) {
|
|
187
|
+
const distro = parsed.positional[0]
|
|
188
|
+
if (!distro) {
|
|
189
|
+
console.error('Usage: opm wsl stop <distro>')
|
|
190
|
+
process.exit(1)
|
|
191
|
+
}
|
|
192
|
+
output(stopDistro(distro))
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
_stopAll() {
|
|
196
|
+
output(stopAll())
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
_setDefault(parsed) {
|
|
200
|
+
const distro = parsed.positional[0]
|
|
201
|
+
if (!distro) {
|
|
202
|
+
console.error('Usage: opm wsl set-default <distro>')
|
|
203
|
+
process.exit(1)
|
|
204
|
+
}
|
|
205
|
+
output(setDefaultDistro(distro))
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
_default() {
|
|
209
|
+
output({ default: getDefaultDistro() })
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
_status() {
|
|
213
|
+
output(getWslStatus())
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
_open(parsed) {
|
|
217
|
+
const distro = parsed.positional[0] || getDefaultDistro()
|
|
218
|
+
output(openWsl(distro || ''))
|
|
219
|
+
}
|
|
220
|
+
}
|
package/src/cli/index.js
CHANGED
|
@@ -15,7 +15,10 @@ import { NvmGroup } from './groups/nvm.js'
|
|
|
15
15
|
import { PhpenvGroup } from './groups/phpenv.js'
|
|
16
16
|
import { UvGroup } from './groups/uv.js'
|
|
17
17
|
import { HomebrewGroup } from './groups/homebrew.js'
|
|
18
|
+
import { WslGroup } from './groups/wsl.js'
|
|
19
|
+
import { DockerGroup } from './groups/docker.js'
|
|
18
20
|
import { EnsureGroup } from './groups/ensure.js'
|
|
21
|
+
import { FtpGroup } from '../tools/ftp/index.js'
|
|
19
22
|
import { HarnessGroup } from '../harnesses/base.js'
|
|
20
23
|
import { opencodeHarness } from '../harnesses/opencode/index.js'
|
|
21
24
|
import { CftGroup } from '../binaries/cft/index.js'
|
|
@@ -33,6 +36,9 @@ const GROUPS = {
|
|
|
33
36
|
apt: new PackageGroup('apt'),
|
|
34
37
|
brew: new PackageGroup('brew'),
|
|
35
38
|
homebrew: new HomebrewGroup(),
|
|
39
|
+
wsl: new WslGroup(),
|
|
40
|
+
docker: new DockerGroup(),
|
|
41
|
+
ftp: new FtpGroup(),
|
|
36
42
|
composer: new PackageGroup('composer'),
|
|
37
43
|
bun: new PackageGroup('bun'),
|
|
38
44
|
winget: new PackageGroup('winget'),
|
package/src/config.json5
CHANGED
|
@@ -155,4 +155,19 @@
|
|
|
155
155
|
active: "npmmirror",
|
|
156
156
|
},
|
|
157
157
|
},
|
|
158
|
+
|
|
159
|
+
// FTP 连接配置
|
|
160
|
+
// password 用 {env:XXX} 引用环境变量,不硬编码
|
|
161
|
+
// pasv: false — 阿里云虚拟主机必须用主动模式
|
|
162
|
+
ftp: {
|
|
163
|
+
host: "wh-nxb3pizm7zyfvpv4113.my3w.com",
|
|
164
|
+
port: 21,
|
|
165
|
+
user: "{env:FTP_USER}",
|
|
166
|
+
password: "{env:FTP_PASSWORD}",
|
|
167
|
+
remote_root: "/htdocs/webwork",
|
|
168
|
+
base_url: "http://deepbluenet.com/webwork",
|
|
169
|
+
timeout: 120,
|
|
170
|
+
max_retries: 2,
|
|
171
|
+
pasv: false,
|
|
172
|
+
},
|
|
158
173
|
}
|
package/src/index.js
CHANGED
|
@@ -16,6 +16,10 @@ export { CftGroup } from './binaries/cft/index.js'
|
|
|
16
16
|
export { NvmGroup } from './cli/groups/nvm.js'
|
|
17
17
|
export { PhpenvGroup } from './cli/groups/phpenv.js'
|
|
18
18
|
export { UvGroup } from './cli/groups/uv.js'
|
|
19
|
+
export { HomebrewGroup } from './cli/groups/homebrew.js'
|
|
20
|
+
export { WslGroup } from './cli/groups/wsl.js'
|
|
21
|
+
export { DockerGroup } from './cli/groups/docker.js'
|
|
22
|
+
export { FtpGroup } from './tools/ftp/index.js'
|
|
19
23
|
export { ToolManagerGroup } from './cli/groups/version-manager.js'
|
|
20
24
|
export { parseFlags } from './cli/helpers/args.js'
|
|
21
25
|
|
|
@@ -31,6 +35,17 @@ export { BunManager } from './managers/bun.js'
|
|
|
31
35
|
export { NodeManager, isNvmInstalled, getNvmSh } from './managers/node.js'
|
|
32
36
|
export { PhpManager, isPhpenvInstalled, getPhpenvBin } from './managers/php.js'
|
|
33
37
|
export { PythonManager, isUvInstalled, getUvBin } from './managers/python.js'
|
|
38
|
+
export {
|
|
39
|
+
isWslInstalled, getWslVersion, parseWslVersionOutput, parseDistroList,
|
|
40
|
+
parseAvailableList, listDistros, listAvailable, installDistro, removeDistro,
|
|
41
|
+
startDistro, stopDistro, stopAll, setDefaultDistro, getDefaultDistro,
|
|
42
|
+
getWslStatus, openWsl, installWsl, updateWsl, uninstallWsl, getWslDir,
|
|
43
|
+
} from './managers/wsl.js'
|
|
44
|
+
export {
|
|
45
|
+
isDockerInstalled, getDockerVersion, installDocker, upgradeDocker,
|
|
46
|
+
uninstallDocker, getDockerDir, getDockerStatus, startDocker, stopDocker,
|
|
47
|
+
restartDocker, openDocker,
|
|
48
|
+
} from './managers/docker.js'
|
|
34
49
|
|
|
35
50
|
export {
|
|
36
51
|
NPM_PRESETS, PIP_PRESETS, DNF_PRESETS, APT_PRESETS, BREW_PRESETS, COMPOSER_PRESETS,
|