dudu-converter-cli 1.0.0 → 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 -2
- package/release/cli.js +7 -7
- package/web/dist/assets/index-BvzR1CnI.js +32 -0
- package/web/dist/assets/index-GlrxWhv_.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/install.ps1 +35 -16
- package/web/dist/install.sh +51 -16
- package/web/dist/assets/index-BZqxEIrH.js +0 -32
- package/web/dist/assets/index-DuwKbhiJ.css +0 -1
package/web/dist/install.ps1
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
# 嘟嘟转换器(dudu-converter-cli)Windows 一键安装脚本(PowerShell 5.1+)
|
|
2
|
-
# 用法:irm
|
|
2
|
+
# 用法:irm https://duduer.com/install.ps1 | iex
|
|
3
3
|
$ErrorActionPreference = 'Stop'
|
|
4
4
|
|
|
5
|
+
# 修复中文输出乱码(irm|iex 场景下 PowerShell 默认编码非 UTF-8)
|
|
6
|
+
try {
|
|
7
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
8
|
+
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
9
|
+
} catch { }
|
|
10
|
+
|
|
5
11
|
$PackageSpec = if ($env:CONVERTER_PACKAGE_SPEC) { $env:CONVERTER_PACKAGE_SPEC } else { 'dudu-converter-cli' }
|
|
6
12
|
|
|
7
13
|
function Say($msg) { Write-Host $msg -ForegroundColor Green }
|
|
8
14
|
function Warn($msg) { Write-Host $msg -ForegroundColor Yellow }
|
|
9
|
-
function
|
|
15
|
+
function Show-Manual {
|
|
16
|
+
Write-Host ''
|
|
17
|
+
Warn '自动安装未完成,可按以下步骤手动安装:'
|
|
18
|
+
Write-Host ' 1. 打开 https://nodejs.org 下载并安装 Node.js 18 或更高版本(安装时保持默认选项)'
|
|
19
|
+
Write-Host ' 2. 重新打开 PowerShell,执行: npm install -g dudu-converter-cli'
|
|
20
|
+
Write-Host ' 3. 启动服务: converter start'
|
|
21
|
+
Write-Host ' 4. 浏览器访问 http://127.0.0.1:3456'
|
|
22
|
+
}
|
|
23
|
+
function Die($msg) { Write-Host $msg -ForegroundColor Red; Show-Manual; exit 1 }
|
|
10
24
|
|
|
11
25
|
function Test-Node {
|
|
12
26
|
$node = Get-Command node -ErrorAction SilentlyContinue
|
|
@@ -23,50 +37,55 @@ function Refresh-Path {
|
|
|
23
37
|
$env:Path = "$machinePath;$userPath"
|
|
24
38
|
}
|
|
25
39
|
|
|
26
|
-
if (
|
|
40
|
+
if (Test-Node) {
|
|
41
|
+
Say "检测到 Node $(node -v),满足要求(需 18+),跳过安装"
|
|
42
|
+
} else {
|
|
27
43
|
Say '未检测到 Node.js 18+,准备安装…'
|
|
28
44
|
if (Get-Command winget -ErrorAction SilentlyContinue) {
|
|
29
45
|
winget install --id OpenJS.NodeJS.LTS --accept-source-agreements --accept-package-agreements
|
|
30
|
-
if ($LASTEXITCODE -ne 0) { Die 'Node.js
|
|
46
|
+
if ($LASTEXITCODE -ne 0) { Die 'Node.js 安装失败' }
|
|
31
47
|
}
|
|
32
48
|
elseif (Get-Command choco -ErrorAction SilentlyContinue) {
|
|
33
49
|
choco install nodejs-lts -y
|
|
34
|
-
if ($LASTEXITCODE -ne 0) { Die 'Node.js
|
|
50
|
+
if ($LASTEXITCODE -ne 0) { Die 'Node.js 安装失败' }
|
|
35
51
|
}
|
|
36
52
|
elseif (Get-Command scoop -ErrorAction SilentlyContinue) {
|
|
37
53
|
scoop install nodejs-lts
|
|
38
|
-
if ($LASTEXITCODE -ne 0) { Die 'Node.js
|
|
54
|
+
if ($LASTEXITCODE -ne 0) { Die 'Node.js 安装失败' }
|
|
39
55
|
}
|
|
40
56
|
else {
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
Say '未检测到 winget / choco / scoop,直接下载 Node.js 官方安装包…'
|
|
58
|
+
$nodeArch = if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { 'arm64' } else { 'x64' }
|
|
59
|
+
$msiUrl = "https://nodejs.org/dist/v22.20.0/node-v22.20.0-$nodeArch.msi"
|
|
60
|
+
$msiFile = Join-Path $env:TEMP 'dudu-node-installer.msi'
|
|
61
|
+
Invoke-WebRequest -Uri $msiUrl -OutFile $msiFile -UseBasicParsing
|
|
62
|
+
Say '正在安装 Node.js(可能弹出系统授权窗口,请点「是」)…'
|
|
63
|
+
Start-Process msiexec.exe -ArgumentList '/i', $msiFile, '/qn' -Verb RunAs -Wait
|
|
43
64
|
}
|
|
44
65
|
# 刚安装的 Node 不会出现在当前会话的 PATH 中,需从注册表重新加载
|
|
45
66
|
Refresh-Path
|
|
67
|
+
if (-not (Test-Node)) { Die 'Node.js 安装后仍未检测到,请重新打开 PowerShell 再执行本脚本' }
|
|
46
68
|
}
|
|
47
69
|
|
|
48
70
|
Say "正在安装嘟嘟转换器($PackageSpec)…"
|
|
49
71
|
npm install -g $PackageSpec
|
|
50
72
|
if ($LASTEXITCODE -ne 0) { Die '安装失败,请检查网络后重试' }
|
|
51
73
|
|
|
74
|
+
Refresh-Path
|
|
52
75
|
$converter = Get-Command converter -ErrorAction SilentlyContinue
|
|
53
|
-
if (-not $converter) { Die '安装完成但找不到 converter 命令,请重新打开 PowerShell
|
|
76
|
+
if (-not $converter) { Die '安装完成但找不到 converter 命令,请重新打开 PowerShell 后执行:converter start' }
|
|
54
77
|
Say "安装成功:converter $(converter --version)"
|
|
55
78
|
|
|
56
|
-
# 注册 converter:// 协议句柄:官网「一键启动服务」按钮使用
|
|
57
|
-
reg add "HKCU\Software\Classes\converter" /ve /d "URL:Dudu Converter Protocol" /f | Out-Null
|
|
58
|
-
reg add "HKCU\Software\Classes\converter" /v "URL Protocol" /f | Out-Null
|
|
59
|
-
reg add "HKCU\Software\Classes\converter\shell\open\command" /ve /d "powershell.exe -NoProfile -WindowStyle Hidden -Command \"Start-Process converter -ArgumentList 'start','--daemon','-no-open-browser'\"" /f | Out-Null
|
|
60
|
-
|
|
61
79
|
if ($env:NO_START -eq '1') {
|
|
62
80
|
Say '已跳过启动。之后可随时运行:converter start'
|
|
63
81
|
exit 0
|
|
64
82
|
}
|
|
65
83
|
|
|
66
84
|
Say '正在开启开机自启…'
|
|
67
|
-
converter autostart enable
|
|
85
|
+
converter autostart enable
|
|
86
|
+
if ($LASTEXITCODE -ne 0) { Warn '开机自启开启失败(不影响本次使用),可稍后在终端执行:converter autostart enable' }
|
|
68
87
|
|
|
69
88
|
Say '正在启动服务,浏览器将自动打开…'
|
|
70
|
-
Start-Process -FilePath 'cmd.exe' -ArgumentList '/c', 'converter', 'start'
|
|
89
|
+
Start-Process -FilePath 'cmd.exe' -ArgumentList '/c', 'converter', 'start'
|
|
71
90
|
Start-Sleep -Seconds 2
|
|
72
91
|
Say '完成!若浏览器未自动打开,请访问 http://127.0.0.1:3456'
|
package/web/dist/install.sh
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
# 嘟嘟转换器(dudu-converter-cli)macOS 一键安装脚本
|
|
3
|
-
# 用法:curl -fsSL
|
|
3
|
+
# 用法:curl -fsSL https://duduer.com/install.sh | sh
|
|
4
4
|
set -eu
|
|
5
5
|
|
|
6
6
|
PACKAGE_SPEC="${CONVERTER_PACKAGE_SPEC:-dudu-converter-cli}"
|
|
@@ -8,9 +8,17 @@ NO_START="${NO_START:-0}"
|
|
|
8
8
|
|
|
9
9
|
say() { printf '\033[1;32m%s\033[0m\n' "$*"; }
|
|
10
10
|
warn() { printf '\033[1;33m%s\033[0m\n' "$*"; }
|
|
11
|
-
die() {
|
|
11
|
+
die() {
|
|
12
|
+
printf '\033[1;31m%s\033[0m\n' "$*" >&2
|
|
13
|
+
printf '\033[1;33m%s\n\033[0m' "自动安装未完成,可按以下步骤手动安装:"
|
|
14
|
+
printf ' 1. 打开 https://nodejs.org 下载并安装 Node.js 18 或更高版本\n'
|
|
15
|
+
printf ' 2. 打开「终端」,执行: npm install -g dudu-converter-cli\n'
|
|
16
|
+
printf ' 3. 启动服务: converter start\n'
|
|
17
|
+
printf ' 4. 浏览器访问 http://127.0.0.1:3456\n'
|
|
18
|
+
exit 1
|
|
19
|
+
}
|
|
12
20
|
|
|
13
|
-
[ "$(uname)" = "Darwin" ] || die "此安装脚本仅支持 macOS。Windows 用户请在 PowerShell 中运行:irm
|
|
21
|
+
[ "$(uname)" = "Darwin" ] || die "此安装脚本仅支持 macOS。Windows 用户请在 PowerShell 中运行:irm https://duduer.com/install.ps1 | iex"
|
|
14
22
|
|
|
15
23
|
macos_major="$(sw_vers -productVersion | cut -d. -f1)"
|
|
16
24
|
if [ "$macos_major" -lt 12 ] 2>/dev/null; then
|
|
@@ -20,21 +28,49 @@ fi
|
|
|
20
28
|
node_major=0
|
|
21
29
|
if command -v node >/dev/null 2>&1; then
|
|
22
30
|
node_major="$(node -p 'Number(process.versions.node.split(".")[0])')"
|
|
31
|
+
if [ "$node_major" -ge 18 ]; then
|
|
32
|
+
say "检测到 Node $(node -v),满足要求(需 18+),跳过安装"
|
|
33
|
+
fi
|
|
23
34
|
fi
|
|
24
35
|
if [ "$node_major" -lt 18 ]; then
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
# 裸机也全自动:直接下载 Node.js 官方 pkg 安装(不依赖 Homebrew)
|
|
37
|
+
NODE_VERSION="22.20.0"
|
|
38
|
+
NODE_PKG_URL="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}.pkg"
|
|
39
|
+
PKG_FILE="${TMPDIR:-/tmp}/dudu-node-installer.pkg"
|
|
40
|
+
say "未检测到 Node.js 18+,正在下载官方安装包(约 70MB)…"
|
|
41
|
+
curl -fsSL "$NODE_PKG_URL" -o "$PKG_FILE" || die "Node.js 安装包下载失败,请检查网络后重试,或到 https://nodejs.org 下载安装"
|
|
42
|
+
say "正在安装 Node.js(可能需要输入一次开机密码)…"
|
|
43
|
+
sudo installer -pkg "$PKG_FILE" -target / || die "Node.js 安装失败,请到 https://nodejs.org 手动安装后重跑本脚本"
|
|
44
|
+
rm -f "$PKG_FILE"
|
|
45
|
+
export PATH="/usr/local/bin:$PATH"
|
|
46
|
+
hash -r
|
|
47
|
+
say "Node.js 安装完成"
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
# npm 缓存目录若存在 root 属主文件(历史 sudo npm 遗留),普通安装会报 EACCES——检测并自动修复
|
|
51
|
+
if [ -d "$HOME/.npm" ] && [ -n "$(find "$HOME/.npm" -user root -print -quit 2>/dev/null)" ]; then
|
|
52
|
+
warn "检测到 ~/.npm 存在 root 属主文件(历史 sudo npm 遗留),正在修复权限(需要输入一次密码)…"
|
|
53
|
+
sudo chown -R "$(id -u):$(id -g)" "$HOME/.npm" || die "缓存权限修复失败,请手动执行:sudo chown -R \$(id -u):\$(id -g) ~/.npm"
|
|
54
|
+
say "权限修复完成"
|
|
34
55
|
fi
|
|
35
56
|
|
|
36
57
|
say "正在安装嘟嘟转换器(${PACKAGE_SPEC})…"
|
|
37
|
-
npm install -g "$PACKAGE_SPEC"
|
|
58
|
+
if output=$(npm install -g "$PACKAGE_SPEC" 2>&1); then
|
|
59
|
+
:
|
|
60
|
+
else
|
|
61
|
+
printf '%s\n' "$output" | tail -3
|
|
62
|
+
if printf '%s\n' "$output" | grep -qi "_cacache"; then
|
|
63
|
+
warn "检测到 npm 缓存权限问题,尝试修复后重试(需要输入一次密码)…"
|
|
64
|
+
sudo chown -R "$(id -u):$(id -g)" "$HOME/.npm" || die "缓存权限修复失败,请手动执行:sudo chown -R \$(id -u):\$(id -g) ~/.npm"
|
|
65
|
+
npm install -g "$PACKAGE_SPEC" || die "安装仍失败,请按上方提示修复后重试"
|
|
66
|
+
elif printf '%s\n' "$output" | grep -qi "EACCES"; then
|
|
67
|
+
# Node 装在系统目录(/usr/local)时,全局安装需要管理员权限——改用 sudo 安装
|
|
68
|
+
warn "全局安装目录需要管理员权限,改用 sudo 安装(需要输入一次密码)…"
|
|
69
|
+
sudo "$(command -v npm)" install -g "$PACKAGE_SPEC" || die "安装失败,请手动执行:sudo npm install -g ${PACKAGE_SPEC}"
|
|
70
|
+
else
|
|
71
|
+
die "安装失败,请检查网络后重试"
|
|
72
|
+
fi
|
|
73
|
+
fi
|
|
38
74
|
|
|
39
75
|
command -v converter >/dev/null 2>&1 || die "安装完成但找不到 converter 命令,请重新打开终端后重新执行本脚本"
|
|
40
76
|
say "安装成功:converter $(converter --version)"
|
|
@@ -45,9 +81,8 @@ if [ "$NO_START" = "1" ]; then
|
|
|
45
81
|
fi
|
|
46
82
|
|
|
47
83
|
say "正在开启开机自启…"
|
|
48
|
-
converter autostart enable >/dev/null 2>&1 || warn "
|
|
84
|
+
converter autostart enable >/dev/null 2>&1 || warn "开机自启开启失败(不影响本次使用),可稍后在终端执行:converter autostart enable"
|
|
49
85
|
|
|
50
86
|
say "正在启动服务,浏览器将自动打开…"
|
|
51
|
-
|
|
52
|
-
sleep 2
|
|
87
|
+
converter start >/dev/null 2>&1 || warn "服务启动失败,可稍后在终端执行:converter start"
|
|
53
88
|
say "完成!若浏览器未自动打开,请访问 http://127.0.0.1:3456"
|