forked from RealKai42/qwerty-learner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-check.ps1
63 lines (59 loc) · 2.01 KB
/
pre-check.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 定义函数
function Test-CommandInstalled([string]$CommandName) {
$command = Get-Command $CommandName -ErrorAction SilentlyContinue
if ($command) {
return $true
}
else {
return $false
}
}
$location = Get-Location
# 检测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 {
winget install OpenJS.Nodejs --silent
Write-Host "nodejs 安装完成,版本为:"
node --version
}
}else{
Write-Host "检测到 nodejs 环境,版本为:"
node --version
}
# 检测Git命令是否存在
if (!(Test-CommandInstalled git)) {
Write-Host "未检测到 git 环境,尝试使用winget安装..."
# 检测winget是否存在
if (!(Test-CommandInstalled winget)) {
Write-Host "未检测到 winget,无法完成安装,请检测系统版本,或尝试安装 winget:https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab"
}
else {
winget install --id Git.Git -e --source winget
Write-Host "git 安装完成,版本为:"
git --version
}
}else{
Write-Host "检测到 git 环境,版本为:"
git --version
}
# 检测Yarn命令是否存在
if (!(Test-CommandInstalled yarn)) {
Write-Host "未检测到 yarn 环境,尝试使用winget安装..."
# 检测winget是否存在
if (!(Test-CommandInstalled npm)) {
Write-Host "未检测到 npm,请尝试手动下载 NodeJS (https://nodejs.org/en/download)"
}
else {
npm install --global yarn
Write-Host "yarn 安装完成,版本为:"
yarn --version
}
}else{
Write-Host "检测到 yarn 环境,版本为:"
yarn --version
}