enviroment-check.ps1 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Environment check script
  2. # 设置控制台编码为 UTF-8,避免乱码
  3. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  4. $OutputEncoding = [System.Text.Encoding]::UTF8
  5. chcp 65001 | Out-Null
  6. Write-Host "Checking development environment..." -ForegroundColor Cyan
  7. Write-Host "================================" -ForegroundColor Cyan
  8. # Check Node.js
  9. Write-Host "`nChecking Node.js..." -ForegroundColor Yellow
  10. $nodeVersion = node --version 2>$null
  11. if ($nodeVersion) {
  12. Write-Host "[OK] Node.js: $nodeVersion" -ForegroundColor Green
  13. } else {
  14. Write-Host "[X] Node.js is not installed" -ForegroundColor Red
  15. # Download nodejs
  16. Write-Host "Downloading Node.js..." -ForegroundColor Yellow
  17. npm install -g node
  18. if ($LASTEXITCODE -ne 0) {
  19. Write-Host "[X] Node.js download failed" -ForegroundColor Red
  20. exit 1
  21. }
  22. Write-Host "[OK] Node.js downloaded successfully" -ForegroundColor Green
  23. node --version
  24. }
  25. # Check npm
  26. Write-Host "`nChecking npm..." -ForegroundColor Yellow
  27. $npmVersion = npm --version 2>$null
  28. if ($npmVersion) {
  29. Write-Host "[OK] npm: $npmVersion" -ForegroundColor Green
  30. } else {
  31. Write-Host "[X] npm is not installed" -ForegroundColor Red
  32. # Download npm
  33. Write-Host "Downloading npm..." -ForegroundColor Yellow
  34. npm install -g npm
  35. if ($LASTEXITCODE -ne 0) {
  36. Write-Host "[X] npm download failed" -ForegroundColor Red
  37. exit 1
  38. }
  39. Write-Host "[OK] npm downloaded successfully" -ForegroundColor Green
  40. npm --version
  41. }
  42. # Check if dependencies are installed
  43. Write-Host "`nChecking project dependencies..." -ForegroundColor Yellow
  44. # 调用 nodejs-dependencies-install.js 脚本进行依赖检查和安装
  45. $nodeDependenciesScript = Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) "nodejs\dependences\nodejs-dependencies-install.js"
  46. if (Test-Path $nodeDependenciesScript) {
  47. node $nodeDependenciesScript
  48. if ($LASTEXITCODE -ne 0) {
  49. Write-Host "[X] Node dependencies check/installation failed" -ForegroundColor Red
  50. exit 1
  51. }
  52. } else {
  53. Write-Host "[X] nodejs-dependencies-install.js not found at: $nodeDependenciesScript" -ForegroundColor Red
  54. Write-Host "[WARN] Continuing without dependency check..." -ForegroundColor Yellow
  55. }
  56. # Check if python is installed
  57. Write-Host "`nChecking if python is installed..." -ForegroundColor Yellow
  58. $pythonVersion = python --version 2>$null
  59. if ($pythonVersion) {
  60. Write-Host "[OK] python: $pythonVersion" -ForegroundColor Green
  61. } else {
  62. Write-Host "[X] python is not installed" -ForegroundColor Red
  63. # Download python
  64. Write-Host "Downloading python..." -ForegroundColor Yellow
  65. npm install -g python
  66. if ($LASTEXITCODE -ne 0) {
  67. Write-Host "[X] python download failed" -ForegroundColor Red
  68. exit 1
  69. }
  70. Write-Host "[OK] python downloaded successfully" -ForegroundColor Green
  71. python --version
  72. }
  73. # check pip is installed
  74. Write-Host "`nChecking pip is installed..." -ForegroundColor Yellow
  75. $pipVersion = pip --version 2>$null
  76. if ($pipVersion) {
  77. Write-Host "[OK] pip: $pipVersion" -ForegroundColor Green
  78. } else {
  79. Write-Host "[X] pip is not installed" -ForegroundColor Red
  80. Write-Host "Installing pip..." -ForegroundColor Yellow
  81. pip install --upgrade pip
  82. if ($LASTEXITCODE -ne 0) {
  83. Write-Host "[X] pip installation failed" -ForegroundColor Red
  84. exit 1
  85. }
  86. Write-Host "[OK] pip installed successfully" -ForegroundColor Green
  87. pip --version
  88. }
  89. #check python virtual environment
  90. Write-Host "`nChecking python virtual environment..." -ForegroundColor Yellow
  91. $venvPath = "./python/env"
  92. if (Test-Path $venvPath) {
  93. Write-Host "[OK] python virtual environment exists at: $venvPath" -ForegroundColor Green
  94. } else {
  95. Write-Host "[X] python virtual environment is not installed" -ForegroundColor Yellow
  96. Write-Host "Creating python virtual environment..." -ForegroundColor Yellow
  97. python -m venv $venvPath
  98. if ($LASTEXITCODE -ne 0) {
  99. Write-Host "[X] python virtual environment creation failed" -ForegroundColor Red
  100. Write-Host "[WARN] Continuing without virtual environment..." -ForegroundColor Yellow
  101. } else {
  102. Write-Host "[OK] python virtual environment created successfully" -ForegroundColor Green
  103. }
  104. }
  105. # check python dependencies
  106. Write-Host "`nChecking python dependencies..." -ForegroundColor Yellow
  107. # 调用 python-enviroment-install.py 脚本进行依赖检查和安装(安装到虚拟环境)
  108. $pythonDependenciesScript = Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) "python\python-enviroment-install.py"
  109. if (Test-Path $pythonDependenciesScript) {
  110. python $pythonDependenciesScript
  111. if ($LASTEXITCODE -ne 0) {
  112. Write-Host "[X] Python dependencies check/installation failed" -ForegroundColor Red
  113. exit 1
  114. }
  115. } else {
  116. Write-Host "[X] python-enviroment-install.py not found at: $pythonDependenciesScript" -ForegroundColor Red
  117. Write-Host "[WARN] Continuing without Python dependency check..." -ForegroundColor Yellow
  118. }
  119. Write-Host "`n================================" -ForegroundColor Cyan
  120. Write-Host "Environment check completed!" -ForegroundColor Green
  121. Write-Host "All dependencies are ready. You can now start the project." -ForegroundColor Green