Skip to content

Commit 16a5df7

Browse files
committed
refactor: npm to yarn
1 parent 48e05aa commit 16a5df7

File tree

5 files changed

+32
-7452
lines changed

5 files changed

+32
-7452
lines changed

.github/workflows/deploy-pages.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ jobs:
2929
uses: actions/setup-node@v4
3030
with:
3131
node-version: '20'
32-
cache: 'npm'
32+
cache: 'yarn'
3333

3434
- name: Install dependencies
35-
run: npm ci
35+
run: yarn install --frozen-lockfile
3636

3737
- name: Build for GitHub Pages
38-
run: npm run build:pages
38+
run: yarn build:pages
3939

4040
- name: Setup Pages
4141
# 使用官方 Action 配置 GitHub Pages
@@ -58,4 +58,4 @@ jobs:
5858
steps:
5959
- name: Deploy to GitHub Pages
6060
id: deployment
61-
uses: actions/deploy-pages@v4
61+
uses: actions/deploy-pages@v4

docs/05-build-and-deploy.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
所有构建相关的命令都定义在 `package.json``scripts` 部分。
88

9-
- **`npm run dev`**: 启动开发服务器,用于日常开发。
10-
- **`npm run build`**: 创建一个标准的生产版本,输出到 `dist/` 目录。
11-
- **`npm run build:itch`**: 为 **itch.io** 平台构建、打包,并自动管理版本号。
12-
- **`npm run build:pages`**: 为 **GitHub Pages** 构建一个生产版本。
13-
- **`npm run deploy`**: 构建并部署到 **GitHub Pages**
9+
- **`yarn dev`**: 启动开发服务器,用于日常开发。
10+
- **`yarn build`**: 创建一个标准的生产版本,输出到 `dist/` 目录。
11+
- **`yarn build:itch`**: 为 **itch.io** 平台构建、打包,并自动管理版本号。
12+
- **`yarn build:pages`**: 为 **GitHub Pages** 构建一个生产版本。
13+
- **`yarn deploy`**: 构建并部署到 **GitHub Pages**
1414

1515
---
1616

@@ -21,7 +21,7 @@
2121
执行以下命令:
2222

2323
```bash
24-
npm run build:itch
24+
yarn build:itch
2525
```
2626

2727
该命令会自动执行以下操作:
@@ -57,7 +57,7 @@ npm run build:itch
5757
配置好 `name` 字段后,只需运行:
5858

5959
```bash
60-
npm run deploy
60+
yarn deploy
6161
```
6262

6363
该命令会:
@@ -71,7 +71,7 @@ npm run deploy
7171
如果您想在本地测试生产构建的效果,可以运行:
7272

7373
```bash
74-
npm run preview
74+
yarn preview
7575
```
7676

7777
此命令会在本地启动一个静态文件服务器,预览 `dist` 目录的内容。
@@ -109,4 +109,4 @@ npm run preview
109109
2. 将您的代码推送到 `main` 分支。
110110
3. 稍等片刻,GitHub Actions 完成后,您的游戏就会在 GitHub Pages 网址上生效。
111111

112-
这个自动化流程取代了原有的 `npm run deploy` 手动部署方式,让部署过程更可靠、更高效。
112+
这个自动化流程取代了原有的 `yarn deploy` 手动部署方式,让部署过程更可靠、更高效。

docs/06-contributing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
1. Fork 本仓库,并从 `main` 分支创建您的开发分支。
2424
2. 在您的分支上进行修改。
25-
3. 确保您的代码通过了 lint 检查 (`npm run lint`)。
25+
3. 确保您的代码通过了 lint 检查 (`yarn lint`)。
2626
4. 如果适用,为您的改动添加或更新测试。
27-
5. 确保所有测试都已通过 (`npm run test`)。
27+
5. 确保所有测试都已通过 (`yarn test`)。
2828
6. 如果您更改了行为或添加了新功能,请务必更新 `docs/` 目录下的相关文档。
2929
7. 向主仓库的 `main` 分支提交 Pull Request。
3030

@@ -36,4 +36,4 @@
3636

3737
## 代码风格
3838

