@hono-filebased-route/runtime 0.1.0 → 0.4.1
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/dist/index.js +554 -7
- package/index.ts +38 -40
- package/package.json +45 -45
- package/tsconfig.json +15 -15
package/index.ts
CHANGED
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
import { getFiles, getRoutePath } from '@hono-filebased-route/core'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import { pathToFileURL } from 'url'
|
|
4
|
-
import { Hono } from 'hono'
|
|
5
|
-
|
|
6
|
-
const ROUTES_DIR = './src/routes'
|
|
7
|
-
|
|
8
|
-
export async function registerRoutes(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return mainApp
|
|
40
|
-
}
|
|
1
|
+
import { getFiles, getRoutePath } from '@hono-filebased-route/core'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { pathToFileURL } from 'url'
|
|
4
|
+
import { Hono } from 'hono'
|
|
5
|
+
|
|
6
|
+
const ROUTES_DIR = './src/routes'
|
|
7
|
+
|
|
8
|
+
export async function registerRoutes(mainApp: Hono, dir: string = ROUTES_DIR) {
|
|
9
|
+
const absoluteRoutesDir = path.resolve(dir)
|
|
10
|
+
const files = await getFiles(absoluteRoutesDir)
|
|
11
|
+
const methods = ['GET', 'POST'] as const
|
|
12
|
+
type Method = 'get' | 'post'
|
|
13
|
+
|
|
14
|
+
for (const file of files) {
|
|
15
|
+
const routePath = getRoutePath(file, absoluteRoutesDir)
|
|
16
|
+
.replace(/\\/g, '/')
|
|
17
|
+
.replace(/\/index$/, '')
|
|
18
|
+
|
|
19
|
+
const fileUrl = pathToFileURL(file).href
|
|
20
|
+
const module = await import(fileUrl)
|
|
21
|
+
const tempHono = new Hono()
|
|
22
|
+
|
|
23
|
+
for (const method of methods) {
|
|
24
|
+
if (typeof module[method] === 'function') {
|
|
25
|
+
if (routePath.endsWith('/*')) {
|
|
26
|
+
const len = routePath.replace(/\/\*$/g, '').length + 1
|
|
27
|
+
tempHono[method.toLowerCase() as Method]('/', async c =>
|
|
28
|
+
module[method](c, c.req.path.substring(len).split('/'))
|
|
29
|
+
)
|
|
30
|
+
} else tempHono[method.toLowerCase() as Method]('/', async c => module[method](c))
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
mainApp.route(routePath, tempHono)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return mainApp
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hono-filebased-route/runtime",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "A core utility for file-based routing in Hono applications.",
|
|
6
|
-
"author": "HM Suiji <hmsuiji@gmail.com>",
|
|
7
|
-
"keywords": [
|
|
8
|
-
"hono",
|
|
9
|
-
"router",
|
|
10
|
-
"file-based",
|
|
11
|
-
"routing",
|
|
12
|
-
"backend",
|
|
13
|
-
"framework",
|
|
14
|
-
"typescript",
|
|
15
|
-
"file-based-route"
|
|
16
|
-
],
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "https://github.com/HM-Suiji/hono-filebased-route.git"
|
|
21
|
-
},
|
|
22
|
-
"main": "dist/index.js",
|
|
23
|
-
"types": "dist/index.d.ts",
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "bun run build.ts",
|
|
26
|
-
"clean": "rm -rf dist"
|
|
27
|
-
},
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"hono": "^4.9.2",
|
|
30
|
-
"path": "^0.12.7",
|
|
31
|
-
"@hono-filebased-route/core": "workspace:*"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@types/bun": "latest",
|
|
35
|
-
"bun-plugin-dts": "^0.3.0",
|
|
36
|
-
"typescript": "^5.0.0"
|
|
37
|
-
},
|
|
38
|
-
"peerDependenciesMeta": {
|
|
39
|
-
"hono": {
|
|
40
|
-
"optional": false
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
"publishConfig": {
|
|
44
|
-
"access": "public"
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@hono-filebased-route/runtime",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A core utility for file-based routing in Hono applications.",
|
|
6
|
+
"author": "HM Suiji <hmsuiji@gmail.com>",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"hono",
|
|
9
|
+
"router",
|
|
10
|
+
"file-based",
|
|
11
|
+
"routing",
|
|
12
|
+
"backend",
|
|
13
|
+
"framework",
|
|
14
|
+
"typescript",
|
|
15
|
+
"file-based-route"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/HM-Suiji/hono-filebased-route.git"
|
|
21
|
+
},
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "bun run build.ts",
|
|
26
|
+
"clean": "rm -rf dist"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"hono": "^4.9.2",
|
|
30
|
+
"path": "^0.12.7",
|
|
31
|
+
"@hono-filebased-route/core": "workspace:*"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/bun": "latest",
|
|
35
|
+
"bun-plugin-dts": "^0.3.0",
|
|
36
|
+
"typescript": "^5.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"hono": {
|
|
40
|
+
"optional": false
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
46
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": ".",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"composite": true
|
|
7
|
-
},
|
|
8
|
-
"include": [
|
|
9
|
-
"index.ts"
|
|
10
|
-
],
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"dist",
|
|
14
|
-
"**/*.test.ts"
|
|
15
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": ".",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"composite": true
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"index.ts"
|
|
10
|
+
],
|
|
11
|
+
"exclude": [
|
|
12
|
+
"node_modules",
|
|
13
|
+
"dist",
|
|
14
|
+
"**/*.test.ts"
|
|
15
|
+
]
|
|
16
16
|
}
|