chore: migrate package manager from npm to bun

This commit is contained in:
RhenCloud 2026-08-13 20:34:52 +08:00
parent cf65111e4e
commit 41ad1a036b
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
14 changed files with 1903 additions and 16113 deletions

View file

@ -5,9 +5,9 @@
```bash
git clone https://github.com/ReCloudStudio/WebHooker.git
cd WebHooker
npm install
bun install
cp .env.example .dev.vars # Fill in secrets
npm run dev # Start local dev server
bun run dev # Start local dev server
```
## Project Structure
@ -81,15 +81,15 @@ tests/ # Unit tests (bun test)
| Command | Description |
| ---------------------- | ------------------------------- |
| `npm run dev` | Start Nuxt dev server (HMR) |
| `npm run typecheck` | TypeScript type checking |
| `npm run lint` | ESLint (TypeScript) |
| `npm run lint:md` | Markdownlint (Markdown) |
| `npm test` | Run unit tests (bun test) |
| `npm run format` | Format all files with Prettier |
| `npm run format:check` | Check Prettier formatting |
| `npm run docs:dev` | Start VitePress docs dev server |
| `npm run docs:build` | Build docs site |
| `bun run dev` | Start Nuxt dev server (HMR) |
| `bun run typecheck` | TypeScript type checking |
| `bun run lint` | ESLint (TypeScript) |
| `bun run lint:md` | Markdownlint (Markdown) |
| `bun test` | Run unit tests (bun test) |
| `bun run format` | Format all files with Prettier |
| `bun run format:check` | Check Prettier formatting |
| `bun run docs:dev` | Start VitePress docs dev server |
| `bun run docs:build` | Build docs site |
## Code Style
@ -106,7 +106,7 @@ tests/ # Unit tests (bun test)
```bash
# Run the unit test suite (bun test)
npm test
bun test
# Or manually check the health endpoint
curl http://localhost:8787/health
@ -127,5 +127,5 @@ curl http://localhost:8787/health
- Keep changes focused and atomic
- Include type annotations for all function returns
- Run `npm run typecheck && npm run lint && npm run format:check` before submitting
- Run `bun run typecheck && bun run lint && bun run format:check` before submitting
- Update documentation if adding features (see the checklist in `AGENTS.md` → Documentation): README (`README.md` / `README.zh.md`), VitePress docs (`docs/` and `docs/zh/`), and example config files

View file

@ -5,7 +5,7 @@
### 1. Create KV Namespace
```bash
npx wrangler kv namespace create KV
bunx wrangler kv namespace create KV
```
This outputs a namespace ID. Update `wrangler.jsonc` with the ID:
@ -24,13 +24,13 @@ This outputs a namespace ID. Update `wrangler.jsonc` with the ID:
### 2. Set Secrets
```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 app public key (Developer Portal) — required for interactions
npx wrangler secret put TELEGRAM_TOKEN # Telegram bot token (BotFather) — required for Telegram routes
npx wrangler secret put ADMIN_USER_IDS # comma-separated GitHub IDs/logins allowed into the 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 app public key (Developer Portal) — required for interactions
bunx wrangler secret put TELEGRAM_TOKEN # Telegram bot token (BotFather) — required for Telegram routes
bunx wrangler secret put ADMIN_USER_IDS # comma-separated GitHub IDs/logins allowed into the Web UI
```
::: tip Target channels are configured per route
@ -48,7 +48,7 @@ Discord interactions arrive via the HTTPS Interactions Endpoint, so set `DISCORD
### 3. Create D1 Database and Run Migrations
```bash
npx wrangler d1 create webhooker
bunx wrangler d1 create webhooker
```
Copy the returned database ID into `wrangler.jsonc`:
@ -68,8 +68,8 @@ Copy the returned database ID into `wrangler.jsonc`:
Then apply the migrations:
```bash
npm run db:migrate:prod # apply migrations to the remote D1 database
npm run db:migrate # apply migrations to the local (Miniflare) database
bun run db:migrate:prod # apply migrations to the remote D1 database
bun run db:migrate # apply migrations to the local (Miniflare) database
```
The `db:migrate` scripts run `wrangler d1 migrations apply webhooker` (see `package.json`), which applies each SQL file in `migrations/` and records applied versions in the `d1_migrations` table.
@ -78,11 +78,11 @@ The `db:migrate` scripts run `wrangler d1 migrations apply webhooker` (see `pack
If the database already has these tables/columns (e.g. previously migrated with `wrangler d1 execute --file`), the `d1_migrations` tracking table may be missing and `db:migrate:prod` will try to re-run every migration. The `ALTER TABLE ... ADD COLUMN` statements in `0002_log_detail.sql` then fail because the columns already exist. In that case run the files directly instead:
```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
```
:::
@ -90,7 +90,7 @@ npx wrangler d1 execute webhooker --remote --file ./migrations/0005_audit_logs.s
### 4. Deploy
```bash
npx wrangler deploy
bunx wrangler deploy
```
Your worker is now live at `https://webhooker.<your-subdomain>.workers.dev`.

View file

@ -2,7 +2,7 @@
## Prerequisites
- [Node.js](https://nodejs.org/) 18+
- [Bun](https://bun.sh/) 1.x (the only package manager; never use npm)
- A [Cloudflare account](https://dash.cloudflare.com/) (free tier works)
- A [GitHub App](https://github.com/settings/apps/new) (see [GitHub App Setup](/guide/deployment#github-app-setup))
- A Discord bot token (see [Discord Bot Setup](/guide/deployment#discord-bot-setup))
@ -12,7 +12,7 @@
```bash
git clone https://github.com/ReCloudStudio/WebHooker.git
cd WebHooker
npm install
bun install
```
## Local Development
@ -48,7 +48,7 @@ BASE_URL=http://localhost:8787
### 2. Start Dev Server
```bash
npm run dev
bun run dev
```
This starts a local Miniflare environment at `http://localhost:8787`.
@ -62,14 +62,16 @@ curl http://localhost:8787/health
## Available Scripts
| Script | Description |
| ---------------------- | --------------------------------- |
| `npm run dev` | Start local dev server (wrangler) |
| `npm run deploy` | Deploy to Cloudflare |
| `npm run typecheck` | TypeScript type checking |
| `npm run lint` | ESLint |
| `npm run lint:md` | Markdownlint |
| `npm run format` | Format with Prettier |
| `npm run format:check` | Check Prettier formatting |
| `npm run docs:dev` | Start docs dev server |
| `npm run docs:build` | Build docs site |
| Script | Description |
|------------------------|---------------------------------------------|
| `bun run dev` | Start Nuxt dev server (HMR) |
| `bun run build` | Production build (cloudflare_module preset) |
| `bun run deploy` | Deploy to Cloudflare |
| `bun run typecheck` | TypeScript type checking |
| `bun run lint` | ESLint |
| `bun run lint:md` | Markdownlint |
| `bun run format` | Format with Prettier |
| `bun run format:check` | Check Prettier formatting |
| `bun test` | Unit tests |
| `bun run docs:dev` | Start docs dev server |
| `bun run docs:build` | Build docs site |

View file

@ -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/`)以及示例配置文件

View file

@ -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 TokenBotFather 获取)—— 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 TokenBotFather 获取)—— 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` 访问。

View file

@ -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` | 构建文档站点 |