39-
请遵循项目现有的代码风格。本项目使用 ESLint 和 Prettier 来保持代码风格的一致性。建议您在提交代码前先格式化代码。
39+
请遵循项目现有的代码风格。本项目使用 ESLint 和 Prettier 来保持代码风格的一致性。建议您在提交代码前先格式化代码。

docs/07-optional-backend-integration.md

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
3. **安装契约包**:
3030
安装后端发布的类型包:
3131
```bash
32-
npm install @tobenot/basic-web-game-backend-contract@latest
32+
yarn add @tobenot/basic-web-game-backend-contract@latest
3333
```
3434

3535
4. **在代码中使用类型**:
@@ -56,35 +56,29 @@
5656

5757
#### **1.2 配置`.npmrc`**
5858

59-
在您的前端项目根目录下(与`package.json`同级)创建一个名为 `.npmrc` 的文件。这个文件会告诉npm去哪里寻找 `@<您的GitHub用户名>` 作用域下的包。
59+
在您的前端项目根目录下(与`package.json`同级)创建一个名为 `.npmrc` 的文件。这个文件会告诉Yarn去哪里寻找 `@<您的GitHub用户名>` 作用域下的包,并提供认证
6060

6161
文件内容如下:
62-
```
62+
```ini
6363
@<您的GitHub用户名>:registry=https://npm.pkg.github.com/
64+
//npm.pkg.github.com/:_authToken=您的PAT令牌
6465
```
66+
`您的PAT令牌` 替换为您在 **步骤 1.1** 中创建的 GitHub Personal Access Token (PAT)。
6567

66-
#### **1.3 登录到GitHub Packages**
67-
68-
打开您的终端,运行以下命令以登录到 GitHub Packages。这将把您的凭证保存在本地,以便将来 `npm install` 时使用。
69-
70-
```bash
71-
npm login --scope=@<您的GitHub用户名> --registry=https://npm.pkg.github.com
72-
```
73-
74-
当提示时,请输入:
75-
* **Username**: 您的GitHub用户名。
76-
* **Password**: 您刚刚创建的 **Personal Access Token (PAT)** (注意,不是您的GitHub密码)。
77-
* **Email**: 您的GitHub账户关联的邮箱。
68+
> **重要提示**: 包含令牌的 `.npmrc` 文件非常敏感。请务必将其添加到 `.gitignore` 文件中,以防止被提交到版本控制中。
69+
> ```bash
70+
> echo ".npmrc" >> .gitignore
71+
> ```
7872
79-
#### **1.4 安装契约包**
73+
#### **1.3 安装契约包**
8074
81-
一切准备就绪后,像安装任何其他npm包一样安装后端的类型契约包
75+
一切准备就绪后,使用 `yarn` 安装后端的类型契约包
8276
```bash
83-
npm install @<您的GitHub用户名>/basic-web-game-backend-contract@latest
77+
yarn add @<您的GitHub用户名>/basic-web-game-backend-contract@latest
8478
```
8579
`@latest` 标签可以确保您总是获取最新版本的类型定义。
8680

87-
#### **1.5 在代码中使用类型**
81+
#### **1.4 在代码中使用类型**
8882

8983
现在,您可以在项目的任何地方导入和使用后端定义的类型,享受完整的IDE自动补全和类型检查。
9084

@@ -144,7 +138,7 @@ export const trpc = createTRPCProxyClient<AppRouter>({
144138
```
145139

146140
#### **2.3 创建GitHub Actions工作流**
147-
后端仓库中会有一个GitHub Actions工作流 (`.github/workflows/publish-contract.yml`),用于在代码推送到 `main` 分支时自动构建和发布npm包
141+
后端仓库中会有一个GitHub Actions工作流 (`.github/workflows/publish-contract.yml`),用于在代码推送到 `main` 分支时自动构建和发布包
148142

149143
```yaml
150144
# Backend's .github/workflows/publish-contract.yml
@@ -167,10 +161,10 @@ jobs:
167161
node-version: '18'
168162
registry-url: 'https://npm.pkg.github.com'
169163
scope: '@<您的GitHub用户名>'
170-
- run: npm ci && npm run build
164+
- run: yarn install --frozen-lockfile && yarn build
171165
env:
172166
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
173-
- run: npm publish
167+
- run: yarn publish
174168
env:
175169
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176170
```

0 commit comments

Comments
 (0)