create-bunspace 0.1.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/README.md +181 -0
- package/dist/bin.js +5755 -0
- package/dist/templates/monorepo/CLAUDE.md +164 -0
- package/dist/templates/monorepo/LICENSE +21 -0
- package/dist/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
- package/dist/templates/monorepo/README.md +74 -0
- package/dist/templates/monorepo/SYNC_VERIFICATION.md +1 -0
- package/dist/templates/monorepo/apps/example/package.json +19 -0
- package/dist/templates/monorepo/apps/example/src/index.ts +23 -0
- package/dist/templates/monorepo/apps/example/src/types/index.ts +7 -0
- package/dist/templates/monorepo/apps/example/src/utils/index.ts +7 -0
- package/dist/templates/monorepo/core/packages/main/package.json +41 -0
- package/dist/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
- package/dist/templates/monorepo/core/packages/main/src/index.ts +80 -0
- package/dist/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
- package/dist/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
- package/dist/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
- package/dist/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
- package/dist/templates/monorepo/core/packages/utils/package.json +43 -0
- package/dist/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
- package/dist/templates/monorepo/core/packages/utils/src/index.ts +2 -0
- package/dist/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
- package/dist/templates/monorepo/core/packages/utils/src/result.ts +146 -0
- package/dist/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
- package/dist/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
- package/dist/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
- package/dist/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
- package/dist/templates/monorepo/oxlint.json +14 -0
- package/dist/templates/monorepo/package.json +39 -0
- package/dist/templates/monorepo/tsconfig.json +35 -0
- package/dist/templates/telegram-bot/.oxlintrc.json +33 -0
- package/dist/templates/telegram-bot/.prettierignore +5 -0
- package/dist/templates/telegram-bot/.prettierrc +26 -0
- package/dist/templates/telegram-bot/CLAUDE.deploy.md +356 -0
- package/dist/templates/telegram-bot/CLAUDE.dev.md +266 -0
- package/dist/templates/telegram-bot/CLAUDE.md +280 -0
- package/dist/templates/telegram-bot/Dockerfile +46 -0
- package/dist/templates/telegram-bot/README.md +245 -0
- package/dist/templates/telegram-bot/apps/.gitkeep +0 -0
- package/dist/templates/telegram-bot/bun.lock +208 -0
- package/dist/templates/telegram-bot/core/.env.example +71 -0
- package/dist/templates/telegram-bot/core/README.md +1067 -0
- package/dist/templates/telegram-bot/core/package.json +15 -0
- package/dist/templates/telegram-bot/core/src/config/env.ts +131 -0
- package/dist/templates/telegram-bot/core/src/config/index.ts +97 -0
- package/dist/templates/telegram-bot/core/src/config/logging.ts +110 -0
- package/dist/templates/telegram-bot/core/src/handlers/control.ts +85 -0
- package/dist/templates/telegram-bot/core/src/handlers/health.ts +83 -0
- package/dist/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
- package/dist/templates/telegram-bot/core/src/index.ts +161 -0
- package/dist/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
- package/dist/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
- package/dist/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
- package/dist/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
- package/dist/templates/telegram-bot/core/src/types/bot.ts +92 -0
- package/dist/templates/telegram-bot/core/src/types/constants.ts +50 -0
- package/dist/templates/telegram-bot/core/src/types/result.ts +1 -0
- package/dist/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
- package/dist/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
- package/dist/templates/telegram-bot/core/src/utils/commands.ts +63 -0
- package/dist/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
- package/dist/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
- package/dist/templates/telegram-bot/core/src/utils/memory.ts +33 -0
- package/dist/templates/telegram-bot/core/src/utils/result.ts +26 -0
- package/dist/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
- package/dist/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
- package/dist/templates/telegram-bot/core/tsconfig.json +9 -0
- package/dist/templates/telegram-bot/docker-compose.yml +37 -0
- package/dist/templates/telegram-bot/docs/cli-commands.md +377 -0
- package/dist/templates/telegram-bot/docs/development.md +363 -0
- package/dist/templates/telegram-bot/docs/environment.md +460 -0
- package/dist/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
- package/dist/templates/telegram-bot/docs/examples/simple-command.md +207 -0
- package/dist/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
- package/dist/templates/telegram-bot/docs/getting-started.md +223 -0
- package/dist/templates/telegram-bot/docs/troubleshooting.md +489 -0
- package/dist/templates/telegram-bot/package.json +49 -0
- package/dist/templates/telegram-bot/packages/utils/package.json +12 -0
- package/dist/templates/telegram-bot/packages/utils/src/index.ts +2 -0
- package/dist/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
- package/dist/templates/telegram-bot/packages/utils/src/result.ts +80 -0
- package/dist/templates/telegram-bot/tools/README.md +47 -0
- package/dist/templates/telegram-bot/tools/commands/doctor.ts +460 -0
- package/dist/templates/telegram-bot/tools/commands/index.ts +35 -0
- package/dist/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
- package/dist/templates/telegram-bot/tools/commands/setup.ts +368 -0
- package/dist/templates/telegram-bot/tools/commands/status.ts +140 -0
- package/dist/templates/telegram-bot/tools/index.ts +16 -0
- package/dist/templates/telegram-bot/tools/package.json +12 -0
- package/dist/templates/telegram-bot/tools/utils/index.ts +13 -0
- package/dist/templates/telegram-bot/tsconfig.json +22 -0
- package/dist/templates/telegram-bot/vitest.config.ts +29 -0
- package/package.json +35 -0
- package/templates/monorepo/CLAUDE.md +164 -0
- package/templates/monorepo/LICENSE +21 -0
- package/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
- package/templates/monorepo/README.md +74 -0
- package/templates/monorepo/apps/example/package.json +19 -0
- package/templates/monorepo/apps/example/src/index.ts +23 -0
- package/templates/monorepo/apps/example/src/types/index.ts +7 -0
- package/templates/monorepo/apps/example/src/utils/index.ts +7 -0
- package/templates/monorepo/core/packages/main/package.json +41 -0
- package/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
- package/templates/monorepo/core/packages/main/src/index.ts +80 -0
- package/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
- package/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
- package/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
- package/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
- package/templates/monorepo/core/packages/utils/package.json +43 -0
- package/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
- package/templates/monorepo/core/packages/utils/src/index.ts +2 -0
- package/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
- package/templates/monorepo/core/packages/utils/src/result.ts +146 -0
- package/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
- package/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
- package/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
- package/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
- package/templates/monorepo/oxlint.json +14 -0
- package/templates/monorepo/package.json +39 -0
- package/templates/monorepo/tsconfig.json +35 -0
- package/templates/telegram-bot/.oxlintrc.json +33 -0
- package/templates/telegram-bot/.prettierignore +5 -0
- package/templates/telegram-bot/.prettierrc +26 -0
- package/templates/telegram-bot/CLAUDE.deploy.md +356 -0
- package/templates/telegram-bot/CLAUDE.dev.md +266 -0
- package/templates/telegram-bot/CLAUDE.md +280 -0
- package/templates/telegram-bot/Dockerfile +46 -0
- package/templates/telegram-bot/README.md +245 -0
- package/templates/telegram-bot/apps/.gitkeep +0 -0
- package/templates/telegram-bot/bun.lock +208 -0
- package/templates/telegram-bot/core/.env.example +71 -0
- package/templates/telegram-bot/core/README.md +1067 -0
- package/templates/telegram-bot/core/package.json +15 -0
- package/templates/telegram-bot/core/src/config/env.ts +131 -0
- package/templates/telegram-bot/core/src/config/index.ts +97 -0
- package/templates/telegram-bot/core/src/config/logging.ts +110 -0
- package/templates/telegram-bot/core/src/handlers/control.ts +85 -0
- package/templates/telegram-bot/core/src/handlers/health.ts +83 -0
- package/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
- package/templates/telegram-bot/core/src/index.ts +161 -0
- package/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
- package/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
- package/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
- package/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
- package/templates/telegram-bot/core/src/types/bot.ts +92 -0
- package/templates/telegram-bot/core/src/types/constants.ts +50 -0
- package/templates/telegram-bot/core/src/types/result.ts +1 -0
- package/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
- package/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
- package/templates/telegram-bot/core/src/utils/commands.ts +63 -0
- package/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
- package/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
- package/templates/telegram-bot/core/src/utils/memory.ts +33 -0
- package/templates/telegram-bot/core/src/utils/result.ts +26 -0
- package/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
- package/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
- package/templates/telegram-bot/core/tsconfig.json +9 -0
- package/templates/telegram-bot/docker-compose.yml +37 -0
- package/templates/telegram-bot/docs/cli-commands.md +377 -0
- package/templates/telegram-bot/docs/development.md +363 -0
- package/templates/telegram-bot/docs/environment.md +460 -0
- package/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
- package/templates/telegram-bot/docs/examples/simple-command.md +207 -0
- package/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
- package/templates/telegram-bot/docs/getting-started.md +223 -0
- package/templates/telegram-bot/docs/troubleshooting.md +489 -0
- package/templates/telegram-bot/package.json +49 -0
- package/templates/telegram-bot/packages/utils/package.json +12 -0
- package/templates/telegram-bot/packages/utils/src/index.ts +2 -0
- package/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
- package/templates/telegram-bot/packages/utils/src/result.ts +80 -0
- package/templates/telegram-bot/tools/README.md +47 -0
- package/templates/telegram-bot/tools/commands/doctor.ts +460 -0
- package/templates/telegram-bot/tools/commands/index.ts +35 -0
- package/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
- package/templates/telegram-bot/tools/commands/setup.ts +368 -0
- package/templates/telegram-bot/tools/commands/status.ts +140 -0
- package/templates/telegram-bot/tools/index.ts +16 -0
- package/templates/telegram-bot/tools/package.json +12 -0
- package/templates/telegram-bot/tools/utils/index.ts +13 -0
- package/templates/telegram-bot/tsconfig.json +22 -0
- package/templates/telegram-bot/vitest.config.ts +29 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
# Development Guide
|
|
2
|
+
|
|
3
|
+
Guía completa de desarrollo para extender y modificar el bot.
|
|
4
|
+
|
|
5
|
+
## Scripts Disponibles
|
|
6
|
+
|
|
7
|
+
| Script | Descripción | Cuándo Usar |
|
|
8
|
+
| ------ | ----------- | ----------- |
|
|
9
|
+
| `bun run dev` | Hot reload desarrollo | Desarrollo activo |
|
|
10
|
+
| `bun run start` | Producción | Testing en producción |
|
|
11
|
+
| `bun run typecheck` | Type-check | Antes de commit |
|
|
12
|
+
| `bun run lint` | Linting | Antes de commit |
|
|
13
|
+
| `bun run build` | Typecheck + lint | Verificación completa |
|
|
14
|
+
| `bun test` | Ejecutar tests | Desarrollo de features |
|
|
15
|
+
| `bun run clean:logs` | Limpiar logs | Debugging |
|
|
16
|
+
| `bun run doctor` | Diagnóstico | Problemas de configuración |
|
|
17
|
+
|
|
18
|
+
## Hot Reload
|
|
19
|
+
|
|
20
|
+
El comando `bun run dev` usa `--watch` para recarga automática:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bun run dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Cómo Funciona
|
|
27
|
+
|
|
28
|
+
1. **Watch** - Bun monitorea archivos en `core/src/`
|
|
29
|
+
2. **Detecta cambios** - Al guardar, detecta modificaciones
|
|
30
|
+
3. **Recompila** - Recompila automáticamente
|
|
31
|
+
4. **Reinicia** - Reinicia el bot sin intervención manual
|
|
32
|
+
|
|
33
|
+
### Limitaciones
|
|
34
|
+
|
|
35
|
+
- **No typecheck en vivo** - Solo recompila, no valida tipos
|
|
36
|
+
- **Para typecheck** - Usa `bun run typecheck` en otra terminal
|
|
37
|
+
- **Timeouts** - El bot puede tardar ~2s en reiniciar
|
|
38
|
+
|
|
39
|
+
### Flujo Recomendado
|
|
40
|
+
|
|
41
|
+
**Terminal 1: Bot con hot reload**
|
|
42
|
+
```bash
|
|
43
|
+
bun run dev
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Terminal 2: Typecheck continuo**
|
|
47
|
+
```bash
|
|
48
|
+
bun run typecheck --watch # Si estuviera disponible
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Agregar Comandos
|
|
52
|
+
|
|
53
|
+
### 1. Crear Handler
|
|
54
|
+
|
|
55
|
+
**Archivo**: `core/src/handlers/mycommand.ts`
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import type { Context } from 'telegraf'
|
|
59
|
+
|
|
60
|
+
export async function handleMyCommand(ctx: Context): Promise<void> {
|
|
61
|
+
const { message } = ctx
|
|
62
|
+
const username = message?.from?.username ?? 'stranger'
|
|
63
|
+
|
|
64
|
+
await ctx.reply(`Hello, ${username}!`)
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 2. Registrar en Bot
|
|
69
|
+
|
|
70
|
+
**Archivo**: `core/src/index.ts`
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { handleMyCommand } from './handlers/mycommand.js'
|
|
74
|
+
|
|
75
|
+
bot.command('mycommand', handleMyCommand)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. Probar
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
bun run dev
|
|
82
|
+
# En Telegram: /mycommand
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Comandos con Argumentos
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
export async function handleGreet(ctx: Context): Promise<void> {
|
|
89
|
+
const message = ctx.message
|
|
90
|
+
const text = message?.text
|
|
91
|
+
const args = text?.split(' ').slice(1) ?? []
|
|
92
|
+
const name = args[0] ?? 'stranger'
|
|
93
|
+
|
|
94
|
+
await ctx.reply(`Hello, ${name}!`)
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Uso: `/greet Alice` → `Hello, Alice!`
|
|
99
|
+
|
|
100
|
+
## Agregar Middleware
|
|
101
|
+
|
|
102
|
+
### Middleware Simple
|
|
103
|
+
|
|
104
|
+
**Archivo**: `core/src/middleware/timestamp.ts`
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import type { Context, Middleware } from 'telegraf'
|
|
108
|
+
|
|
109
|
+
export function timestamp(): Middleware<Context> {
|
|
110
|
+
return async (ctx, next) => {
|
|
111
|
+
const start = Date.now()
|
|
112
|
+
await next()
|
|
113
|
+
const duration = Date.now() - start
|
|
114
|
+
console.log(`Request took ${duration}ms`)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Registrar**:
|
|
120
|
+
```typescript
|
|
121
|
+
import { timestamp } from './middleware/timestamp.js'
|
|
122
|
+
|
|
123
|
+
bot.use(timestamp())
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Middleware con Auth
|
|
127
|
+
|
|
128
|
+
**Archivo**: `core/src/middleware/admin-only.ts`
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import type { Context, Middleware } from 'telegraf'
|
|
132
|
+
|
|
133
|
+
const ADMIN_IDS = ['123456789', '987654321']
|
|
134
|
+
|
|
135
|
+
export function adminOnly(): Middleware<Context> {
|
|
136
|
+
return async (ctx, next) => {
|
|
137
|
+
const userId = ctx.from?.id.toString()
|
|
138
|
+
|
|
139
|
+
if (!userId || !ADMIN_IDS.includes(userId)) {
|
|
140
|
+
await ctx.reply('⛔ You are not authorized')
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return next()
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Usar**:
|
|
150
|
+
```typescript
|
|
151
|
+
import { adminOnly } from './middleware/admin-only.js'
|
|
152
|
+
|
|
153
|
+
bot.command('admin', adminOnly(), handleAdmin)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Patrones Comunes
|
|
157
|
+
|
|
158
|
+
### Manejo de Errors con Result Type
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { ok, err, type Result, botError } from '@mks2508/telegram-bot-utils'
|
|
162
|
+
|
|
163
|
+
function divide(a: number, b: number): Result<number> {
|
|
164
|
+
if (b === 0) {
|
|
165
|
+
return err(botError('INVALID_ARGS', 'Cannot divide by zero'))
|
|
166
|
+
}
|
|
167
|
+
return ok(a / b)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// En un handler
|
|
171
|
+
export async function handleCalc(ctx: Context): Promise<void> {
|
|
172
|
+
const result = divide(10, 2)
|
|
173
|
+
|
|
174
|
+
if (result.ok) {
|
|
175
|
+
await ctx.reply(`Result: ${result.value}`)
|
|
176
|
+
} else {
|
|
177
|
+
await ctx.reply(`Error: ${result.error.message}`)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Logging con Better Logger
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { botLogger, kv, badge } from '@mks2508/telegram-bot-utils'
|
|
186
|
+
|
|
187
|
+
export async function handleMyCommand(ctx: Context): Promise<void> {
|
|
188
|
+
botLogger.info(`${badge('CMD')} /mycommand`, kv({ user: ctx.from.id }))
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
// ... logic
|
|
192
|
+
botLogger.success('Command executed successfully')
|
|
193
|
+
} catch (error) {
|
|
194
|
+
botLogger.error('Command failed:', error)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Async Operations con Timeout
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
async function fetchWithTimeout(url: string, timeout = 5000): Promise<string> {
|
|
203
|
+
const controller = new AbortController()
|
|
204
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout)
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
const response = await fetch(url, { signal: controller.signal })
|
|
208
|
+
const text = await response.text()
|
|
209
|
+
return text
|
|
210
|
+
} finally {
|
|
211
|
+
clearTimeout(timeoutId)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Debugging
|
|
217
|
+
|
|
218
|
+
### Logs en Consola
|
|
219
|
+
|
|
220
|
+
El bot usa Better Logger con preset cyberpunk:
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
[Bot] ℹ Bot started successfully
|
|
224
|
+
[Bot] ✓ Polling for updates...
|
|
225
|
+
[Cmd] ℹ /health from user 123456789
|
|
226
|
+
[Bot] ✓ Health check completed in 45ms
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Ver Variables de Entorno
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Ver todas las variables
|
|
233
|
+
cat core/.env.local
|
|
234
|
+
|
|
235
|
+
# Ver variable específica
|
|
236
|
+
grep TG_BOT_TOKEN core/.env.local
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Ver Instancias Corriendo
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
bun run cli status
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Ver Logs Archivados
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Logs de info
|
|
249
|
+
cat core/logs/info.log
|
|
250
|
+
|
|
251
|
+
# Logs de error
|
|
252
|
+
cat core/logs/error.log
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Habilitar Debug Mode
|
|
256
|
+
|
|
257
|
+
En `core/.env.local`:
|
|
258
|
+
```bash
|
|
259
|
+
TG_DEBUG=true
|
|
260
|
+
LOG_LEVEL=debug
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Testing
|
|
264
|
+
|
|
265
|
+
### Escribir Tests
|
|
266
|
+
|
|
267
|
+
**Archivo**: `core/src/handlers/mycommand.test.ts`
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import { describe, test, expect } from 'bun:test'
|
|
271
|
+
import { handleMyCommand } from './mycommand.js'
|
|
272
|
+
|
|
273
|
+
describe('handleMyCommand', () => {
|
|
274
|
+
test('debe responder con greeting', async () => {
|
|
275
|
+
const mockCtx = {
|
|
276
|
+
from: { id: 123, username: 'testuser' },
|
|
277
|
+
reply: async (msg: string) => msg,
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
await handleMyCommand(mockCtx as never)
|
|
281
|
+
expect(mockCtx.reply).toHaveBeenCalledWith('Hello, testuser!')
|
|
282
|
+
})
|
|
283
|
+
})
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Ejecutar Tests
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
# Todos los tests
|
|
290
|
+
bun test
|
|
291
|
+
|
|
292
|
+
# Un archivo específico
|
|
293
|
+
bun test core/src/handlers/mycommand.test.ts
|
|
294
|
+
|
|
295
|
+
# Watch mode
|
|
296
|
+
bun test --watch
|
|
297
|
+
|
|
298
|
+
# Con coverage
|
|
299
|
+
bun test --coverage
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Antes de Commitear
|
|
303
|
+
|
|
304
|
+
### Checklist
|
|
305
|
+
|
|
306
|
+
- [ ] `bun run typecheck` → 0 errores
|
|
307
|
+
- [ ] `bun run lint` → 0 warnings, 0 errors
|
|
308
|
+
- [ ] `bun test` → Todos los tests pasan
|
|
309
|
+
- [ ] No `console.log` (usar `botLogger`)
|
|
310
|
+
- [ ] Código formateado
|
|
311
|
+
|
|
312
|
+
### Precommit Hook (Opcional)
|
|
313
|
+
|
|
314
|
+
```json
|
|
315
|
+
{
|
|
316
|
+
"scripts": {
|
|
317
|
+
"precommit": "bun run build && bun test"
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Usar con Husky o similar:
|
|
323
|
+
```bash
|
|
324
|
+
npm pkg set scripts.precommit="bun run precommit"
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## Estructura de Archivos
|
|
328
|
+
|
|
329
|
+
```
|
|
330
|
+
core/src/
|
|
331
|
+
├── index.ts # Entry point, registro de comandos
|
|
332
|
+
├── config/
|
|
333
|
+
│ ├── env.ts # Zod schema para env
|
|
334
|
+
│ └── index.ts # Config singleton
|
|
335
|
+
├── handlers/ # Command handlers
|
|
336
|
+
│ ├── health.ts
|
|
337
|
+
│ ├── control.ts
|
|
338
|
+
│ └── mycommand.ts # Tus comandos aquí
|
|
339
|
+
├── middleware/ # Telegraf middleware
|
|
340
|
+
│ ├── auth.ts
|
|
341
|
+
│ ├── error-handler.ts
|
|
342
|
+
│ └── mymiddleware.ts # Tu middleware aquí
|
|
343
|
+
├── types/ # TypeScript types
|
|
344
|
+
│ ├── result.ts # Result type (re-export)
|
|
345
|
+
│ └── bot.ts # Bot-specific types
|
|
346
|
+
└── utils/ # Utilities
|
|
347
|
+
├── bot-manager.ts # Bot lifecycle
|
|
348
|
+
├── instance-manager.ts
|
|
349
|
+
└── myutil.ts # Tus utils aquí
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Recursos Adicionales
|
|
353
|
+
|
|
354
|
+
- **Telegraf Docs** - [telegraf.js.org](https://telegraf.js.org/)
|
|
355
|
+
- **Telegram Bot API** - [core.telegram.org/bots/api](https://core.telegram.org/bots/api)
|
|
356
|
+
- **Better Logger** - [@mks2508/better-logger](https://github.com/mks2508/better-logger)
|
|
357
|
+
- **CLAUDE.dev.md** - [Guía de desarrollo completa](../CLAUDE.dev.md)
|
|
358
|
+
|
|
359
|
+
## Referencias
|
|
360
|
+
|
|
361
|
+
- [Getting Started](./getting-started.md) - Primeros pasos
|
|
362
|
+
- [CLI Commands](./cli-commands.md) - Comandos CLI
|
|
363
|
+
- [Environment](./environment.md) - Variables de entorno
|