mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
chore: migrate package manager from npm to bun
This commit is contained in:
parent
cf65111e4e
commit
41ad1a036b
14 changed files with 1903 additions and 16113 deletions
|
|
@ -5,9 +5,9 @@
|
|||
```bash
|
||||
git clone https://github.com/ReCloudStudio/WebHooker.git
|
||||
cd WebHooker
|
||||
npm install
|
||||
bun install
|
||||
cp .env.example .dev.vars # 填入密钥
|
||||
npm run dev # 启动本地开发服务器
|
||||
bun run dev # 启动本地开发服务器
|
||||
```
|
||||
|
||||
## 项目结构
|
||||
|
|
@ -81,15 +81,15 @@ tests/ # 单元测试 (bun test)
|
|||
|
||||
| 命令 | 说明 |
|
||||
| ---------------------- | ----------------------------- |
|
||||
| `npm run dev` | 启动 Nuxt 开发服务器 (HMR) |
|
||||
| `npm run typecheck` | TypeScript 类型检查 |
|
||||
| `npm run lint` | ESLint (TypeScript) |
|
||||
| `npm run lint:md` | Markdownlint (Markdown) |
|
||||
| `npm test` | 运行单元测试 (bun test) |
|
||||
| `npm run format` | 使用 Prettier 格式化所有文件 |
|
||||
| `npm run format:check` | 检查 Prettier 格式 |
|
||||
| `npm run docs:dev` | 启动 VitePress 文档开发服务器 |
|
||||
| `npm run docs:build` | 构建文档站点 |
|
||||
| `bun run dev` | 启动 Nuxt 开发服务器 (HMR) |
|
||||
| `bun run typecheck` | TypeScript 类型检查 |
|
||||
| `bun run lint` | ESLint (TypeScript) |
|
||||
| `bun run lint:md` | Markdownlint (Markdown) |
|
||||
| `bun test` | 运行单元测试 (bun test) |
|
||||
| `bun run format` | 使用 Prettier 格式化所有文件 |
|
||||
| `bun run format:check` | 检查 Prettier 格式 |
|
||||
| `bun run docs:dev` | 启动 VitePress 文档开发服务器 |
|
||||
| `bun run docs:build` | 构建文档站点 |
|
||||
|
||||
## 代码风格
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ tests/ # 单元测试 (bun test)
|
|||
|
||||
```bash
|
||||
# 运行单元测试套件 (bun test)
|
||||
npm test
|
||||
bun test
|
||||
|
||||
# 或手动检查健康端点
|
||||
curl http://localhost:8787/health
|
||||
|
|
@ -127,5 +127,5 @@ curl http://localhost:8787/health
|
|||
|
||||
- 保持变更聚焦且原子化
|
||||
- 为所有函数返回值包含类型注解
|
||||
- 提交前运行 `npm run typecheck && npm run lint && npm run format:check`
|
||||
- 提交前运行 `bun run typecheck && bun run lint && bun run format:check`
|
||||
- 添加功能时更新文档(见 `AGENTS.md` → Documentation 的清单):README(`README.md` / `README.zh.md`)、VitePress 文档(`docs/` 与 `docs/zh/`)以及示例配置文件
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
### 1. 创建 KV 命名空间
|
||||
|
||||
```bash
|
||||
npx wrangler kv namespace create KV
|
||||
bunx wrangler kv namespace create KV
|
||||
```
|
||||
|
||||
这会输出一个命名空间 ID。更新 `wrangler.jsonc`,填入 ID:
|
||||
|
|
@ -24,13 +24,13 @@ npx wrangler kv namespace create KV
|
|||
### 2. 设置密钥
|
||||
|
||||
```bash
|
||||
npx wrangler secret put GITHUB_WEBHOOK_SECRET
|
||||
npx wrangler secret put GITHUB_CLIENT_ID
|
||||
npx wrangler secret put GITHUB_CLIENT_SECRET
|
||||
npx wrangler secret put DISCORD_TOKEN
|
||||
npx wrangler secret put DISCORD_PUBLIC_KEY # Discord 应用的公钥(开发者门户获取),交互功能必需
|
||||
npx wrangler secret put TELEGRAM_TOKEN # Telegram Bot Token(BotFather 获取)—— Telegram 路由必需
|
||||
npx wrangler secret put ADMIN_USER_IDS # 逗号分隔的 GitHub ID/登录名,允许进入 Web UI
|
||||
bunx wrangler secret put GITHUB_WEBHOOK_SECRET
|
||||
bunx wrangler secret put GITHUB_CLIENT_ID
|
||||
bunx wrangler secret put GITHUB_CLIENT_SECRET
|
||||
bunx wrangler secret put DISCORD_TOKEN
|
||||
bunx wrangler secret put DISCORD_PUBLIC_KEY # Discord 应用的公钥(开发者门户获取),交互功能必需
|
||||
bunx wrangler secret put TELEGRAM_TOKEN # Telegram Bot Token(BotFather 获取)—— Telegram 路由必需
|
||||
bunx wrangler secret put ADMIN_USER_IDS # 逗号分隔的 GitHub ID/登录名,允许进入 Web UI
|
||||
```
|
||||
|
||||
::: tip 目标频道按路由配置
|
||||
|
|
@ -47,7 +47,7 @@ Discord 交互通过 HTTPS Interactions Endpoint 送达,需要设置 `DISCORD_
|
|||
### 3. 创建 D1 数据库并执行迁移
|
||||
|
||||
```bash
|
||||
npx wrangler d1 create webhooker
|
||||
bunx wrangler d1 create webhooker
|
||||
```
|
||||
|
||||
将返回的数据库 ID 填入 `wrangler.jsonc`:
|
||||
|
|
@ -67,8 +67,8 @@ npx wrangler d1 create webhooker
|
|||
然后执行迁移:
|
||||
|
||||
```bash
|
||||
npm run db:migrate:prod # 将迁移应用到远端 D1 数据库
|
||||
npm run db:migrate # 将迁移应用到本地(Miniflare)数据库
|
||||
bun run db:migrate:prod # 将迁移应用到远端 D1 数据库
|
||||
bun run db:migrate # 将迁移应用到本地(Miniflare)数据库
|
||||
```
|
||||
|
||||
`db:migrate` 脚本执行 `wrangler d1 migrations apply webhooker`(见 `package.json`),逐一应用 `migrations/` 下的 SQL 文件,并在 `d1_migrations` 表中记录已应用的版本。
|
||||
|
|
@ -77,11 +77,11 @@ npm run db:migrate # 将迁移应用到本地(Miniflare)数据库
|
|||
如果数据库已有这些表/列(例如之前用 `wrangler d1 execute --file` 迁移过),可能缺少 `d1_migrations` 追踪表,`db:migrate:prod` 会尝试重新执行所有迁移;`0002_log_detail.sql` 中的 `ALTER TABLE ... ADD COLUMN` 语句会因列已存在而失败。此时请直接执行文件:
|
||||
|
||||
```bash
|
||||
npx wrangler d1 execute webhooker --remote --file ./migrations/0001_init.sql
|
||||
npx wrangler d1 execute webhooker --remote --file ./migrations/0002_log_detail.sql
|
||||
npx wrangler d1 execute webhooker --remote --file ./migrations/0003_telegram_links.sql
|
||||
npx wrangler d1 execute webhooker --remote --file ./migrations/0004_add_group_id.sql
|
||||
npx wrangler d1 execute webhooker --remote --file ./migrations/0005_audit_logs.sql
|
||||
bunx wrangler d1 execute webhooker --remote --file ./migrations/0001_init.sql
|
||||
bunx wrangler d1 execute webhooker --remote --file ./migrations/0002_log_detail.sql
|
||||
bunx wrangler d1 execute webhooker --remote --file ./migrations/0003_telegram_links.sql
|
||||
bunx wrangler d1 execute webhooker --remote --file ./migrations/0004_add_group_id.sql
|
||||
bunx wrangler d1 execute webhooker --remote --file ./migrations/0005_audit_logs.sql
|
||||
```
|
||||
|
||||
:::
|
||||
|
|
@ -89,7 +89,7 @@ npx wrangler d1 execute webhooker --remote --file ./migrations/0005_audit_logs.s
|
|||
### 4. 部署
|
||||
|
||||
```bash
|
||||
npx wrangler deploy
|
||||
bunx wrangler deploy
|
||||
```
|
||||
|
||||
Worker 现在可通过 `https://webhooker.<your-subdomain>.workers.dev` 访问。
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## 前置要求
|
||||
|
||||
- [Node.js](https://nodejs.org/) 18+
|
||||
- [Bun](https://bun.sh/) 1.x(唯一包管理器,不要使用 npm)
|
||||
- [Cloudflare 账号](https://dash.cloudflare.com/)(免费套餐即可)
|
||||
- [GitHub App](https://github.com/settings/apps/new)(参见 [GitHub App 设置](/zh/guide/deployment#github-app-设置))
|
||||
- Discord Bot Token(参见 [Discord Bot 设置](/zh/guide/deployment#discord-bot-设置))
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
```bash
|
||||
git clone https://github.com/ReCloudStudio/WebHooker.git
|
||||
cd WebHooker
|
||||
npm install
|
||||
bun install
|
||||
```
|
||||
|
||||
## 本地开发
|
||||
|
|
@ -48,7 +48,7 @@ BASE_URL=http://localhost:8787
|
|||
### 2. 启动开发服务器
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
bun run dev
|
||||
```
|
||||
|
||||
这将在 `http://localhost:8787` 启动本地 Miniflare 环境。
|
||||
|
|
@ -64,12 +64,12 @@ curl http://localhost:8787/health
|
|||
|
||||
| 脚本 | 说明 |
|
||||
| ---------------------- | ----------------------------- |
|
||||
| `npm run dev` | 启动本地开发服务器 (wrangler) |
|
||||
| `npm run deploy` | 部署到 Cloudflare |
|
||||
| `npm run typecheck` | TypeScript 类型检查 |
|
||||
| `npm run lint` | ESLint |
|
||||
| `npm run lint:md` | Markdownlint |
|
||||
| `npm run format` | 使用 Prettier 格式化 |
|
||||
| `npm run format:check` | 检查 Prettier 格式 |
|
||||
| `npm run docs:dev` | 启动文档开发服务器 |
|
||||
| `npm run docs:build` | 构建文档站点 |
|
||||
| `bun run dev` | 启动本地开发服务器 (wrangler) |
|
||||
| `bun run deploy` | 部署到 Cloudflare |
|
||||
| `bun run typecheck` | TypeScript 类型检查 |
|
||||
| `bun run lint` | ESLint |
|
||||
| `bun run lint:md` | Markdownlint |
|
||||
| `bun run format` | 使用 Prettier 格式化 |
|
||||
| `bun run format:check` | 检查 Prettier 格式 |
|
||||
| `bun run docs:dev` | 启动文档开发服务器 |
|
||||
| `bun run docs:build` | 构建文档站点 |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue