@hono-filebased-route/vite-plugin 0.3.0 → 0.3.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/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { Plugin } from 'vite'
2
2
  import { createPluginName } from './shared/create'
3
- import { generateRoutesFile } from '@hono-filebased-route/core'
3
+ import { generateRoutesFile, createLogger } from '@hono-filebased-route/core'
4
+ import path from 'path'
5
+ import { writeFile, readFile } from 'fs/promises'
4
6
 
5
7
  interface Options {
6
8
  dir: string
@@ -11,6 +13,15 @@ interface Options {
11
13
  }
12
14
 
13
15
  const useName = createPluginName(true)
16
+ const virtualFileId = 'virtual:generated-routes'
17
+
18
+ const newFileContent = `
19
+ import { Context } from 'hono'
20
+
21
+ export function GET(c: Context) {
22
+ return c.text('')
23
+ }
24
+ `
14
25
 
15
26
  const usePlugin = (options?: Partial<Options>): Plugin => {
16
27
  const {
@@ -20,8 +31,8 @@ const usePlugin = (options?: Partial<Options>): Plugin => {
20
31
  verbose = false,
21
32
  callback,
22
33
  } = options || {}
23
- const virtualFileId = 'generated-routes'
24
34
  let generated_route: string = ''
35
+ const logger = createLogger(verbose)
25
36
 
26
37
  const generateRoutes = async () => {
27
38
  if (virtualRoute) {
@@ -30,6 +41,7 @@ const usePlugin = (options?: Partial<Options>): Plugin => {
30
41
  output: '',
31
42
  write: false,
32
43
  verbose,
44
+ typescript: false,
33
45
  })
34
46
  generated_route = router
35
47
  } else {
@@ -51,6 +63,12 @@ const usePlugin = (options?: Partial<Options>): Plugin => {
51
63
  await generateRoutes()
52
64
 
53
65
  server.watcher.on('all', async (event, file) => {
66
+ if (!file.startsWith(path.resolve(dir))) return
67
+ logger.info(`${event}, ${file}`)
68
+ if (event === 'add') {
69
+ const fileContent = (await readFile(file, 'utf-8')).trim()
70
+ if (fileContent === '') return await writeFile(file, newFileContent.trimStart())
71
+ }
54
72
  if (events.includes(event)) {
55
73
  await generateRoutes()
56
74
  server.restart()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono-filebased-route/vite-plugin",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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>",
@@ -30,11 +30,13 @@
30
30
  "@hono-filebased-route/core": "workspace:*",
31
31
  "chokidar": "^4.0.3",
32
32
  "hono": "^4.9.2",
33
- "path": "^0.12.7"
33
+ "path": "^0.12.7",
34
+ "pino": "^9.9.0"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/bun": "latest",
37
38
  "bun-plugin-dts": "^0.3.0",
39
+ "pino-pretty": "^13.1.1",
38
40
  "terser": "^5.43.1",
39
41
  "typescript": "^5.0.0",
40
42
  "vite": "^7.1.3"
@@ -42,6 +44,9 @@
42
44
  "peerDependenciesMeta": {
43
45
  "hono": {
44
46
  "optional": false
47
+ },
48
+ "typescript": {
49
+ "optional": false
45
50
  }
46
51
  },
47
52
  "publishConfig": {