docs(readme): Enhance README and add environment check scripts

This commit is contained in:
KingYen.
2025-01-21 14:25:43 +08:00
parent 15bd9ed85a
commit 0c16dbeb6f
3 changed files with 142 additions and 5 deletions

View File

@@ -135,13 +135,40 @@ GitHub Pages: <https://realkai42.github.io/qwerty-learner/>
本项目是基于`React`开发的,需要 node 环境来运行。
### 环境准备
1. NodeJS
2. Git
3. Yarn
> **验证是否已经拥有相关环境**
>
> 1. 手动验证
> 请在命令行下执行以下命令,查看是否有对应版本输出
>
> ```sh
> node --version
> git --version
> yarn --version
> ```
>
> 2. 脚本验证
> 使用我们提供的脚本对所需环境进行验证,如果确实依赖项会自动安装
> - Windows 用户可以直接执行 [pre-check.ps1](scripts/pre-check.ps1) 脚本
> - MacOS 用户可以直接执行 [pre-check.sh](scripts/pre-check.sh) 脚本
如果有对应环境缺失,我们可以参考下列官方文档进行安装
> - [NodeJS](https://nodejs.org/en/download)
> - [Git](https://git-scm.com/downloads)
> - [yarn](https://classic.yarnpkg.com/lang/en/docs/install)
### 手动安装
1. 安装 NodeJS参考[官方文档](https://nodejs.org/en/download)
2. 使用 `git clone` 下载项目到本地, 不使用 git 可能因为缺少依赖而无法运行
3. 打开命令行,在项目根目录下,运`yarn install`来下载依赖。
4. 执行`yarn start`来启动项目,项目默认地址为`http://localhost:5173/`
5. 在浏览器中打开`http://localhost:5173/`来访问项目。
1. 在命令行中执行 `git clone https://github.com/RealKai42/qwerty-learner.git` 将项目拉取到本地, 如果不使用 git 可能因为缺少依赖而无法运行
2. 在命令行中执行 `cd qwerty-learner`,进入项目根目录,执行`yarn install`来下载依赖。
3. `yarn start`来启动项目,项目默认地址为`http://localhost:5173/`
4. 在浏览器中打开`http://localhost:5173/`来访问项目。
### 脚本执行

63
scripts/pre-check.ps1 Normal file
View File

@@ -0,0 +1,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
}

47
scripts/pre-check.sh Normal file
View File

@@ -0,0 +1,47 @@
cd "$(dirname "$0")" || exit
# 判断是否安装了 Node
if ! type node >/dev/null 2>&1; then
echo "未检测到 nodejs 环境尝试使用homebrew安装..."
# 检测homebrew是否存在
if ! type brew >/dev/null 2>&1; then
echo "未检测到 homebrew无法完成安装请安装 homebrew 后进行尝试 (https://brew.sh/)"
else
brew install node
echo "node 安装完成,版本为: "
node --version
fi
else
echo "检测到 NodeJS 环境,版本为:"
node -v
fi
if ! type git >/dev/null 2>&1; then
echo "未检测到 git 环境,尝试使用 homebrew 安装..."
# 检测 homebrew 是否存在
if ! type brew >/dev/null 2>&1; then
echo "未检测到 homebrew请手动安装 homebrew 后进行尝试 (https://brew.sh/)"
else
brew install git
echo "git 安装完成,版本为: "
git --version
fi
else
echo "检测到 git 环境,版本为:"
git --version
fi
if ! type yarn >/dev/null 2>&1; then
echo "未检测到 yarn 环境,尝试使用 homebrew 进行安装"
# 检测 homebrew 是否存在
if ! type brew >/dev/null 2>&1; then
echo "未检测到 homebrew ,请手动安装 homebrew 后进行尝试 (https://brew.sh/)"
else
brew install yarn
echo "yarn 安装完成,版本为: "
yarn --version
fi
else
echo "检测到 yarn 环境,版本为:"
yarn -v
fi