添加windows下一键安装和运行脚本 (#607)

Co-authored-by: KaiyiWing <Zhang.kaiyi42@gmail.com>
This commit is contained in:
Ater_NilTor
2023-09-03 15:04:36 +08:00
committed by GitHub
parent 6d3d395201
commit a4579ed3ac
2 changed files with 66 additions and 0 deletions

43
scripts/install.ps1 Normal file
View File

@@ -0,0 +1,43 @@
# 定义函数
function Test-CommandInstalled([string]$CommandName) {
$command = Get-Command $CommandName -ErrorAction SilentlyContinue
if ($command) {
return $true
}
else {
return $false
}
}
$location = Get-Location
$hasWinget = false;
# 检测Node命令是否存在
if (!(Test-CommandInstalled node)) {
Write-Host "未检测到nodejs环境尝试使用winget安装..."
# 检测winget是否存在
if (!(Test-CommandInstalled winget)) {
Write-Host "未检测到winget无法完成安装请检测系统版本或尝试安装winget:https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab"
}
else {
$hasWinget = true;
winget install OpenJS.Nodejs --slient
Write-Host "nodejs 安装完成"
}
}
if ($hasWinget) {
Set-Location ..
Write-Host "开始安装依赖..."
yarn install --registry=https://registry.npm.taobao.org
Write-Host "依赖安装完成,启动程序..."
Start-Job -ScriptBlock {
Start-Sleep 4
Start-Process http://localhost:5173/
} | Out-Null
npm run start
Set-Location $location
}