src/utils/templates.ts 6.2 K raw
1
import type { TemplateInfo } from "../types";
2
3
export const TEMPLATES: Record<string, TemplateInfo> = {
4
	default: {
5
		branch: "main",
6
		description: "Basic setup with Bun, Hono, Vite and React",
7
	},
8
	tailwind: { branch: "tailwindcss", description: "Basic setup + TailwindCSS" },
9
	shadcn: {
10
		branch: "shadcn-ui",
11
		description: "Basic setup + TailwindCSS + shadcn/ui",
12
	},
13
};
14
15
export const honoRpcTemplate = `import { Hono } from "hono";
16
import { cors } from "hono/cors";
17
import type { ApiResponse } from "shared/dist";
18
19
export const app = new Hono()
20
21
.use(cors())
22
23
.get("/", (c) => {
24
	return c.text("Hello Hono!");
25
})
26
27
.get("/hello", async (c) => {
28
	const data: ApiResponse = {
29
		message: "Hello BHVR!",
30
		success: true,
31
	};
32
33
	return c.json(data, { status: 200 });
34
});
35
36
export default app;`;
37
38
export const honoClientTemplate = `import { hc } from "hono/client";
39
import type { app } from "./index";
40
41
export type AppType = typeof app;
42
export type Client = ReturnType<typeof hc<AppType>>;
43
44
export const hcWithType = (...args: Parameters<typeof hc>): Client =>
45
  hc<AppType>(...args);`;
46
47
export const tailwindTemplate = `import { useState } from 'react'
48
import beaver from './assets/beaver.svg'
49
import { hcWithType } from 'server/dist/client'
50
51
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000"
52
53
type ResponseType = Awaited<ReturnType<typeof client.hello.$get>>;
54
55
const client = hcWithType(SERVER_URL);
56
57
function App() {
58
  const [data, setData] = useState<Awaited<ReturnType<ResponseType["json"]>> | undefined>()
59
60
  async function sendRequest() {
61
    try {
62
      const res = await client.hello.$get()
63
      if (!res.ok) {
64
        console.log("Error fetching data")
65
        return
66
      }
67
      const data = await res.json()
68
      setData(data)
69
    } catch (error) {
70
      console.log(error)
71
    }
72
  }
73
74
  return (
75
    <div className="max-w-xl mx-auto flex flex-col gap-6 items-center justify-center min-h-screen">
76
      <a href="https://github.com/stevedylandev/bhvr" target="_blank">
77
        <img
78
          src={beaver}
79
          className="w-16 h-16 cursor-pointer"
80
          alt="beaver logo"
81
        />
82
      </a>
83
      <h1 className="text-5xl font-black">bhvr</h1>
84
      <h2 className="text-2xl font-bold">Bun + Hono + Vite + React</h2>
85
      <p>A typesafe fullstack monorepo</p>
86
      <div className='flex items-center gap-4'>
87
        <button
88
          onClick={sendRequest}
89
          className="bg-black text-white px-2.5 py-1.5 rounded-md"
90
        >
91
          Call API
92
        </button>
93
        <a target='_blank' href="https://bhvr.dev" className='border-1 border-black text-black px-2.5 py-1.5 rounded-md'>
94
          Docs
95
        </a>
96
      </div>
97
        {data && (
98
          <pre className="bg-gray-100 p-4 rounded-md">
99
            <code>
100
            Message: {data.message} <br />
101
            Success: {data.success.toString()}
102
            </code>
103
          </pre>
104
        )}
105
    </div>
106
  )
107
}
108
109
export default App`;
110
111
export const shadcnTemplate = `import { useState } from 'react'
112
import beaver from './assets/beaver.svg'
113
import { Button } from './components/ui/button'
114
import { hcWithType } from 'server/dist/client'
115
116
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000"
117
118
const client = hcWithType(SERVER_URL);
119
120
type ResponseType = Awaited<ReturnType<typeof client.hello.$get>>;
121
122
function App() {
123
  const [data, setData] = useState<Awaited<ReturnType<ResponseType["json"]>> | undefined>()
124
125
  async function sendRequest() {
126
    try {
127
      const res = await client.hello.$get()
128
      if (!res.ok) {
129
        console.log("Error fetching data")
130
        return
131
      }
132
      const data = await res.json()
133
      setData(data)
134
    } catch (error) {
135
      console.log(error)
136
    }
137
  }
138
139
  return (
140
    <div className="max-w-xl mx-auto flex flex-col gap-6 items-center justify-center min-h-screen">
141
      <a href="https://github.com/stevedylandev/bhvr" target="_blank">
142
        <img
143
          src={beaver}
144
          className="w-16 h-16 cursor-pointer"
145
          alt="beaver logo"
146
        />
147
      </a>
148
      <h1 className="text-5xl font-black">bhvr</h1>
149
      <h2 className="text-2xl font-bold">Bun + Hono + Vite + React</h2>
150
      <p>A typesafe fullstack monorepo</p>
151
      <div className='flex items-center gap-4'>
152
        <Button
153
          onClick={sendRequest}
154
        >
155
          Call API
156
        </Button>
157
        <Button
158
          variant='secondary'
159
          asChild
160
        >
161
          <a target='_blank' href="https://bhvr.dev">
162
          Docs
163
          </a>
164
        </Button>
165
      </div>
166
        {data && (
167
          <pre className="bg-gray-100 p-4 rounded-md">
168
            <code>
169
            Message: {data.message} <br />
170
            Success: {data.success.toString()}
171
            </code>
172
          </pre>
173
        )}
174
    </div>
175
  )
176
}
177
178
export default App`;
179
180
export const defaultTemplate = `import { useState } from 'react'
181
import beaver from './assets/beaver.svg'
182
import { hcWithType } from 'server/dist/client'
183
import './App.css'
184
185
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000"
186
187
const client = hcWithType(SERVER_URL);
188
189
type ResponseType = Awaited<ReturnType<typeof client.hello.$get>>;
190
191
function App() {
192
  const [data, setData] = useState<Awaited<ReturnType<ResponseType["json"]>> | undefined>()
193
194
  async function sendRequest() {
195
    try {
196
      const res = await client.hello.$get()
197
      if (!res.ok) {
198
        console.log("Error fetching data")
199
        return
200
      }
201
      const data = await res.json()
202
      setData(data)
203
    } catch (error) {
204
      console.log(error)
205
    }
206
  }
207
208
  return (
209
    <>
210
      <div>
211
        <a href="https://github.com/stevedylandev/bhvr" target="_blank">
212
          <img src={beaver} className="logo" alt="beaver logo" />
213
        </a>
214
      </div>
215
      <h1>bhvr</h1>
216
      <h2>Bun + Hono + Vite + React</h2>
217
      <p>A typesafe fullstack monorepo</p>
218
      <div className="card">
219
        <div className='button-container'>
220
          <button onClick={sendRequest}>
221
            Call API
222
          </button>
223
          <a className='docs-link' target='_blank' href="https://bhvr.dev">Docs</a>
224
        </div>
225
        {data && (
226
          <pre className='response'>
227
            <code>
228
            Message: {data.message} <br />
229
            Success: {data.success.toString()}
230
            </code>
231
          </pre>
232
        )}
233
      </div>
234
    </>
235
  )
236
}
237
238
export default App`;