- 结论先行与依赖清单:GUI 行改为「SwiftUI(App/)=Mac 分支保留;新建 App.Win/(Tauri 2 + 内嵌 Vue3)」 - 阶段 4 改为「Windows GUI 分支」:三方案选型(推荐 Tauri 2)、Mac/Win 代码组织、 Windows 特性与 macOS(SwiftUI) 的等价物对照表 - 速查表与落地形态同步更新
190 lines
8.0 KiB
PowerShell
190 lines
8.0 KiB
PowerShell
# FinDataHub Windows 端 · 基础依赖安装脚本
|
||
# 仅安装运行 FinDataHub 所需的「基础依赖软件」,不安装 FinDataHub 本体。
|
||
# 依赖清单:Git / Python 3.12 / Node.js LTS / uv / pnpm / MySQL(默认仅检测引导)
|
||
#
|
||
# 用法:
|
||
# 双击 install-deps.cmd(自动请求管理员权限)
|
||
# 或 PowerShell(管理员):powershell -ExecutionPolicy Bypass -File install-deps.ps1
|
||
# 若要静默安装 MySQL: powershell -ExecutionPolicy Bypass -File install-deps.ps1 -IncludeMySQL
|
||
|
||
[CmdletBinding()]
|
||
param(
|
||
[switch]$IncludeMySQL # 显式传入才尝试静默安装 MySQL(默认仅检测 + 引导)
|
||
)
|
||
|
||
$ErrorActionPreference = 'Continue'
|
||
|
||
# ---------- 日志辅助 ----------
|
||
function Write-Step { param([string]$m) Write-Host "`n==> $m" -ForegroundColor Cyan }
|
||
function Write-Ok { param([string]$m) Write-Host " [OK] $m" -ForegroundColor Green }
|
||
function Write-Warn { param([string]$m) Write-Host " [!] $m" -ForegroundColor Yellow }
|
||
function Write-Err { param([string]$m) Write-Host " [X] $m" -ForegroundColor Red }
|
||
|
||
function Test-Cmd([string]$name) {
|
||
return [bool](Get-Command $name -ErrorAction SilentlyContinue)
|
||
}
|
||
|
||
# ---------- winget ----------
|
||
function Get-Winget {
|
||
if (Test-Cmd 'winget') { return $true }
|
||
Write-Warn '未检测到 winget(Windows 10 需先安装「应用安装程序 / App Installer」)。'
|
||
Write-Warn '请打开 Microsoft Store 搜索安装「应用安装程序」,或参考 https://aka.ms/getwinget'
|
||
return $false
|
||
}
|
||
|
||
function Install-WingetPkg([string]$id, [string]$override) {
|
||
Write-Step "安装 $id"
|
||
$pkgArgs = @('install', '--id', $id, '-e', '--source', 'winget',
|
||
'--silent', '--accept-package-agreements', '--accept-source-agreements')
|
||
if ($override) { $pkgArgs += '--override'; $pkgArgs += $override }
|
||
& winget @pkgArgs
|
||
if ($LASTEXITCODE -eq 0) {
|
||
Write-Ok "$id 安装完成"
|
||
} else {
|
||
Write-Err "$id 安装失败(退出码 $LASTEXITCODE),可手动运行 winget search $id 确认包名后重试"
|
||
}
|
||
}
|
||
|
||
# ---------- 刷新当前会话 PATH(安装后本会话内验证用) ----------
|
||
function Refresh-Path {
|
||
$add = @(
|
||
'C:\Program Files\Git\cmd',
|
||
'C:\Program Files\Python312',
|
||
'C:\Program Files\Python312\Scripts',
|
||
'C:\Program Files\nodejs'
|
||
)
|
||
foreach ($p in $add) {
|
||
if ((Test-Path $p) -and ($env:Path -notlike "*$p*")) {
|
||
$env:Path = "$p;$env:Path"
|
||
}
|
||
}
|
||
}
|
||
|
||
# ---------- 各依赖软件 ----------
|
||
function Ensure-Git {
|
||
if (Test-Cmd 'git') { Write-Ok "git 已存在: $(git --version)"; return }
|
||
Install-WingetPkg 'Git.Git'
|
||
}
|
||
|
||
function Ensure-Python312 {
|
||
if (Test-Cmd 'python') {
|
||
$v = python --version 2>&1
|
||
if ($v -match '3\.12') { Write-Ok "Python 已存在: $v"; return }
|
||
Write-Warn "已装 Python 但非 3.12(当前: $v),FinDataHub 要求 3.12,继续安装 3.12"
|
||
}
|
||
# InstallAllUsers=1 装到 C:\Program Files\Python312;PrependPath=1 写入系统 PATH
|
||
Install-WingetPkg 'Python.Python.3.12' '/quiet InstallAllUsers=1 PrependPath=1 Include_test=0 Include_launcher=0'
|
||
Refresh-Path
|
||
if (Test-Cmd 'python') { Write-Ok "Python: $(python --version)" }
|
||
else { Write-Err 'Python 3.12 安装后未能识别,请关闭本窗口重开后再验证' }
|
||
}
|
||
|
||
function Ensure-NodeLTS {
|
||
if (Test-Cmd 'node') { Write-Ok "Node 已存在: $(node --version)"; return }
|
||
Install-WingetPkg 'OpenJS.NodeJS.LTS'
|
||
Refresh-Path
|
||
if (Test-Cmd 'node') { Write-Ok "Node: $(node --version)" }
|
||
else { Write-Err 'Node 安装后未能识别,请关闭本窗口重开后再验证' }
|
||
}
|
||
|
||
function Ensure-Uv {
|
||
if (Test-Cmd 'uv') { Write-Ok "uv 已存在: $(uv --version)"; return }
|
||
Write-Step '安装 uv(pip 安装,走清华镜像)'
|
||
python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple uv
|
||
if ($LASTEXITCODE -eq 0) { Write-Ok "uv: $(uv --version)" }
|
||
else { Write-Err 'uv 安装失败' }
|
||
}
|
||
|
||
function Ensure-Pnpm {
|
||
if (Test-Cmd 'pnpm') { Write-Ok "pnpm 已存在: $(pnpm --version)"; return }
|
||
Write-Step '安装 pnpm(npm 全局安装,走 npmmirror 镜像)'
|
||
npm install -g pnpm --registry=https://registry.npmmirror.com
|
||
if ($LASTEXITCODE -eq 0) { Write-Ok "pnpm: $(pnpm --version)" }
|
||
else { Write-Err 'pnpm 安装失败' }
|
||
}
|
||
|
||
function Ensure-MySQL {
|
||
$hasCmd = Test-Cmd 'mysql'
|
||
$svc = Get-Service -Name '*mysql*' -ErrorAction SilentlyContinue
|
||
if ($hasCmd -or $svc) {
|
||
Write-Ok "MySQL 已检测到(服务: $($svc.Name -join ', '))"
|
||
return
|
||
}
|
||
Write-Warn '未检测到 MySQL(FinDataHub 数据落地依赖)'
|
||
if ($IncludeMySQL) {
|
||
Install-WingetPkg 'Oracle.MySQL'
|
||
} else {
|
||
Write-Warn 'MySQL 静默安装无法可靠设置 root 密码,为避免留下无密码 root,默认不自动装。'
|
||
Write-Warn '请手动安装 MySQL 8.x 并设置 root 密码;或带 -IncludeMySQL 重试:'
|
||
Write-Warn ' powershell -ExecutionPolicy Bypass -File install-deps.ps1 -IncludeMySQL'
|
||
}
|
||
}
|
||
|
||
# ---------- VC++ 运行库(py_mini_racer 等原生扩展必需) ----------
|
||
function Ensure-VCRedist {
|
||
# 检测 VC++ 2015-2022 x64 运行时注册表键
|
||
$key = 'HKLM:\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64'
|
||
$installed = $false
|
||
if (Test-Path $key) {
|
||
$v = (Get-ItemProperty -Path $key -Name 'Installed' -ErrorAction SilentlyContinue).Installed
|
||
if ($v -eq 1) { $installed = $true }
|
||
}
|
||
if ($installed) { Write-Ok 'VC++ Redistributable (2015-2022 x64) 已存在'; return }
|
||
Install-WingetPkg 'Microsoft.VCRedist.2015+.x64'
|
||
}
|
||
|
||
# ---------- 汇总 ----------
|
||
function Show-Summary {
|
||
Write-Host "`n" ('=' * 60) -ForegroundColor Cyan
|
||
Write-Host ' FinDataHub 基础依赖检测结果' -ForegroundColor Cyan
|
||
Write-Host ('=' * 60) -ForegroundColor Cyan
|
||
$items = @(
|
||
@{ n = 'git' ; ok = (Test-Cmd 'git') },
|
||
@{ n = 'python' ; ok = (Test-Cmd 'python') },
|
||
@{ n = 'node' ; ok = (Test-Cmd 'node') },
|
||
@{ n = 'npm' ; ok = (Test-Cmd 'npm') },
|
||
@{ n = 'pnpm' ; ok = (Test-Cmd 'pnpm') },
|
||
@{ n = 'uv' ; ok = (Test-Cmd 'uv') },
|
||
@{ n = 'mysql' ; ok = (Test-Cmd 'mysql') }
|
||
)
|
||
foreach ($it in $items) {
|
||
$ver = ''
|
||
if ($it.ok) { $ver = (& $it.n --version 2>$null | Out-String).Trim() }
|
||
$mark = if ($it.ok) { '[OK]' } else { '[--]' }
|
||
$color = if ($it.ok) { 'Green' } else { 'Yellow' }
|
||
Write-Host (" {0} {1,-8} {2}" -f $mark, $it.n, $ver) -ForegroundColor $color
|
||
}
|
||
Write-Host ('=' * 60) -ForegroundColor Cyan
|
||
Write-Host ' 提示:若某软件 [--],请关闭本窗口重开后再单独确认。' -ForegroundColor DarkGray
|
||
Write-Host ' MySQL 若 [--],请按上文引导手动安装并设置 root 密码。' -ForegroundColor DarkGray
|
||
Write-Host ('=' * 60) -ForegroundColor Cyan
|
||
}
|
||
|
||
# ---------- 主流程 ----------
|
||
Write-Host '============================================================' -ForegroundColor Cyan
|
||
Write-Host ' FinDataHub Windows 端 · 基础依赖安装' -ForegroundColor Cyan
|
||
Write-Host ' 仅安装基础依赖,不安装 FinDataHub 本体' -ForegroundColor DarkGray
|
||
Write-Host '============================================================' -ForegroundColor Cyan
|
||
|
||
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||
if (-not $isAdmin) {
|
||
Write-Warn '当前非管理员权限,部分系统级软件(Node/Git/Python)可能安装失败。'
|
||
Write-Warn '建议关闭本窗口,改双击 install-deps.cmd 以自动提权。'
|
||
}
|
||
|
||
if (-not (Get-Winget)) {
|
||
Write-Err 'winget 不可用,请先安装 App Installer 后重试。'
|
||
return
|
||
}
|
||
|
||
Ensure-VCRedist
|
||
Ensure-Git
|
||
Ensure-Python312
|
||
Ensure-NodeLTS
|
||
Ensure-Uv
|
||
Ensure-Pnpm
|
||
Ensure-MySQL
|
||
|
||
Show-Summary
|
||
Write-Host "`n安装流程结束。" -ForegroundColor DarkGray
|