Skip to content

Commit 3fc1ceb

Browse files
committed
Add Bun example
1 parent 7c2bdf5 commit 3fc1ceb

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,37 @@ Follow these steps to set up and run your bot using this template:
4747

4848
Install the required dependencies:
4949
```bash
50-
npm install
50+
bun install
5151
```
5252
Start the bot in watch mode (auto-reload when code changes):
5353
```bash
54-
npm run dev
54+
bun dev
5555
```
5656

5757
**Production Mode:**
5858

5959
Install only production dependencies:
6060
```bash
61-
npm install --only=prod
61+
bun install --only=prod
6262
```
6363

6464
Set `DEBUG` environment variable to `false` in your `.env` file.
6565

6666
Start the bot in production mode:
6767
```bash
68-
npm run start:force # skip type checking and start
68+
bun run start:force # skip type checking and start
6969
# or
70-
npm start # with type checking (requires development dependencies)
70+
bun start # with type checking (requires development dependencies)
7171
```
7272

7373
### List of Available Commands
7474

75-
- `npm run lint` — Lint source code.
76-
- `npm run format` — Format source code.
77-
- `npm run typecheck` — Run type checking.
78-
- `npm run dev` — Start the bot in development mode.
79-
- `npm run start` — Start the bot.
80-
- `npm run start:force` — Starts the bot without type checking.
75+
- `bun lint` — Lint source code.
76+
- `bun format` — Format source code.
77+
- `bun typecheck` — Run type checking.
78+
- `bun dev` — Start the bot in development mode.
79+
- `bun start` — Start the bot.
80+
- `bun start:force` — Starts the bot without type checking.
8181

8282
### Directory Structure
8383

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"format": "eslint . --fix",
1919
"typecheck": "tsc",
2020
"build": "tsc --noEmit false",
21-
"dev": "tsc-watch --onSuccess \"tsx ./src/main.ts\"",
22-
"start": "tsc && tsx ./src/main.ts",
23-
"start:force": "tsx ./src/main.ts",
21+
"dev": "bun --watch ./src/main.ts",
22+
"start": "tsc && bun ./src/main.ts",
23+
"start:force": "bun ./src/main.ts",
2424
"prepare": "husky || true"
2525
},
2626
"dependencies": {

src/server/index.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,20 @@ export function createServer(dependencies: Dependencies) {
7272
export type Server = Awaited<ReturnType<typeof createServer>>
7373

7474
export function createServerManager(server: Server, options: { host: string, port: number }) {
75-
let handle: undefined | ReturnType<typeof serve>
75+
let handle: undefined | ReturnType<typeof Bun.serve>
7676
return {
7777
start() {
78-
return new Promise<{ url: string }>((resolve) => {
79-
handle = serve(
80-
{
81-
fetch: server.fetch,
82-
hostname: options.host,
83-
port: options.port,
84-
},
85-
info => resolve({
86-
url: info.family === 'IPv6'
87-
? `http://[${info.address}]:${info.port}`
88-
: `http://${info.address}:${info.port}`,
89-
}),
90-
)
78+
handle = Bun.serve({
79+
fetch: server.fetch,
80+
hostname: options.host,
81+
port: options.port,
9182
})
83+
return {
84+
url: handle.url,
85+
}
9286
},
9387
stop() {
94-
return new Promise<void>((resolve) => {
95-
if (handle)
96-
handle.close(() => resolve())
97-
else
98-
resolve()
99-
})
88+
return handle?.stop()
10089
},
10190
}
10291
}

0 commit comments

Comments
 (0)