@hono-filebased-route/vite-plugin 0.1.0 → 0.3.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/index.ts CHANGED
@@ -3,30 +3,42 @@ import { createPluginName } from './shared/create'
3
3
  import { generateRoutesFile } from '@hono-filebased-route/core'
4
4
 
5
5
  interface Options {
6
- routesDir: string
6
+ dir: string
7
+ output: string
8
+ verbose: boolean
7
9
  virtualRoute: boolean
8
- outputFile: string
9
- callback: (router: string) => void
10
+ callback?: (router: string) => void
10
11
  }
11
12
 
12
13
  const useName = createPluginName(true)
13
14
 
14
15
  const usePlugin = (options?: Partial<Options>): Plugin => {
15
16
  const {
16
- routesDir = './src/routes',
17
+ dir = './src/routes',
17
18
  virtualRoute = true,
18
- outputFile = './src/generated-routes.ts',
19
- callback
19
+ output = './src/generated-routes.ts',
20
+ verbose = false,
21
+ callback,
20
22
  } = options || {}
21
23
  const virtualFileId = 'generated-routes'
22
24
  let generated_route: string = ''
23
25
 
24
26
  const generateRoutes = async () => {
25
27
  if (virtualRoute) {
26
- const router = await generateRoutesFile(routesDir, '', false)
28
+ const router = await generateRoutesFile({
29
+ dir,
30
+ output: '',
31
+ write: false,
32
+ verbose,
33
+ })
27
34
  generated_route = router
28
35
  } else {
29
- generateRoutesFile(routesDir, outputFile)
36
+ generateRoutesFile({
37
+ dir,
38
+ output,
39
+ write: true,
40
+ verbose,
41
+ })
30
42
  }
31
43
  callback?.(generated_route)
32
44
  }
@@ -46,20 +58,20 @@ const usePlugin = (options?: Partial<Options>): Plugin => {
46
58
  })
47
59
  },
48
60
  resolveId: virtualRoute
49
- ? (id) => {
50
- if (id === virtualFileId) {
51
- return virtualFileId
61
+ ? id => {
62
+ if (id === virtualFileId) {
63
+ return virtualFileId
64
+ }
52
65
  }
53
- }
54
66
  : undefined,
55
67
  load: virtualRoute
56
- ? (id) => {
57
- if (id === virtualFileId) {
58
- return generated_route
68
+ ? id => {
69
+ if (id === virtualFileId) {
70
+ return generated_route
71
+ }
59
72
  }
60
- }
61
- : undefined
73
+ : undefined,
62
74
  }
63
75
  }
64
76
 
65
- export default usePlugin
77
+ export default usePlugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono-filebased-route/vite-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "A Vite plugin for file-based routing in Hono applications.",
6
6
  "author": "HM Suiji <hmsuiji@gmail.com>",
package/shared/create.ts CHANGED
@@ -1,6 +1,4 @@
1
- export const createPluginName = (
2
- reusable: boolean = false
3
- ) => {
1
+ export const createPluginName = (reusable: boolean = false) => {
4
2
  let i = 0
5
3
  return (name: string) => {
6
4
  const base = `vite-plugin-${name}`
@@ -13,6 +11,6 @@ export const createVirtualModuleID = (name: string) => {
13
11
  const resolvedVirtualModuleId = '\0' + virtualModuleId
14
12
  return {
15
13
  virtualModuleId,
16
- resolvedVirtualModuleId
14
+ resolvedVirtualModuleId,
17
15
  }
18
- }
16
+ }