buncargo 1.0.22 → 1.0.23

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/dist/bin.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  } from "./index-qzwpzjbx.js";
5
5
  import {
6
6
  loadDevEnv
7
- } from "./index-3h3dhtf2.js";
8
- import"./index-wz9x8g7z.js";
7
+ } from "./index-qqmms8rs.js";
8
+ import"./index-x249gyde.js";
9
9
  import"./index-ggq3yryx.js";
10
10
  import"./index-1yvbwj4k.js";
11
11
  import"./index-tjqw9vtj.js";
@@ -22,7 +22,7 @@ import {
22
22
  var require_package = __commonJS((exports, module) => {
23
23
  module.exports = {
24
24
  name: "buncargo",
25
- version: "1.0.22",
25
+ version: "1.0.23",
26
26
  description: "A Bun-powered development environment CLI for managing Docker Compose services, dev servers, and environment variables",
27
27
  type: "module",
28
28
  module: "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createDevEnvironment
3
- } from "./index-wz9x8g7z.js";
3
+ } from "./index-x249gyde.js";
4
4
  import"./index-ggq3yryx.js";
5
5
  import"./index-1yvbwj4k.js";
6
6
  import"./index-tjqw9vtj.js";
@@ -0,0 +1,58 @@
1
+ import {
2
+ createDevEnvironment
3
+ } from "./index-x249gyde.js";
4
+
5
+ // loader.ts
6
+ import { existsSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ var CONFIG_FILES = [
9
+ "dev.config.ts",
10
+ "dev.config.js",
11
+ "dev-tools.config.ts",
12
+ "dev-tools.config.js"
13
+ ];
14
+ function findConfigFile(startDir) {
15
+ let currentDir = startDir;
16
+ while (true) {
17
+ for (const file of CONFIG_FILES) {
18
+ const configPath = join(currentDir, file);
19
+ if (existsSync(configPath)) {
20
+ return configPath;
21
+ }
22
+ }
23
+ const parentDir = dirname(currentDir);
24
+ if (parentDir === currentDir) {
25
+ return null;
26
+ }
27
+ currentDir = parentDir;
28
+ }
29
+ }
30
+ var cachedEnv = null;
31
+ async function loadDevEnv(options) {
32
+ if (cachedEnv && !options?.reload) {
33
+ return cachedEnv;
34
+ }
35
+ const cwd = options?.cwd ?? process.cwd();
36
+ const configPath = findConfigFile(cwd);
37
+ if (configPath) {
38
+ const mod = await import(configPath);
39
+ const config = mod.default;
40
+ if (!config?.projectPrefix || !config?.services) {
41
+ throw new Error(`Invalid config in "${configPath}". Use defineDevConfig() and export as default.`);
42
+ }
43
+ cachedEnv = createDevEnvironment(config);
44
+ return cachedEnv;
45
+ }
46
+ throw new Error(`No config file found. Create dev.config.ts with: export default defineDevConfig({ ... })`);
47
+ }
48
+ function getDevEnv() {
49
+ if (!cachedEnv) {
50
+ throw new Error("Dev environment not loaded. Call loadDevEnv() first.");
51
+ }
52
+ return cachedEnv;
53
+ }
54
+ function clearDevEnvCache() {
55
+ cachedEnv = null;
56
+ }
57
+
58
+ export { CONFIG_FILES, findConfigFile, loadDevEnv, getDevEnv, clearDevEnvCache };
@@ -0,0 +1,399 @@
1
+ import {
2
+ spawnWatchdog,
3
+ startHeartbeat,
4
+ stopHeartbeat,
5
+ stopWatchdog
6
+ } from "./index-ggq3yryx.js";
7
+ import {
8
+ buildApps,
9
+ execAsync,
10
+ startDevServers,
11
+ stopProcess
12
+ } from "./index-1yvbwj4k.js";
13
+ import {
14
+ assertValidConfig
15
+ } from "./index-tjqw9vtj.js";
16
+ import {
17
+ createPrismaRunner
18
+ } from "./index-5hka0tff.js";
19
+ import {
20
+ areContainersRunning,
21
+ startContainers,
22
+ stopContainers,
23
+ waitForAllServices
24
+ } from "./index-2fr3g85b.js";
25
+ import {
26
+ getLocalIp,
27
+ isCI,
28
+ logExpoApiUrl,
29
+ logFrontendPort,
30
+ waitForDevServers,
31
+ waitForServer
32
+ } from "./index-6fm7mvwj.js";
33
+ import {
34
+ calculatePortOffset,
35
+ computePorts,
36
+ computeUrls,
37
+ findMonorepoRoot,
38
+ getProjectName,
39
+ isWorktree
40
+ } from "./index-08wa79cs.js";
41
+
42
+ // environment.ts
43
+ import pc from "picocolors";
44
+ function formatUrl(url) {
45
+ return pc.cyan(url.replace(/:(\d+)(\/?)/, (_, port, slash) => `:${pc.bold(port)}${slash}`));
46
+ }
47
+ function formatLabel(label, value, arrow = "➜") {
48
+ return ` ${pc.green(arrow)} ${pc.bold(label.padEnd(10))} ${value}`;
49
+ }
50
+ function formatDimLabel(label, value) {
51
+ return ` ${pc.dim("•")} ${pc.dim(label.padEnd(10))} ${pc.dim(value)}`;
52
+ }
53
+ function createDevEnvironment(config, options = {}) {
54
+ assertValidConfig(config);
55
+ const root = findMonorepoRoot();
56
+ const suffix = options.suffix;
57
+ const worktree = isWorktree(root);
58
+ const portOffset = calculatePortOffset(suffix, root);
59
+ const projectName = getProjectName(config.projectPrefix, suffix, root);
60
+ const localIp = getLocalIp();
61
+ const services = config.services;
62
+ const apps = config.apps ?? {};
63
+ const ports = computePorts(services, apps, portOffset);
64
+ const urls = computeUrls(services, apps, ports, localIp);
65
+ function buildEnvVars(production = false) {
66
+ const baseEnv = {
67
+ COMPOSE_PROJECT_NAME: projectName,
68
+ NODE_ENV: production ? "production" : "development"
69
+ };
70
+ for (const [name, port] of Object.entries(ports)) {
71
+ const envName = `${name.toUpperCase()}_PORT`;
72
+ baseEnv[envName] = String(port);
73
+ }
74
+ for (const [name, url] of Object.entries(urls)) {
75
+ const envName = `${name.toUpperCase()}_URL`;
76
+ baseEnv[envName] = url;
77
+ }
78
+ if (config.envVars) {
79
+ const userEnv = config.envVars(ports, urls, {
80
+ projectName,
81
+ localIp,
82
+ portOffset
83
+ });
84
+ for (const [key, value] of Object.entries(userEnv)) {
85
+ baseEnv[key] = String(value);
86
+ }
87
+ }
88
+ return baseEnv;
89
+ }
90
+ let hookContext = null;
91
+ function getHookContext() {
92
+ if (!hookContext) {
93
+ hookContext = {
94
+ projectName,
95
+ ports,
96
+ urls,
97
+ root,
98
+ isCI: isCI(),
99
+ portOffset,
100
+ localIp,
101
+ exec: async (cmd, opts) => {
102
+ const envVars = buildEnvVars();
103
+ return execAsync(cmd, root, envVars, opts);
104
+ }
105
+ };
106
+ }
107
+ return hookContext;
108
+ }
109
+ function exec(cmd, options2) {
110
+ const envVars = buildEnvVars();
111
+ return execAsync(cmd, root, envVars, options2);
112
+ }
113
+ async function start(startOptions = {}) {
114
+ const isCI2 = process.env.CI === "true";
115
+ const {
116
+ verbose = config.options?.verbose ?? true,
117
+ wait = true,
118
+ startServers: shouldStartServers = true,
119
+ productionBuild = isCI2
120
+ } = startOptions;
121
+ const envVars = buildEnvVars(productionBuild);
122
+ if (verbose) {
123
+ logInfo(productionBuild ? "Production Environment" : "Dev Environment");
124
+ }
125
+ const serviceCount = Object.keys(services).length;
126
+ const alreadyRunning = await areContainersRunning(projectName, serviceCount);
127
+ if (alreadyRunning) {
128
+ if (verbose)
129
+ console.log("✓ Containers already running");
130
+ } else {
131
+ startContainers(root, projectName, envVars, {
132
+ verbose,
133
+ wait,
134
+ composeFile: config.options?.composeFile
135
+ });
136
+ }
137
+ if (wait) {
138
+ await waitForAllServices(services, ports, {
139
+ verbose,
140
+ projectName,
141
+ root
142
+ });
143
+ }
144
+ const allMigrations = [
145
+ ...config.prisma ? [
146
+ {
147
+ name: "prisma",
148
+ command: "bunx prisma migrate deploy",
149
+ cwd: config.prisma.cwd ?? "packages/prisma"
150
+ }
151
+ ] : [],
152
+ ...config.migrations ?? []
153
+ ];
154
+ if (allMigrations.length > 0) {
155
+ if (verbose)
156
+ console.log("\uD83D\uDCE6 Running migrations...");
157
+ const migrationResults = await Promise.all(allMigrations.map(async (migration) => {
158
+ const result = await exec(migration.command, {
159
+ cwd: migration.cwd,
160
+ throwOnError: false
161
+ });
162
+ return { name: migration.name, result };
163
+ }));
164
+ for (const { name, result } of migrationResults) {
165
+ if (result.exitCode !== 0) {
166
+ console.error(`❌ Migration "${name}" failed`);
167
+ if (result.stdout) {
168
+ console.error(result.stdout);
169
+ }
170
+ if (result.stderr) {
171
+ console.error(result.stderr);
172
+ }
173
+ throw new Error(`Migration "${name}" failed`);
174
+ }
175
+ }
176
+ if (verbose)
177
+ console.log("✓ Migrations complete");
178
+ }
179
+ if (config.hooks?.afterContainersReady) {
180
+ await config.hooks.afterContainersReady(getHookContext());
181
+ }
182
+ if (config.seed) {
183
+ let shouldSeed = true;
184
+ if (config.seed.check) {
185
+ const checkTable = async (tableName, service) => {
186
+ const serviceName = service ?? "postgres";
187
+ const serviceUrl = urls[serviceName];
188
+ if (!serviceUrl) {
189
+ console.warn(`⚠️ Service "${serviceName}" not found for checkTable`);
190
+ return true;
191
+ }
192
+ const checkResult = await exec(`psql "${serviceUrl}" -tAc 'SELECT COUNT(*) FROM "${tableName}" LIMIT 1'`, { throwOnError: false });
193
+ const count = checkResult.stdout.trim();
194
+ const shouldSeed2 = checkResult.exitCode !== 0 || count === "0" || count === "";
195
+ if (!shouldSeed2) {
196
+ console.log(` \uD83D\uDCCA Table "${tableName}" has ${count} rows`);
197
+ }
198
+ return shouldSeed2;
199
+ };
200
+ const seedCheckContext = {
201
+ ...getHookContext(),
202
+ checkTable
203
+ };
204
+ shouldSeed = await config.seed.check(seedCheckContext);
205
+ }
206
+ if (shouldSeed) {
207
+ if (verbose)
208
+ console.log("\uD83C\uDF31 Running seeders...");
209
+ const seedResult = await exec(config.seed.command, {
210
+ cwd: config.seed.cwd,
211
+ verbose,
212
+ throwOnError: false
213
+ });
214
+ if (seedResult.exitCode !== 0) {
215
+ console.error("❌ Seeding failed");
216
+ console.error(seedResult.stderr);
217
+ } else {
218
+ if (verbose)
219
+ console.log("✓ Seeding complete");
220
+ }
221
+ } else {
222
+ if (verbose)
223
+ console.log("✓ Database already has data, skipping seeders");
224
+ }
225
+ }
226
+ if (shouldStartServers && Object.keys(apps).length > 0) {
227
+ if (config.hooks?.beforeServers) {
228
+ await config.hooks.beforeServers(getHookContext());
229
+ }
230
+ if (productionBuild) {
231
+ buildApps(apps, root, envVars, { verbose });
232
+ }
233
+ const pids = await startDevServers(apps, root, envVars, ports, {
234
+ verbose,
235
+ productionBuild,
236
+ isCI: isCI2
237
+ });
238
+ if (verbose)
239
+ console.log("⏳ Waiting for servers to be ready...");
240
+ await waitForDevServers(apps, ports, {
241
+ timeout: isCI2 ? 120000 : 60000,
242
+ verbose,
243
+ productionBuild
244
+ });
245
+ if (config.hooks?.afterServers) {
246
+ await config.hooks.afterServers(getHookContext());
247
+ }
248
+ if (verbose)
249
+ console.log(`✅ Environment ready
250
+ `);
251
+ return pids;
252
+ }
253
+ if (verbose)
254
+ console.log(`✅ Containers ready
255
+ `);
256
+ return null;
257
+ }
258
+ async function stop(stopOptions = {}) {
259
+ const { verbose = true, removeVolumes = false } = stopOptions;
260
+ if (config.hooks?.beforeStop) {
261
+ await config.hooks.beforeStop(getHookContext());
262
+ }
263
+ stopContainers(root, projectName, {
264
+ verbose,
265
+ removeVolumes,
266
+ composeFile: config.options?.composeFile
267
+ });
268
+ }
269
+ async function restart() {
270
+ await stop();
271
+ await start({ startServers: false });
272
+ }
273
+ async function isRunning() {
274
+ const serviceCount = Object.keys(services).length;
275
+ return areContainersRunning(projectName, serviceCount);
276
+ }
277
+ async function startServersOnly(options2 = {}) {
278
+ const { productionBuild = false, verbose = true } = options2;
279
+ const envVars = buildEnvVars(productionBuild);
280
+ const isCI2 = process.env.CI === "true";
281
+ if (productionBuild) {
282
+ buildApps(apps, root, envVars, { verbose });
283
+ }
284
+ return startDevServers(apps, root, envVars, ports, {
285
+ verbose,
286
+ productionBuild,
287
+ isCI: isCI2
288
+ });
289
+ }
290
+ async function waitForServersReady(options2 = {}) {
291
+ const { timeout = 60000, productionBuild = false } = options2;
292
+ await waitForDevServers(apps, ports, { timeout, productionBuild });
293
+ }
294
+ function logInfo(label = "Docker Dev") {
295
+ const serviceNames = Object.keys(services);
296
+ const appNames = Object.keys(apps);
297
+ console.log("");
298
+ console.log(` ${pc.cyan(pc.bold(`\uD83D\uDC33 ${label}`))}`);
299
+ console.log(formatLabel("Project:", pc.white(projectName)));
300
+ if (serviceNames.length > 0) {
301
+ console.log("");
302
+ console.log(` ${pc.dim("─── Services ───")}`);
303
+ for (const name of serviceNames) {
304
+ const port = ports[name];
305
+ const url = `localhost:${port}`;
306
+ console.log(formatLabel(`${name}:`, formatUrl(`http://${url}`)));
307
+ }
308
+ }
309
+ if (appNames.length > 0) {
310
+ console.log("");
311
+ console.log(` ${pc.dim("─── Applications ───")}`);
312
+ for (const name of appNames) {
313
+ const port = ports[name];
314
+ const localUrl = `http://localhost:${port}`;
315
+ const networkUrl = `http://${localIp}:${port}`;
316
+ console.log(` ${pc.green("➜")} ${pc.bold(pc.cyan(name))}`);
317
+ console.log(` ${pc.dim("Local:")} ${formatUrl(localUrl)}`);
318
+ console.log(` ${pc.dim("Network:")} ${formatUrl(networkUrl)}`);
319
+ }
320
+ }
321
+ console.log("");
322
+ console.log(` ${pc.dim("─── Environment ───")}`);
323
+ console.log(formatDimLabel("Worktree:", worktree ? "yes" : "no"));
324
+ console.log(formatDimLabel("Port offset:", portOffset > 0 ? `+${portOffset}` : "none"));
325
+ if (suffix) {
326
+ console.log(formatDimLabel("Suffix:", suffix));
327
+ }
328
+ console.log(formatDimLabel("Local IP:", localIp));
329
+ console.log("");
330
+ }
331
+ async function waitForServerUrl(url, timeout) {
332
+ await waitForServer(url, { timeout });
333
+ }
334
+ function startHeartbeat2(intervalMs) {
335
+ startHeartbeat(projectName, intervalMs);
336
+ }
337
+ function stopHeartbeat2() {
338
+ stopHeartbeat();
339
+ }
340
+ async function spawnWatchdog2(timeoutMinutes) {
341
+ await spawnWatchdog(projectName, root, {
342
+ timeoutMinutes,
343
+ verbose: true,
344
+ composeFile: config.options?.composeFile
345
+ });
346
+ }
347
+ function stopWatchdog2() {
348
+ stopWatchdog(projectName);
349
+ }
350
+ function getExpoApiUrl() {
351
+ const apiPort = ports.api;
352
+ const url = `http://${localIp}:${apiPort}`;
353
+ logExpoApiUrl(url);
354
+ return url;
355
+ }
356
+ function getFrontendPort() {
357
+ const port = ports.platform;
358
+ logFrontendPort(port);
359
+ return port;
360
+ }
361
+ function withSuffix(newSuffix) {
362
+ return createDevEnvironment(config, { suffix: newSuffix });
363
+ }
364
+ const env = {
365
+ projectName,
366
+ ports,
367
+ urls,
368
+ apps,
369
+ portOffset,
370
+ isWorktree: worktree,
371
+ localIp,
372
+ root,
373
+ start,
374
+ stop,
375
+ restart,
376
+ isRunning,
377
+ startServers: startServersOnly,
378
+ stopProcess,
379
+ waitForServers: waitForServersReady,
380
+ buildEnvVars,
381
+ exec,
382
+ waitForServer: waitForServerUrl,
383
+ logInfo,
384
+ getExpoApiUrl,
385
+ getFrontendPort,
386
+ startHeartbeat: startHeartbeat2,
387
+ stopHeartbeat: stopHeartbeat2,
388
+ spawnWatchdog: spawnWatchdog2,
389
+ stopWatchdog: stopWatchdog2,
390
+ prisma: undefined,
391
+ withSuffix
392
+ };
393
+ if (config.prisma) {
394
+ env.prisma = createPrismaRunner(env, config.prisma);
395
+ }
396
+ return env;
397
+ }
398
+
399
+ export { createDevEnvironment };
package/dist/index.js CHANGED
@@ -10,10 +10,10 @@ import {
10
10
  clearDevEnvCache,
11
11
  getDevEnv,
12
12
  loadDevEnv
13
- } from "./index-3h3dhtf2.js";
13
+ } from "./index-qqmms8rs.js";
14
14
  import {
15
15
  createDevEnvironment
16
- } from "./index-wz9x8g7z.js";
16
+ } from "./index-x249gyde.js";
17
17
  import {
18
18
  getHeartbeatFile,
19
19
  getWatchdogPidFile,
package/dist/loader.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  findConfigFile,
5
5
  getDevEnv,
6
6
  loadDevEnv
7
- } from "./index-3h3dhtf2.js";
8
- import"./index-wz9x8g7z.js";
7
+ } from "./index-qqmms8rs.js";
8
+ import"./index-x249gyde.js";
9
9
  import"./index-ggq3yryx.js";
10
10
  import"./index-1yvbwj4k.js";
11
11
  import"./index-tjqw9vtj.js";
package/environment.ts CHANGED
@@ -265,14 +265,19 @@ export function createDevEnvironment<
265
265
  }),
266
266
  );
267
267
 
268
- // Check for failures
269
- for (const { name, result } of migrationResults) {
270
- if (result.exitCode !== 0) {
271
- console.error(`❌ Migration "${name}" failed`);
268
+ // Check for failures
269
+ for (const { name, result } of migrationResults) {
270
+ if (result.exitCode !== 0) {
271
+ console.error(`❌ Migration "${name}" failed`);
272
+ if (result.stdout) {
273
+ console.error(result.stdout);
274
+ }
275
+ if (result.stderr) {
272
276
  console.error(result.stderr);
273
- throw new Error(`Migration "${name}" failed`);
274
277
  }
278
+ throw new Error(`Migration "${name}" failed`);
275
279
  }
280
+ }
276
281
 
277
282
  if (verbose) console.log("✓ Migrations complete");
278
283
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buncargo",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "A Bun-powered development environment CLI for managing Docker Compose services, dev servers, and environment variables",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",