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