buncargo 1.0.5
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/bin.ts +253 -0
- package/cli.ts +238 -0
- package/config.ts +194 -0
- package/core/docker.ts +384 -0
- package/core/index.ts +7 -0
- package/core/network.ts +152 -0
- package/core/ports.ts +253 -0
- package/core/process.ts +253 -0
- package/core/utils.ts +127 -0
- package/core/watchdog-runner.ts +111 -0
- package/core/watchdog.ts +196 -0
- package/dist/bin.d.ts +12 -0
- package/dist/cli.d.ts +22 -0
- package/dist/config.d.ts +72 -0
- package/dist/core/docker.d.ts +74 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/network.d.ts +30 -0
- package/dist/core/ports.d.ts +30 -0
- package/dist/core/process.d.ts +52 -0
- package/dist/core/utils.d.ts +60 -0
- package/dist/core/watchdog-runner.d.ts +14 -0
- package/dist/core/watchdog.d.ts +46 -0
- package/dist/environment.d.ts +23 -0
- package/dist/index.d.ts +12 -0
- package/dist/lint.d.ts +46 -0
- package/dist/loader.d.ts +39 -0
- package/dist/prisma.d.ts +29 -0
- package/dist/types.d.ts +391 -0
- package/environment.ts +604 -0
- package/index.ts +103 -0
- package/lint.ts +277 -0
- package/loader.ts +100 -0
- package/package.json +124 -0
- package/prisma.ts +138 -0
- package/readme.md +198 -0
- package/types.ts +538 -0
package/readme.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Buncargo
|
|
2
|
+
|
|
3
|
+
Type-safe development environment CLI for Docker Compose-based projects. Handles container lifecycle, port isolation for git worktrees, and dev server orchestration.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### 1. Create `dev.config.ts` in your project root
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { defineDevConfig } from 'buncargo'
|
|
11
|
+
|
|
12
|
+
export default defineDevConfig({
|
|
13
|
+
projectPrefix: 'myapp',
|
|
14
|
+
|
|
15
|
+
services: {
|
|
16
|
+
postgres: {
|
|
17
|
+
port: 5432,
|
|
18
|
+
healthCheck: 'pg_isready',
|
|
19
|
+
urlTemplate: ({ port }) => `postgresql://postgres:postgres@localhost:${port}/mydb`
|
|
20
|
+
},
|
|
21
|
+
redis: {
|
|
22
|
+
port: 6379,
|
|
23
|
+
healthCheck: 'redis-cli'
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
apps: {
|
|
28
|
+
api: {
|
|
29
|
+
port: 3000,
|
|
30
|
+
devCommand: 'bun run dev',
|
|
31
|
+
cwd: 'apps/backend'
|
|
32
|
+
},
|
|
33
|
+
web: {
|
|
34
|
+
port: 5173,
|
|
35
|
+
devCommand: 'bun run dev',
|
|
36
|
+
cwd: 'apps/frontend'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
envVars: (ports, urls) => ({
|
|
41
|
+
DATABASE_URL: urls.postgres,
|
|
42
|
+
REDIS_URL: urls.redis,
|
|
43
|
+
API_PORT: ports.api
|
|
44
|
+
}),
|
|
45
|
+
|
|
46
|
+
hooks: {
|
|
47
|
+
afterContainersReady: async (ctx) => {
|
|
48
|
+
await ctx.exec('bunx prisma migrate deploy', { cwd: 'packages/prisma' })
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
prisma: {
|
|
53
|
+
cwd: 'packages/prisma'
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. Run it
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
bunx buncargo dev # Start containers + dev servers
|
|
62
|
+
bunx buncargo dev --up-only # Start containers only
|
|
63
|
+
bunx buncargo dev --down # Stop containers
|
|
64
|
+
bunx buncargo dev --reset # Stop and remove volumes
|
|
65
|
+
bunx buncargo prisma studio # Run prisma with correct DATABASE_URL
|
|
66
|
+
bunx buncargo env # Print ports/urls as JSON
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Or add scripts to `package.json`:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"scripts": {
|
|
74
|
+
"dev": "bunx buncargo dev",
|
|
75
|
+
"dev:docker:down": "bunx buncargo dev --down",
|
|
76
|
+
"prisma": "bunx buncargo prisma"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Programmatic Access
|
|
82
|
+
|
|
83
|
+
Need ports/urls in your code (e.g., for tests)?
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { loadDevEnv } from 'buncargo'
|
|
87
|
+
|
|
88
|
+
const env = await loadDevEnv()
|
|
89
|
+
console.log(env.ports.postgres) // 5432 (or offset port)
|
|
90
|
+
console.log(env.urls.api) // http://localhost:3000
|
|
91
|
+
console.log(env.urls.postgres) // postgresql://...
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Features
|
|
95
|
+
|
|
96
|
+
### Worktree Isolation
|
|
97
|
+
|
|
98
|
+
Each git worktree automatically gets unique ports (offset 10-99) so you can run multiple branches simultaneously without conflicts.
|
|
99
|
+
|
|
100
|
+
### Health Checks
|
|
101
|
+
|
|
102
|
+
Built-in health checks for common services:
|
|
103
|
+
|
|
104
|
+
- `pg_isready` - PostgreSQL
|
|
105
|
+
- `redis-cli` - Redis
|
|
106
|
+
- `http` - HTTP endpoint check
|
|
107
|
+
- `tcp` - TCP port check
|
|
108
|
+
|
|
109
|
+
### URL Templates
|
|
110
|
+
|
|
111
|
+
Define connection URLs as functions:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
urlTemplate: ({ port, host, localIp }) =>
|
|
115
|
+
`postgresql://user:pass@${host}:${port}/db`
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Default templates exist for: `postgres`, `redis`, `clickhouse`, `mysql`, `mongodb`
|
|
119
|
+
|
|
120
|
+
### Lifecycle Hooks
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
hooks: {
|
|
124
|
+
afterContainersReady: async (ctx) => { /* Run migrations */ },
|
|
125
|
+
beforeServers: async (ctx) => { /* Seed database */ },
|
|
126
|
+
afterServers: async (ctx) => { /* Post-startup tasks */ },
|
|
127
|
+
beforeStop: async (ctx) => { /* Cleanup */ }
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Hook Context
|
|
132
|
+
|
|
133
|
+
Hooks receive a context object with:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
interface HookContext {
|
|
137
|
+
projectName: string
|
|
138
|
+
ports: { postgres: number, api: number, ... }
|
|
139
|
+
urls: { postgres: string, api: string, ... }
|
|
140
|
+
root: string
|
|
141
|
+
isCI: boolean
|
|
142
|
+
portOffset: number
|
|
143
|
+
localIp: string
|
|
144
|
+
exec(cmd: string, opts?): Promise<ExecResult>
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Watchdog Auto-Shutdown
|
|
149
|
+
|
|
150
|
+
Containers automatically stop after 10 minutes of inactivity when running via CLI.
|
|
151
|
+
|
|
152
|
+
## CLI Reference
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
COMMANDS:
|
|
156
|
+
dev Start the development environment
|
|
157
|
+
prisma <args> Run Prisma CLI with correct DATABASE_URL
|
|
158
|
+
env Print environment info as JSON
|
|
159
|
+
help Show help
|
|
160
|
+
version Show version
|
|
161
|
+
|
|
162
|
+
DEV OPTIONS:
|
|
163
|
+
--up-only Start containers only (no dev servers)
|
|
164
|
+
--down Stop containers
|
|
165
|
+
--reset Stop containers and remove volumes
|
|
166
|
+
--migrate Run migrations only
|
|
167
|
+
--seed Run seeders
|
|
168
|
+
--lint Run typecheck (no Docker required)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Environment Variables
|
|
172
|
+
|
|
173
|
+
The `envVars` function receives:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
envVars: (ports, urls, context) => ({
|
|
177
|
+
// ports: { postgres: 5432, api: 3000, ... }
|
|
178
|
+
// urls: { postgres: "postgresql://...", ... }
|
|
179
|
+
// context: { localIp, portOffset, isCI, root }
|
|
180
|
+
})
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
These are injected into:
|
|
184
|
+
- Docker Compose (via `COMPOSE_PROJECT_NAME`)
|
|
185
|
+
- Dev server processes
|
|
186
|
+
- Hook `exec()` calls
|
|
187
|
+
|
|
188
|
+
## Docker Compose
|
|
189
|
+
|
|
190
|
+
Your `docker-compose.yml` should use environment variables for ports:
|
|
191
|
+
|
|
192
|
+
```yaml
|
|
193
|
+
services:
|
|
194
|
+
postgres:
|
|
195
|
+
image: postgres:16
|
|
196
|
+
ports:
|
|
197
|
+
- "${POSTGRES_PORT:-5432}:5432"
|
|
198
|
+
```
|