buncargo 3.2.4 → 3.2.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/dist/cli/bin.js +5 -5
- package/dist/cli/index.js +2 -2
- package/dist/core/quick-tunnel/cloudflared-process.d.ts +2 -0
- package/dist/core/quick-tunnel/constants.d.ts +2 -0
- package/dist/core/quick-tunnel/index.d.ts +4 -3
- package/dist/environment/index.js +2 -2
- package/dist/index-39s6ez1q.js +250 -0
- package/dist/index-6att53sd.js +250 -0
- package/dist/index-94kgbw4m.js +72 -0
- package/dist/index-96q4yh56.js +72 -0
- package/dist/index-bgcx898h.js +451 -0
- package/dist/index-c28x1pjb.js +250 -0
- package/dist/index-gfs10vb8.js +389 -0
- package/dist/index-pbwvaz4v.js +666 -0
- package/dist/index-pmbmwg3x.js +72 -0
- package/dist/index-pt8t9tkg.js +389 -0
- package/dist/index-qnpd5fn5.js +666 -0
- package/dist/index-qtprmjbm.js +399 -0
- package/dist/index-thsdxz7m.js +250 -0
- package/dist/index-ymdvr5sn.js +666 -0
- package/dist/index-yw46g4tr.js +666 -0
- package/dist/index-znaek8z2.js +72 -0
- package/dist/index.js +4 -4
- package/dist/loader/index.js +3 -3
- package/package.json +1 -1
- package/src/core/quick-tunnel/cloudflared-process.ts +40 -2
- package/src/core/quick-tunnel/constants.ts +14 -1
- package/src/core/quick-tunnel/index.ts +53 -49
- package/src/core/quick-tunnel/install.ts +1 -1
- package/src/core/tunnel.ts +1 -1
package/dist/cli/bin.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import {
|
|
3
3
|
runCli
|
|
4
|
-
} from "../index-
|
|
4
|
+
} from "../index-c28x1pjb.js";
|
|
5
5
|
import {
|
|
6
6
|
loadDevEnv
|
|
7
|
-
} from "../index-
|
|
8
|
-
import"../index-
|
|
7
|
+
} from "../index-znaek8z2.js";
|
|
8
|
+
import"../index-ymdvr5sn.js";
|
|
9
9
|
import"../index-twwcjn9p.js";
|
|
10
10
|
import"../index-5t9jxqm0.js";
|
|
11
|
-
import"../index-
|
|
11
|
+
import"../index-bgcx898h.js";
|
|
12
12
|
import"../index-mam0bcyz.js";
|
|
13
13
|
import"../index-mm412dkp.js";
|
|
14
14
|
import"../index-fkgqg6w2.js";
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
var require_package = __commonJS((exports, module) => {
|
|
24
24
|
module.exports = {
|
|
25
25
|
name: "buncargo",
|
|
26
|
-
version: "3.2.
|
|
26
|
+
version: "3.2.5",
|
|
27
27
|
description: "A Bun-powered development environment CLI for managing Docker Compose services, dev servers, and environment variables",
|
|
28
28
|
type: "module",
|
|
29
29
|
module: "./dist/index.js",
|
package/dist/cli/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
getFlagValue,
|
|
3
3
|
hasFlag,
|
|
4
4
|
runCli
|
|
5
|
-
} from "../index-
|
|
6
|
-
import"../index-
|
|
5
|
+
} from "../index-c28x1pjb.js";
|
|
6
|
+
import"../index-bgcx898h.js";
|
|
7
7
|
import"../index-mam0bcyz.js";
|
|
8
8
|
import"../index-mm412dkp.js";
|
|
9
9
|
import"../index-fkgqg6w2.js";
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Derived from unjs/untun (MIT), originally forked from node-cloudflared.
|
|
4
4
|
*/
|
|
5
5
|
import { type ChildProcess } from "node:child_process";
|
|
6
|
+
/** Default 30s; set `BUNCARGO_QUICK_TUNNEL_TIMEOUT_MS=0` to disable. */
|
|
7
|
+
export declare function resolveQuickTunnelUrlTimeoutMs(): number;
|
|
6
8
|
export declare function parseQuickTunnelUrlFromOutput(log: string): string | null;
|
|
7
9
|
export declare function startCloudflaredTunnel(options: Record<string, string | number | null>): {
|
|
8
10
|
url: Promise<string>;
|
|
@@ -6,4 +6,6 @@ export declare const CLOUDFLARED_VERSION: string;
|
|
|
6
6
|
export declare const RELEASE_BASE = "https://github.com/cloudflare/cloudflared/releases/";
|
|
7
7
|
/** Directory for buncargo-managed cloudflared (avoid clashing with untun's node-untun). */
|
|
8
8
|
export declare const cloudflaredBinPath: string;
|
|
9
|
+
/** Spawn/install target: optional `BUNCARGO_CLOUDFLARED_PATH` overrides the bundled cache path. */
|
|
10
|
+
export declare function resolvedCloudflaredBinPath(): string;
|
|
9
11
|
export declare const cloudflaredNotice = "\n\uD83D\uDD25 Your installation of cloudflared software constitutes a symbol of your signature\n indicating that you accept the terms of the Cloudflare License, Terms and Privacy Policy.\n\n\u276F License: `https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/license/`\n\u276F Terms: `https://www.cloudflare.com/terms/`\n\u276F Privacy Policy: `https://www.cloudflare.com/privacypolicy/`\n";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
/** True when trycloudflare.com is overloaded / rate-limited or returns non-JSON (cloudflared then errors on unmarshal). */
|
|
2
|
+
export declare function isRetryableQuickTunnelError(message: string): boolean;
|
|
1
3
|
export interface QuickTunnelOptions {
|
|
2
4
|
url?: string;
|
|
3
5
|
port?: number | string;
|
|
4
6
|
hostname?: string;
|
|
5
7
|
protocol?: "http" | "https";
|
|
6
8
|
verifyTLS?: boolean;
|
|
7
|
-
acceptCloudflareNotice?: boolean;
|
|
8
9
|
}
|
|
9
10
|
export interface QuickTunnel {
|
|
10
11
|
getURL: () => Promise<string>;
|
|
@@ -12,6 +13,6 @@ export interface QuickTunnel {
|
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Start a Cloudflare quick tunnel to a local HTTP(S) URL.
|
|
15
|
-
*
|
|
16
|
+
* If the cloudflared binary is missing, prints the license notice and installs it from GitHub.
|
|
16
17
|
*/
|
|
17
|
-
export declare function startQuickTunnel(opts: QuickTunnelOptions): Promise<QuickTunnel
|
|
18
|
+
export declare function startQuickTunnel(opts: QuickTunnelOptions): Promise<QuickTunnel>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createDevEnvironment
|
|
3
|
-
} from "../index-
|
|
3
|
+
} from "../index-ymdvr5sn.js";
|
|
4
4
|
import"../index-twwcjn9p.js";
|
|
5
5
|
import"../index-5t9jxqm0.js";
|
|
6
|
-
import"../index-
|
|
6
|
+
import"../index-bgcx898h.js";
|
|
7
7
|
import"../index-mam0bcyz.js";
|
|
8
8
|
import"../index-mm412dkp.js";
|
|
9
9
|
import"../index-fkgqg6w2.js";
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveExposeTargets,
|
|
3
|
+
startPublicTunnels,
|
|
4
|
+
stopPublicTunnels
|
|
5
|
+
} from "./index-gfs10vb8.js";
|
|
6
|
+
import {
|
|
7
|
+
spawnWatchdog,
|
|
8
|
+
startHeartbeat,
|
|
9
|
+
stopHeartbeat
|
|
10
|
+
} from "./index-mam0bcyz.js";
|
|
11
|
+
import {
|
|
12
|
+
killProcessesOnAppPorts
|
|
13
|
+
} from "./index-mm412dkp.js";
|
|
14
|
+
|
|
15
|
+
// src/cli/run-cli.ts
|
|
16
|
+
import { spawn } from "node:child_process";
|
|
17
|
+
var ACCEPTED_FLAGS = [
|
|
18
|
+
"--help",
|
|
19
|
+
"--down",
|
|
20
|
+
"--reset",
|
|
21
|
+
"--migrate",
|
|
22
|
+
"--seed",
|
|
23
|
+
"--up-only",
|
|
24
|
+
"--expose"
|
|
25
|
+
];
|
|
26
|
+
function printHelp() {
|
|
27
|
+
console.log(`
|
|
28
|
+
Usage: buncargo dev [options]
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
--help Show this help message
|
|
32
|
+
--down Stop all containers
|
|
33
|
+
--reset Stop containers and remove volumes (fresh start)
|
|
34
|
+
--migrate Run migrations and exit
|
|
35
|
+
--seed Run migrations and seeders, then exit
|
|
36
|
+
--up-only Start containers and run migrations, then exit (no dev servers)
|
|
37
|
+
--expose Expose configured targets via public quick tunnels
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
bun dev Start dev environment with all services
|
|
41
|
+
bun dev --seed Run migrations and seed the database
|
|
42
|
+
bun dev --down Stop all containers
|
|
43
|
+
bun dev --reset Stop containers and remove all data
|
|
44
|
+
bun dev --expose Expose all targets with expose: true
|
|
45
|
+
bun dev --expose=api,web Expose specific targets
|
|
46
|
+
`);
|
|
47
|
+
}
|
|
48
|
+
function getUnknownFlags(args) {
|
|
49
|
+
return args.filter((arg) => arg.startsWith("--") && !ACCEPTED_FLAGS.includes(arg.includes("=") ? arg.split("=")[0] : arg));
|
|
50
|
+
}
|
|
51
|
+
async function runCli(env, options = {}) {
|
|
52
|
+
const {
|
|
53
|
+
args = process.argv.slice(2),
|
|
54
|
+
watchdog = true,
|
|
55
|
+
watchdogTimeout = 10,
|
|
56
|
+
devServersCommand,
|
|
57
|
+
cliTestTunnel
|
|
58
|
+
} = options;
|
|
59
|
+
const tunnelApi = cliTestTunnel ?? {
|
|
60
|
+
resolveExposeTargets,
|
|
61
|
+
startPublicTunnels,
|
|
62
|
+
stopPublicTunnels
|
|
63
|
+
};
|
|
64
|
+
const exposeRequested = hasFlag(args, "--expose");
|
|
65
|
+
const exposeValue = getFlagValue(args, "--expose");
|
|
66
|
+
let tunnels = [];
|
|
67
|
+
async function cleanupTunnels() {
|
|
68
|
+
env.clearPublicUrls();
|
|
69
|
+
if (tunnels.length === 0)
|
|
70
|
+
return;
|
|
71
|
+
await tunnelApi.stopPublicTunnels(tunnels);
|
|
72
|
+
tunnels = [];
|
|
73
|
+
}
|
|
74
|
+
if (args.includes("--help")) {
|
|
75
|
+
printHelp();
|
|
76
|
+
process.exit(0);
|
|
77
|
+
}
|
|
78
|
+
const unknownFlags = getUnknownFlags(args);
|
|
79
|
+
if (unknownFlags.length > 0) {
|
|
80
|
+
console.error(`❌ Unknown flag${unknownFlags.length > 1 ? "s" : ""}: ${unknownFlags.join(", ")}`);
|
|
81
|
+
console.error("");
|
|
82
|
+
printHelp();
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
if (args.includes("--down")) {
|
|
86
|
+
env.logInfo();
|
|
87
|
+
await cleanupTunnels();
|
|
88
|
+
await env.stop();
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
if (args.includes("--reset")) {
|
|
92
|
+
env.logInfo();
|
|
93
|
+
await cleanupTunnels();
|
|
94
|
+
await env.stop({ removeVolumes: true });
|
|
95
|
+
process.exit(0);
|
|
96
|
+
}
|
|
97
|
+
const skipSeed = args.includes("--seed");
|
|
98
|
+
await env.start({
|
|
99
|
+
startServers: false,
|
|
100
|
+
wait: true,
|
|
101
|
+
skipSeed,
|
|
102
|
+
skipEnvironmentLog: exposeRequested
|
|
103
|
+
});
|
|
104
|
+
if (exposeRequested) {
|
|
105
|
+
const { targets, unknownNames, notEnabledNames } = tunnelApi.resolveExposeTargets(env, exposeValue);
|
|
106
|
+
if (unknownNames.length > 0) {
|
|
107
|
+
console.error(`❌ Unknown expose target${unknownNames.length > 1 ? "s" : ""}: ${unknownNames.join(", ")}`);
|
|
108
|
+
await cleanupTunnels();
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
if (notEnabledNames.length > 0) {
|
|
112
|
+
console.error(`❌ Target${notEnabledNames.length > 1 ? "s" : ""} missing expose: true: ${notEnabledNames.join(", ")}`);
|
|
113
|
+
console.error(" Mark these in dev.config.ts with expose: true or remove them from --expose.");
|
|
114
|
+
await cleanupTunnels();
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
if (targets.length === 0) {
|
|
118
|
+
console.error("❌ No expose targets selected. Add expose: true to services/apps or pass names with --expose=<name>.");
|
|
119
|
+
await cleanupTunnels();
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
tunnels = await tunnelApi.startPublicTunnels(targets);
|
|
123
|
+
env.setPublicUrls(Object.fromEntries(tunnels.map((tunnel) => [tunnel.name, tunnel.publicUrl])));
|
|
124
|
+
env.logInfo("Dev Environment", tunnels);
|
|
125
|
+
}
|
|
126
|
+
if (args.includes("--migrate")) {
|
|
127
|
+
console.log("");
|
|
128
|
+
console.log("✅ Migrations applied successfully");
|
|
129
|
+
await cleanupTunnels();
|
|
130
|
+
process.exit(0);
|
|
131
|
+
}
|
|
132
|
+
if (args.includes("--seed")) {
|
|
133
|
+
console.log("\uD83C\uDF31 Running seeders...");
|
|
134
|
+
const result = await env.exec("bun run run:seeder", {
|
|
135
|
+
throwOnError: false
|
|
136
|
+
});
|
|
137
|
+
if (result.exitCode !== 0) {
|
|
138
|
+
console.error("❌ Seeding failed");
|
|
139
|
+
if (result.stderr) {
|
|
140
|
+
console.error(result.stderr);
|
|
141
|
+
}
|
|
142
|
+
if (result.stdout) {
|
|
143
|
+
console.error(result.stdout);
|
|
144
|
+
}
|
|
145
|
+
await cleanupTunnels();
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
148
|
+
console.log("");
|
|
149
|
+
console.log("✅ Seeding complete");
|
|
150
|
+
await cleanupTunnels();
|
|
151
|
+
process.exit(0);
|
|
152
|
+
}
|
|
153
|
+
if (args.includes("--up-only")) {
|
|
154
|
+
console.log("");
|
|
155
|
+
console.log("✅ Containers started. Environment ready.");
|
|
156
|
+
console.log("");
|
|
157
|
+
await cleanupTunnels();
|
|
158
|
+
process.exit(0);
|
|
159
|
+
}
|
|
160
|
+
if (watchdog) {
|
|
161
|
+
await spawnWatchdog(env.projectName, env.root, {
|
|
162
|
+
timeoutMinutes: watchdogTimeout,
|
|
163
|
+
verbose: true,
|
|
164
|
+
composeFile: env.composeFile
|
|
165
|
+
});
|
|
166
|
+
startHeartbeat(env.projectName);
|
|
167
|
+
}
|
|
168
|
+
const command = devServersCommand ?? buildDevServersCommand(env.apps);
|
|
169
|
+
if (!command) {
|
|
170
|
+
console.log("✅ Containers ready. No apps configured.");
|
|
171
|
+
await new Promise(() => {});
|
|
172
|
+
await cleanupTunnels();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
await killProcessesOnAppPorts(env.apps, env.ports);
|
|
176
|
+
console.log("");
|
|
177
|
+
console.log("\uD83D\uDD27 Starting dev servers...");
|
|
178
|
+
console.log("");
|
|
179
|
+
await runCommand(command, env.root, env.buildEnvVars(), {
|
|
180
|
+
onSignal: async () => {
|
|
181
|
+
await cleanupTunnels();
|
|
182
|
+
stopHeartbeat();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
stopHeartbeat();
|
|
186
|
+
await cleanupTunnels();
|
|
187
|
+
}
|
|
188
|
+
function buildDevServersCommand(apps) {
|
|
189
|
+
const appEntries = Object.entries(apps);
|
|
190
|
+
if (appEntries.length === 0)
|
|
191
|
+
return null;
|
|
192
|
+
const commands = [];
|
|
193
|
+
const names = [];
|
|
194
|
+
const colors = ["blue", "green", "yellow", "magenta", "cyan", "red"];
|
|
195
|
+
for (const [name, config] of appEntries) {
|
|
196
|
+
names.push(name);
|
|
197
|
+
const cwdPart = config.cwd ? `--cwd ${config.cwd}` : "";
|
|
198
|
+
commands.push(`"bun run ${cwdPart} ${config.devCommand}"`.replace(/\s+/g, " ").trim());
|
|
199
|
+
}
|
|
200
|
+
const namesArg = `-n ${names.join(",")}`;
|
|
201
|
+
const colorsArg = `-c ${colors.slice(0, names.length).join(",")}`;
|
|
202
|
+
const commandsArg = commands.join(" ");
|
|
203
|
+
return `bun concurrently ${namesArg} ${colorsArg} ${commandsArg}`;
|
|
204
|
+
}
|
|
205
|
+
function runCommand(command, cwd, envVars, options = {}) {
|
|
206
|
+
const { onSignal } = options;
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
const proc = spawn(command, [], {
|
|
209
|
+
cwd,
|
|
210
|
+
env: { ...process.env, ...envVars },
|
|
211
|
+
stdio: "inherit",
|
|
212
|
+
shell: true
|
|
213
|
+
});
|
|
214
|
+
proc.on("close", (code) => {
|
|
215
|
+
if (code === 0 || code === null) {
|
|
216
|
+
resolve();
|
|
217
|
+
} else {
|
|
218
|
+
reject(new Error(`Command exited with code ${code}`));
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
proc.on("error", reject);
|
|
222
|
+
const cleanup = () => {
|
|
223
|
+
if (onSignal) {
|
|
224
|
+
onSignal();
|
|
225
|
+
}
|
|
226
|
+
proc.kill("SIGTERM");
|
|
227
|
+
};
|
|
228
|
+
process.on("SIGINT", cleanup);
|
|
229
|
+
process.on("SIGTERM", cleanup);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function hasFlag(args, flag) {
|
|
233
|
+
return args.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
|
|
234
|
+
}
|
|
235
|
+
function getFlagValue(args, flag) {
|
|
236
|
+
const prefixed = args.find((arg) => arg.startsWith(`${flag}=`));
|
|
237
|
+
if (prefixed) {
|
|
238
|
+
return prefixed.split("=")[1];
|
|
239
|
+
}
|
|
240
|
+
const index = args.indexOf(flag);
|
|
241
|
+
if (index !== -1 && index + 1 < args.length) {
|
|
242
|
+
const nextArg = args[index + 1];
|
|
243
|
+
if (nextArg !== undefined && !nextArg.startsWith("-")) {
|
|
244
|
+
return nextArg;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export { runCli, hasFlag, getFlagValue };
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveExposeTargets,
|
|
3
|
+
startPublicTunnels,
|
|
4
|
+
stopPublicTunnels
|
|
5
|
+
} from "./index-pt8t9tkg.js";
|
|
6
|
+
import {
|
|
7
|
+
spawnWatchdog,
|
|
8
|
+
startHeartbeat,
|
|
9
|
+
stopHeartbeat
|
|
10
|
+
} from "./index-mam0bcyz.js";
|
|
11
|
+
import {
|
|
12
|
+
killProcessesOnAppPorts
|
|
13
|
+
} from "./index-mm412dkp.js";
|
|
14
|
+
|
|
15
|
+
// src/cli/run-cli.ts
|
|
16
|
+
import { spawn } from "node:child_process";
|
|
17
|
+
var ACCEPTED_FLAGS = [
|
|
18
|
+
"--help",
|
|
19
|
+
"--down",
|
|
20
|
+
"--reset",
|
|
21
|
+
"--migrate",
|
|
22
|
+
"--seed",
|
|
23
|
+
"--up-only",
|
|
24
|
+
"--expose"
|
|
25
|
+
];
|
|
26
|
+
function printHelp() {
|
|
27
|
+
console.log(`
|
|
28
|
+
Usage: buncargo dev [options]
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
--help Show this help message
|
|
32
|
+
--down Stop all containers
|
|
33
|
+
--reset Stop containers and remove volumes (fresh start)
|
|
34
|
+
--migrate Run migrations and exit
|
|
35
|
+
--seed Run migrations and seeders, then exit
|
|
36
|
+
--up-only Start containers and run migrations, then exit (no dev servers)
|
|
37
|
+
--expose Expose configured targets via public quick tunnels
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
bun dev Start dev environment with all services
|
|
41
|
+
bun dev --seed Run migrations and seed the database
|
|
42
|
+
bun dev --down Stop all containers
|
|
43
|
+
bun dev --reset Stop containers and remove all data
|
|
44
|
+
bun dev --expose Expose all targets with expose: true
|
|
45
|
+
bun dev --expose=api,web Expose specific targets
|
|
46
|
+
`);
|
|
47
|
+
}
|
|
48
|
+
function getUnknownFlags(args) {
|
|
49
|
+
return args.filter((arg) => arg.startsWith("--") && !ACCEPTED_FLAGS.includes(arg.includes("=") ? arg.split("=")[0] : arg));
|
|
50
|
+
}
|
|
51
|
+
async function runCli(env, options = {}) {
|
|
52
|
+
const {
|
|
53
|
+
args = process.argv.slice(2),
|
|
54
|
+
watchdog = true,
|
|
55
|
+
watchdogTimeout = 10,
|
|
56
|
+
devServersCommand,
|
|
57
|
+
cliTestTunnel
|
|
58
|
+
} = options;
|
|
59
|
+
const tunnelApi = cliTestTunnel ?? {
|
|
60
|
+
resolveExposeTargets,
|
|
61
|
+
startPublicTunnels,
|
|
62
|
+
stopPublicTunnels
|
|
63
|
+
};
|
|
64
|
+
const exposeRequested = hasFlag(args, "--expose");
|
|
65
|
+
const exposeValue = getFlagValue(args, "--expose");
|
|
66
|
+
let tunnels = [];
|
|
67
|
+
async function cleanupTunnels() {
|
|
68
|
+
env.clearPublicUrls();
|
|
69
|
+
if (tunnels.length === 0)
|
|
70
|
+
return;
|
|
71
|
+
await tunnelApi.stopPublicTunnels(tunnels);
|
|
72
|
+
tunnels = [];
|
|
73
|
+
}
|
|
74
|
+
if (args.includes("--help")) {
|
|
75
|
+
printHelp();
|
|
76
|
+
process.exit(0);
|
|
77
|
+
}
|
|
78
|
+
const unknownFlags = getUnknownFlags(args);
|
|
79
|
+
if (unknownFlags.length > 0) {
|
|
80
|
+
console.error(`❌ Unknown flag${unknownFlags.length > 1 ? "s" : ""}: ${unknownFlags.join(", ")}`);
|
|
81
|
+
console.error("");
|
|
82
|
+
printHelp();
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
if (args.includes("--down")) {
|
|
86
|
+
env.logInfo();
|
|
87
|
+
await cleanupTunnels();
|
|
88
|
+
await env.stop();
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
if (args.includes("--reset")) {
|
|
92
|
+
env.logInfo();
|
|
93
|
+
await cleanupTunnels();
|
|
94
|
+
await env.stop({ removeVolumes: true });
|
|
95
|
+
process.exit(0);
|
|
96
|
+
}
|
|
97
|
+
const skipSeed = args.includes("--seed");
|
|
98
|
+
await env.start({
|
|
99
|
+
startServers: false,
|
|
100
|
+
wait: true,
|
|
101
|
+
skipSeed,
|
|
102
|
+
skipEnvironmentLog: exposeRequested
|
|
103
|
+
});
|
|
104
|
+
if (exposeRequested) {
|
|
105
|
+
const { targets, unknownNames, notEnabledNames } = tunnelApi.resolveExposeTargets(env, exposeValue);
|
|
106
|
+
if (unknownNames.length > 0) {
|
|
107
|
+
console.error(`❌ Unknown expose target${unknownNames.length > 1 ? "s" : ""}: ${unknownNames.join(", ")}`);
|
|
108
|
+
await cleanupTunnels();
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
if (notEnabledNames.length > 0) {
|
|
112
|
+
console.error(`❌ Target${notEnabledNames.length > 1 ? "s" : ""} missing expose: true: ${notEnabledNames.join(", ")}`);
|
|
113
|
+
console.error(" Mark these in dev.config.ts with expose: true or remove them from --expose.");
|
|
114
|
+
await cleanupTunnels();
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
if (targets.length === 0) {
|
|
118
|
+
console.error("❌ No expose targets selected. Add expose: true to services/apps or pass names with --expose=<name>.");
|
|
119
|
+
await cleanupTunnels();
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
tunnels = await tunnelApi.startPublicTunnels(targets);
|
|
123
|
+
env.setPublicUrls(Object.fromEntries(tunnels.map((tunnel) => [tunnel.name, tunnel.publicUrl])));
|
|
124
|
+
env.logInfo("Dev Environment", tunnels);
|
|
125
|
+
}
|
|
126
|
+
if (args.includes("--migrate")) {
|
|
127
|
+
console.log("");
|
|
128
|
+
console.log("✅ Migrations applied successfully");
|
|
129
|
+
await cleanupTunnels();
|
|
130
|
+
process.exit(0);
|
|
131
|
+
}
|
|
132
|
+
if (args.includes("--seed")) {
|
|
133
|
+
console.log("\uD83C\uDF31 Running seeders...");
|
|
134
|
+
const result = await env.exec("bun run run:seeder", {
|
|
135
|
+
throwOnError: false
|
|
136
|
+
});
|
|
137
|
+
if (result.exitCode !== 0) {
|
|
138
|
+
console.error("❌ Seeding failed");
|
|
139
|
+
if (result.stderr) {
|
|
140
|
+
console.error(result.stderr);
|
|
141
|
+
}
|
|
142
|
+
if (result.stdout) {
|
|
143
|
+
console.error(result.stdout);
|
|
144
|
+
}
|
|
145
|
+
await cleanupTunnels();
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
148
|
+
console.log("");
|
|
149
|
+
console.log("✅ Seeding complete");
|
|
150
|
+
await cleanupTunnels();
|
|
151
|
+
process.exit(0);
|
|
152
|
+
}
|
|
153
|
+
if (args.includes("--up-only")) {
|
|
154
|
+
console.log("");
|
|
155
|
+
console.log("✅ Containers started. Environment ready.");
|
|
156
|
+
console.log("");
|
|
157
|
+
await cleanupTunnels();
|
|
158
|
+
process.exit(0);
|
|
159
|
+
}
|
|
160
|
+
if (watchdog) {
|
|
161
|
+
await spawnWatchdog(env.projectName, env.root, {
|
|
162
|
+
timeoutMinutes: watchdogTimeout,
|
|
163
|
+
verbose: true,
|
|
164
|
+
composeFile: env.composeFile
|
|
165
|
+
});
|
|
166
|
+
startHeartbeat(env.projectName);
|
|
167
|
+
}
|
|
168
|
+
const command = devServersCommand ?? buildDevServersCommand(env.apps);
|
|
169
|
+
if (!command) {
|
|
170
|
+
console.log("✅ Containers ready. No apps configured.");
|
|
171
|
+
await new Promise(() => {});
|
|
172
|
+
await cleanupTunnels();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
await killProcessesOnAppPorts(env.apps, env.ports);
|
|
176
|
+
console.log("");
|
|
177
|
+
console.log("\uD83D\uDD27 Starting dev servers...");
|
|
178
|
+
console.log("");
|
|
179
|
+
await runCommand(command, env.root, env.buildEnvVars(), {
|
|
180
|
+
onSignal: async () => {
|
|
181
|
+
await cleanupTunnels();
|
|
182
|
+
stopHeartbeat();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
stopHeartbeat();
|
|
186
|
+
await cleanupTunnels();
|
|
187
|
+
}
|
|
188
|
+
function buildDevServersCommand(apps) {
|
|
189
|
+
const appEntries = Object.entries(apps);
|
|
190
|
+
if (appEntries.length === 0)
|
|
191
|
+
return null;
|
|
192
|
+
const commands = [];
|
|
193
|
+
const names = [];
|
|
194
|
+
const colors = ["blue", "green", "yellow", "magenta", "cyan", "red"];
|
|
195
|
+
for (const [name, config] of appEntries) {
|
|
196
|
+
names.push(name);
|
|
197
|
+
const cwdPart = config.cwd ? `--cwd ${config.cwd}` : "";
|
|
198
|
+
commands.push(`"bun run ${cwdPart} ${config.devCommand}"`.replace(/\s+/g, " ").trim());
|
|
199
|
+
}
|
|
200
|
+
const namesArg = `-n ${names.join(",")}`;
|
|
201
|
+
const colorsArg = `-c ${colors.slice(0, names.length).join(",")}`;
|
|
202
|
+
const commandsArg = commands.join(" ");
|
|
203
|
+
return `bun concurrently ${namesArg} ${colorsArg} ${commandsArg}`;
|
|
204
|
+
}
|
|
205
|
+
function runCommand(command, cwd, envVars, options = {}) {
|
|
206
|
+
const { onSignal } = options;
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
const proc = spawn(command, [], {
|
|
209
|
+
cwd,
|
|
210
|
+
env: { ...process.env, ...envVars },
|
|
211
|
+
stdio: "inherit",
|
|
212
|
+
shell: true
|
|
213
|
+
});
|
|
214
|
+
proc.on("close", (code) => {
|
|
215
|
+
if (code === 0 || code === null) {
|
|
216
|
+
resolve();
|
|
217
|
+
} else {
|
|
218
|
+
reject(new Error(`Command exited with code ${code}`));
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
proc.on("error", reject);
|
|
222
|
+
const cleanup = () => {
|
|
223
|
+
if (onSignal) {
|
|
224
|
+
onSignal();
|
|
225
|
+
}
|
|
226
|
+
proc.kill("SIGTERM");
|
|
227
|
+
};
|
|
228
|
+
process.on("SIGINT", cleanup);
|
|
229
|
+
process.on("SIGTERM", cleanup);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function hasFlag(args, flag) {
|
|
233
|
+
return args.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
|
|
234
|
+
}
|
|
235
|
+
function getFlagValue(args, flag) {
|
|
236
|
+
const prefixed = args.find((arg) => arg.startsWith(`${flag}=`));
|
|
237
|
+
if (prefixed) {
|
|
238
|
+
return prefixed.split("=")[1];
|
|
239
|
+
}
|
|
240
|
+
const index = args.indexOf(flag);
|
|
241
|
+
if (index !== -1 && index + 1 < args.length) {
|
|
242
|
+
const nextArg = args[index + 1];
|
|
243
|
+
if (nextArg !== undefined && !nextArg.startsWith("-")) {
|
|
244
|
+
return nextArg;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export { runCli, hasFlag, getFlagValue };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDevEnvironment
|
|
3
|
+
} from "./index-yw46g4tr.js";
|
|
4
|
+
|
|
5
|
+
// src/loader/cache.ts
|
|
6
|
+
var cachedEnv = null;
|
|
7
|
+
function setCachedDevEnv(env) {
|
|
8
|
+
cachedEnv = env;
|
|
9
|
+
}
|
|
10
|
+
function getCachedDevEnv() {
|
|
11
|
+
return cachedEnv;
|
|
12
|
+
}
|
|
13
|
+
function clearDevEnvCache() {
|
|
14
|
+
cachedEnv = null;
|
|
15
|
+
}
|
|
16
|
+
// src/loader/find-config-file.ts
|
|
17
|
+
import { existsSync } from "node:fs";
|
|
18
|
+
import { dirname, join } from "node:path";
|
|
19
|
+
var CONFIG_FILES = [
|
|
20
|
+
"dev.config.ts",
|
|
21
|
+
"dev.config.js",
|
|
22
|
+
"dev-tools.config.ts",
|
|
23
|
+
"dev-tools.config.js"
|
|
24
|
+
];
|
|
25
|
+
function findConfigFile(startDir) {
|
|
26
|
+
let currentDir = startDir;
|
|
27
|
+
while (true) {
|
|
28
|
+
for (const file of CONFIG_FILES) {
|
|
29
|
+
const configPath = join(currentDir, file);
|
|
30
|
+
if (existsSync(configPath)) {
|
|
31
|
+
return configPath;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const parentDir = dirname(currentDir);
|
|
35
|
+
if (parentDir === currentDir) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
currentDir = parentDir;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// src/loader/load-dev-env.ts
|
|
42
|
+
async function loadDevEnv(options) {
|
|
43
|
+
if (!options?.reload) {
|
|
44
|
+
const cached = getCachedDevEnv();
|
|
45
|
+
if (cached)
|
|
46
|
+
return cached;
|
|
47
|
+
}
|
|
48
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
49
|
+
const configPath = findConfigFile(cwd);
|
|
50
|
+
if (configPath) {
|
|
51
|
+
const mod = await import(configPath);
|
|
52
|
+
const config = mod.default;
|
|
53
|
+
if (!config?.projectPrefix || !config?.services) {
|
|
54
|
+
throw new Error(`Invalid config in "${configPath}". Use defineDevConfig() and export as default.`);
|
|
55
|
+
}
|
|
56
|
+
const env = createDevEnvironment(config);
|
|
57
|
+
setCachedDevEnv(env);
|
|
58
|
+
return env;
|
|
59
|
+
}
|
|
60
|
+
throw new Error("No config file found. Create dev.config.ts with: export default defineDevConfig({ ... })");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/loader/index.ts
|
|
64
|
+
function getDevEnv() {
|
|
65
|
+
const env = getCachedDevEnv();
|
|
66
|
+
if (!env) {
|
|
67
|
+
throw new Error("Dev environment not loaded. Call loadDevEnv() first.");
|
|
68
|
+
}
|
|
69
|
+
return env;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { clearDevEnvCache, CONFIG_FILES, findConfigFile, loadDevEnv, getDevEnv };
|