@hono-filebased-route/core 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @hono-filebased-route/core
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - BREAKING CHANGE: route config keys changed from `configGET`/`configPOST` to `config = { GET: {}, ... }`.
package/README.md CHANGED
@@ -1,183 +1,183 @@
1
- # Hono File-Based Routing Core
2
-
3
- 一个基于 Hono 框架的文件路由系统,使用 Turborepo 管理的 monorepo 项目,支持类似 Next.js 的文件路由模式。
4
-
5
- ## 特性
6
-
7
- - 🚀 **文件路由系统**: 基于文件结构自动生成路由
8
- - ⚡ **Bun 运行时**: 快速的 JavaScript 运行时
9
- - 🔥 **热重载**: 开发时自动重新加载
10
- - 📁 **动态路由**: 支持动态参数和通配符路由
11
- - 🎯 **类型安全**: 完整的 TypeScript 支持
12
- - 🛠️ **自动生成**: 路由配置自动生成,无需手动维护
13
- - 📦 **Monorepo**: 使用 Turborepo 管理多包项目
14
- - ⚡ **构建缓存**: 智能缓存和并行构建优化
15
-
16
- ## 路由规则
17
-
18
- ### 基本路由实例
19
-
20
- | 文件路径 | 路由路径 | 说明 |
21
- | ---------------------------------- | ------------- | ------------ |
22
- | `src/routes/index.ts` | `/` | 根路由 |
23
- | `src/routes/about.ts` | `/about` | 静态路由 |
24
- | `src/routes/users/index.ts` | `/users` | 嵌套路由 |
25
- | `src/routes/users/[id].ts` | `/users/:id` | 动态参数路由 |
26
- | `src/routes/articles/[...slug].ts` | `/articles/*` | 通配符路由 |
27
-
28
- ## 安装
29
-
30
- 安装项目依赖:
31
-
32
- ```bash
33
- npm install
34
- # or
35
- yarn add
36
- # or
37
- pnpm add
38
- # or
39
- bun add
40
- ```
41
-
42
- ## 使用方法
43
-
44
- ### Turborepo 命令
45
-
46
- 本项目使用 Turborepo 进行 monorepo 管理,支持以下命令:
47
-
48
- ```bash
49
- # 构建所有包
50
- bun run build
51
-
52
- # 启动所有开发服务
53
- bun run dev
54
-
55
- # 运行所有测试
56
- bun run test
57
-
58
- # 类型检查
59
- bun run type-check
60
-
61
- # 清理构建产物
62
- bun run clean
63
- ```
64
-
65
- ### 开发模式
66
-
67
- ```bash
68
- # 使用 Turborepo 启动开发服务器
69
- bun run dev
70
-
71
- # 或者直接启动示例项目
72
- cd examples/bun
73
- bun run dev
74
- ```
75
-
76
- 这将启动开发服务器,支持热重载,访问 <http://localhost:3000>
77
-
78
- ### 生产模式
79
-
80
- ```bash
81
- # 先构建所有包
82
- bun run build
83
-
84
- # 启动示例应用
85
- cd examples/bun
86
- bun run start
87
- ```
88
-
89
- ### 手动生成路由
90
-
91
- ```bash
92
- bun run generate-routes
93
- ```
94
-
95
- ## 创建路由
96
-
97
- 在 `src/routes` 目录下创建 TypeScript 文件,导出 HTTP 方法处理函数:
98
-
99
- ```typescript
100
- import { Context } from 'hono'
101
-
102
- // GET 请求处理
103
- export function GET(c: Context) {
104
- return c.json({ message: 'Hello from GET' })
105
- }
106
-
107
- // POST 请求处理
108
- export function POST(c: Context) {
109
- return c.json({ message: 'Hello from POST' })
110
- }
111
- ```
112
-
113
- ### 动态路由
114
-
115
- 使用方括号创建动态路由:
116
-
117
- ```typescript
118
- import { Context } from 'hono'
119
-
120
- export function GET(c: Context) {
121
- const id = c.req.param('id')
122
- return c.json({ userId: id })
123
- }
124
- ```
125
-
126
- ### 通配符路由
127
-
128
- 使用 `[...slug]` 创建通配符路由:
129
-
130
- 该项目通过 `c.req.path` 填充 `slug` 参数,自动为 `GET/POST` 函数提供第二个参数。
131
-
132
- ```typescript
133
- import { Context } from 'hono'
134
-
135
- export function GET(c: Context, slug: string[]) {
136
- return c.json({ slug })
137
- }
138
- ```
139
-
140
- ## 工作原理
141
-
142
- 1. **路由扫描**: `scripts/generate-routes.ts` 扫描 `src/routes` 目录
143
- 2. **路径转换**: 将文件路径转换为 Hono 路由路径
144
- 3. **代码生成**: 生成 `src/generated-routes.ts` 文件
145
- 4. **自动注册**: 主应用自动注册所有生成的路由
146
-
147
- ## 开发脚本
148
-
149
- ### 根目录脚本(Turborepo)
150
-
151
- - `bun run build`: 构建所有包(支持缓存和并行构建)
152
- - `bun run dev`: 启动所有开发服务
153
- - `bun run test`: 运行所有测试
154
- - `bun run lint`: 代码检查
155
- - `bun run type-check`: TypeScript 类型检查
156
- - `bun run clean`: 清理所有构建产物
157
- - `bun run test:basic`: 快速启动基础示例
158
-
159
- ### 包级别脚本
160
-
161
- - `bun run build`: 构建当前包
162
- - `bun run dev`: 开发模式(包含热重载)
163
- - `bun run clean`: 清理构建产物
164
- - `bun run generate-routes`: 生成路由配置(仅示例项目)
165
-
166
- ## 技术栈
167
-
168
- - **[Hono](https://hono.dev/)**: 轻量级 Web 框架
169
- - **[bun](https://bun.sh/)**: 快速的 JavaScript 运行时
170
- - **[Turborepo](https://turbo.build/)**: 高性能 monorepo 构建系统
171
- - **TypeScript**: 类型安全的 JavaScript
172
-
173
- ## 许可证
174
-
175
- MIT License
176
-
177
- ## 贡献
178
-
179
- 欢迎提交 Issue 和 Pull Request!
180
-
181
- ---
182
-
183
- **注意**: `src/generated-routes.ts` 文件是自动生成的,请不要手动编辑。如需修改路由,请直接修改 `src/routes` 目录下的文件。
1
+ # Hono File-Based Routing Core
2
+
3
+ 一个基于 Hono 框架的文件路由系统,使用 Turborepo 管理的 monorepo 项目,支持类似 Next.js 的文件路由模式。
4
+
5
+ ## 特性
6
+
7
+ - 🚀 **文件路由系统**: 基于文件结构自动生成路由
8
+ - ⚡ **Bun 运行时**: 快速的 JavaScript 运行时
9
+ - 🔥 **热重载**: 开发时自动重新加载
10
+ - 📁 **动态路由**: 支持动态参数和通配符路由
11
+ - 🎯 **类型安全**: 完整的 TypeScript 支持
12
+ - 🛠️ **自动生成**: 路由配置自动生成,无需手动维护
13
+ - 📦 **Monorepo**: 使用 Turborepo 管理多包项目
14
+ - ⚡ **构建缓存**: 智能缓存和并行构建优化
15
+
16
+ ## 路由规则
17
+
18
+ ### 基本路由实例
19
+
20
+ | 文件路径 | 路由路径 | 说明 |
21
+ | ---------------------------------- | ------------- | ------------ |
22
+ | `src/routes/index.ts` | `/` | 根路由 |
23
+ | `src/routes/about.ts` | `/about` | 静态路由 |
24
+ | `src/routes/users/index.ts` | `/users` | 嵌套路由 |
25
+ | `src/routes/users/[id].ts` | `/users/:id` | 动态参数路由 |
26
+ | `src/routes/articles/[...slug].ts` | `/articles/*` | 通配符路由 |
27
+
28
+ ## 安装
29
+
30
+ 安装项目依赖:
31
+
32
+ ```bash
33
+ npm install
34
+ # or
35
+ yarn add
36
+ # or
37
+ pnpm add
38
+ # or
39
+ bun add
40
+ ```
41
+
42
+ ## 使用方法
43
+
44
+ ### Turborepo 命令
45
+
46
+ 本项目使用 Turborepo 进行 monorepo 管理,支持以下命令:
47
+
48
+ ```bash
49
+ # 构建所有包
50
+ bun run build
51
+
52
+ # 启动所有开发服务
53
+ bun run dev
54
+
55
+ # 运行所有测试
56
+ bun run test
57
+
58
+ # 类型检查
59
+ bun run type-check
60
+
61
+ # 清理构建产物
62
+ bun run clean
63
+ ```
64
+
65
+ ### 开发模式
66
+
67
+ ```bash
68
+ # 使用 Turborepo 启动开发服务器
69
+ bun run dev
70
+
71
+ # 或者直接启动示例项目
72
+ cd examples/bun
73
+ bun run dev
74
+ ```
75
+
76
+ 这将启动开发服务器,支持热重载,访问 <http://localhost:3000>
77
+
78
+ ### 生产模式
79
+
80
+ ```bash
81
+ # 先构建所有包
82
+ bun run build
83
+
84
+ # 启动示例应用
85
+ cd examples/bun
86
+ bun run start
87
+ ```
88
+
89
+ ### 手动生成路由
90
+
91
+ ```bash
92
+ bun run generate-routes
93
+ ```
94
+
95
+ ## 创建路由
96
+
97
+ 在 `src/routes` 目录下创建 TypeScript 文件,导出 HTTP 方法处理函数:
98
+
99
+ ```typescript
100
+ import { Context } from 'hono'
101
+
102
+ // GET 请求处理
103
+ export function GET(c: Context) {
104
+ return c.json({ message: 'Hello from GET' })
105
+ }
106
+
107
+ // POST 请求处理
108
+ export function POST(c: Context) {
109
+ return c.json({ message: 'Hello from POST' })
110
+ }
111
+ ```
112
+
113
+ ### 动态路由
114
+
115
+ 使用方括号创建动态路由:
116
+
117
+ ```typescript
118
+ import { Context } from 'hono'
119
+
120
+ export function GET(c: Context) {
121
+ const id = c.req.param('id')
122
+ return c.json({ userId: id })
123
+ }
124
+ ```
125
+
126
+ ### 通配符路由
127
+
128
+ 使用 `[...slug]` 创建通配符路由:
129
+
130
+ 该项目通过 `c.req.path` 填充 `slug` 参数,自动为 `GET/POST` 函数提供第二个参数。
131
+
132
+ ```typescript
133
+ import { Context } from 'hono'
134
+
135
+ export function GET(c: Context, slug: string[]) {
136
+ return c.json({ slug })
137
+ }
138
+ ```
139
+
140
+ ## 工作原理
141
+
142
+ 1. **路由扫描**: `scripts/generate-routes.ts` 扫描 `src/routes` 目录
143
+ 2. **路径转换**: 将文件路径转换为 Hono 路由路径
144
+ 3. **代码生成**: 生成 `src/generated-routes.ts` 文件
145
+ 4. **自动注册**: 主应用自动注册所有生成的路由
146
+
147
+ ## 开发脚本
148
+
149
+ ### 根目录脚本(Turborepo)
150
+
151
+ - `bun run build`: 构建所有包(支持缓存和并行构建)
152
+ - `bun run dev`: 启动所有开发服务
153
+ - `bun run test`: 运行所有测试
154
+ - `bun run lint`: 代码检查
155
+ - `bun run type-check`: TypeScript 类型检查
156
+ - `bun run clean`: 清理所有构建产物
157
+ - `bun run test:basic`: 快速启动基础示例
158
+
159
+ ### 包级别脚本
160
+
161
+ - `bun run build`: 构建当前包
162
+ - `bun run dev`: 开发模式(包含热重载)
163
+ - `bun run clean`: 清理构建产物
164
+ - `bun run generate-routes`: 生成路由配置(仅示例项目)
165
+
166
+ ## 技术栈
167
+
168
+ - **[Hono](https://hono.dev/)**: 轻量级 Web 框架
169
+ - **[bun](https://bun.sh/)**: 快速的 JavaScript 运行时
170
+ - **[Turborepo](https://turbo.build/)**: 高性能 monorepo 构建系统
171
+ - **TypeScript**: 类型安全的 JavaScript
172
+
173
+ ## 许可证
174
+
175
+ MIT License
176
+
177
+ ## 贡献
178
+
179
+ 欢迎提交 Issue 和 Pull Request!
180
+
181
+ ---
182
+
183
+ **注意**: `src/generated-routes.ts` 文件是自动生成的,请不要手动编辑。如需修改路由,请直接修改 `src/routes` 目录下的文件。
package/build.ts CHANGED
@@ -1,10 +1,8 @@
1
- import dts from 'bun-plugin-dts'
2
-
3
- await Bun.build({
4
- minify: true,
5
- target: 'node',
6
- outdir: './dist',
7
- plugins: [dts()],
8
- entrypoints: ['./index.ts'],
9
- external: ['typescript'],
10
- })
1
+ import { buildPackage } from '../../build'
2
+
3
+ await buildPackage({
4
+ name: '@hono-filebased-route/core',
5
+ entry: './index.ts',
6
+ outDir: './dist',
7
+ external: ['typescript', 'pino', 'pino-pretty'],
8
+ })
package/dist/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
- // Generated by dts-bundle-generator v9.5.1
2
-
3
1
  import pino from 'pino';
4
2
 
5
3
  declare const METHODS: readonly [
6
4
  "GET",
7
- "POST"
5
+ "POST",
6
+ "PUT",
7
+ "DELETE",
8
+ "PATCH",
9
+ "HEAD",
10
+ "OPTIONS"
8
11
  ];
9
12
  export type Method = (typeof METHODS)[number];
10
13
  export type ExportedMethods = {