mirror of
https://github.com/RealKai42/qwerty-learner.git
synced 2026-04-05 06:19:08 +08:00
添加windows下一键安装和运行脚本 (#607)
Co-authored-by: KaiyiWing <Zhang.kaiyi42@gmail.com>
This commit is contained in:
23
README.md
23
README.md
@@ -110,6 +110,29 @@ Gitee Pages: <https://kaiyiwing.gitee.io/qwerty-learner/>
|
||||
|
||||
[导入词典](./docs/toBuildDict.md)
|
||||
|
||||
## 运行项目
|
||||
|
||||
本项目是基于`React`开发的,需要 node 环境来运行。
|
||||
|
||||
### 手动安装
|
||||
|
||||
1. 安装 NodeJS,参考[官方文档](https://nodejs.org/en/download)
|
||||
2. 使用 `git clone` 下载项目到本地, 不使用 git 可能因为缺少依赖而无法运行
|
||||
3. 打开命令行,在项目根目录下,运行`yarn install`来下载依赖。
|
||||
4. 执行`yarn start`来启动项目,项目默认地址为`http://localhost:5173/`
|
||||
5. 在浏览器中打开`http://localhost:5173/`来访问项目。
|
||||
|
||||
### 脚本执行
|
||||
|
||||
对于 Windows 用户,可以直接执行 ps1 脚本,来一键安装依赖并启动项目。
|
||||
|
||||
1. 打开 powershell,定位到项目根目录中的`scripts`目录
|
||||
2. 在命令行中,执行`.\install.ps1`
|
||||
3. 等待脚本完成。
|
||||
|
||||
> 备注
|
||||
> 脚本依赖`winget`来安装 node,仅在 Windows 10 1709(版本 16299)或更高版本上受支持!
|
||||
|
||||
## 🏆 荣誉
|
||||
|
||||
- Github 全球趋势榜上榜项目
|
||||
|
||||
43
scripts/install.ps1
Normal file
43
scripts/install.ps1
Normal 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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user