buncargo 1.0.26 → 3.0.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/dist/bin.d.ts +1 -12
- package/dist/bin.js +261 -252
- package/dist/cli/bin.d.ts +13 -0
- package/dist/cli/bin.js +315 -0
- package/dist/cli/commands/help.d.ts +1 -0
- package/dist/cli/commands/runtime.d.ts +5 -0
- package/dist/cli/commands/version.d.ts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +14 -0
- package/dist/cli/run-cli.d.ts +22 -0
- package/dist/cli.d.ts +1 -22
- package/dist/cli.js +5 -13
- package/dist/config/config.d.ts +1 -0
- package/dist/config/define-config.d.ts +13 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +15 -0
- package/dist/config/merge-configs.d.ts +3 -0
- package/dist/config/validate-config.d.ts +3 -0
- package/dist/config.d.ts +1 -72
- package/dist/config.js +12 -12
- package/dist/core/docker.d.ts +1 -74
- package/dist/core/docker.js +35 -26
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +123 -108
- package/dist/core/network.js +2 -2
- package/dist/core/ports.d.ts +22 -0
- package/dist/core/ports.js +5 -1
- package/dist/core/process.js +1 -1
- package/dist/core/tunnel.d.ts +33 -0
- package/dist/core/utils.js +2 -2
- package/dist/core/watchdog-runner.js +45 -42
- package/dist/core/watchdog.d.ts +1 -0
- package/dist/core/watchdog.js +4 -2
- package/dist/docker/index.d.ts +1 -0
- package/dist/docker/index.js +38 -0
- package/dist/docker/runtime.d.ts +87 -0
- package/dist/docker/runtime.js +37 -0
- package/dist/docker-compose/compose.d.ts +1 -0
- package/dist/docker-compose/generated-file.d.ts +7 -0
- package/dist/docker-compose/index.d.ts +3 -0
- package/dist/docker-compose/index.js +15 -0
- package/dist/docker-compose/model.d.ts +6 -0
- package/dist/docker-compose/services/clickhouse.d.ts +16 -0
- package/dist/docker-compose/services/define-docker-service.d.ts +41 -0
- package/dist/docker-compose/services/index.d.ts +23 -0
- package/dist/docker-compose/services/index.js +17 -0
- package/dist/docker-compose/services/postgres.d.ts +12 -0
- package/dist/docker-compose/services/redis.d.ts +12 -0
- package/dist/docker-compose/services/shared.d.ts +7 -0
- package/dist/docker-compose/yaml.d.ts +2 -0
- package/dist/environment/create-dev-environment.d.ts +23 -0
- package/dist/environment/index.d.ts +1 -0
- package/dist/environment/index.js +15 -0
- package/dist/environment/logging.d.ts +17 -0
- package/dist/environment/seeding.d.ts +9 -0
- package/dist/environment.d.ts +1 -23
- package/dist/environment.js +12 -14
- package/dist/index-045jksh5.js +147 -0
- package/dist/index-08wa79cs.js +125 -117
- package/dist/index-0kxnae3z.js +335 -0
- package/dist/index-1mdrf7nz.js +66 -0
- package/dist/index-1yvbwj4k.js +262 -242
- package/dist/index-23ev345g.js +475 -0
- package/dist/index-2ckr49sf.js +228 -0
- package/dist/index-2f47khe5.js +376 -369
- package/dist/index-2fr3g85b.js +220 -183
- package/dist/index-38xnzpa6.js +450 -0
- package/dist/index-3h3dhtf2.js +51 -43
- package/dist/index-42x95209.js +51 -43
- package/dist/index-4gp0az1g.js +145 -0
- package/dist/index-4xrxh8yv.js +72 -0
- package/dist/index-5gmws6ah.js +181 -0
- package/dist/index-5hka0tff.js +78 -76
- package/dist/index-5rfqps4b.js +3 -0
- package/dist/index-5t9jxqm0.js +428 -0
- package/dist/index-6c1w1xk5.js +101 -0
- package/dist/index-6fm7mvwj.js +118 -97
- package/dist/index-6srpc523.js +127 -128
- package/dist/index-731rzzfp.js +187 -0
- package/dist/index-75y4cg2z.js +51 -43
- package/dist/index-7ja4ywyj.js +126 -127
- package/dist/index-8bw1cmz4.js +531 -0
- package/dist/index-8hbbj1mp.js +120 -121
- package/dist/index-8xj2p5n5.js +145 -0
- package/dist/index-bj79tw5w.js +0 -0
- package/dist/index-bnk6nr0g.js +73 -0
- package/dist/index-brbbzyks.js +72 -0
- package/dist/index-c0dr6mcv.js +123 -0
- package/dist/index-cty0bcry.js +235 -218
- package/dist/index-d8tyv5se.js +228 -0
- package/dist/index-d9efy0n4.js +176 -150
- package/dist/index-etfmqjjf.js +427 -0
- package/dist/index-fb29934k.js +172 -0
- package/dist/index-g50jw1yf.js +72 -0
- package/dist/index-g6eb5wdw.js +118 -117
- package/dist/index-ggq3yryx.js +99 -95
- package/dist/index-h70tce00.js +177 -0
- package/dist/index-hkxtfqtc.js +333 -0
- package/dist/index-kf3dhser.js +146 -143
- package/dist/index-ma6tgdb2.js +500 -0
- package/dist/index-mam0bcyz.js +123 -0
- package/dist/index-mm412dkp.js +274 -0
- package/dist/index-n8v18aeb.js +0 -0
- package/dist/index-ndnmnsej.js +378 -371
- package/dist/index-p8wty0e2.js +389 -379
- package/dist/index-qfphr2fd.js +100 -0
- package/dist/index-qqmms8rs.js +51 -43
- package/dist/index-qw4093g2.js +51 -43
- package/dist/index-qzwpzjbx.js +121 -122
- package/dist/index-segbnm0h.js +146 -143
- package/dist/index-t0fj6gg1.js +112 -0
- package/dist/index-thdkwnv7.js +122 -0
- package/dist/index-tjbx2r2t.js +270 -0
- package/dist/index-tjqw9vtj.js +62 -54
- package/dist/index-vbpb89jy.js +248 -0
- package/dist/index-vhs88xhe.js +99 -95
- package/dist/index-w8zxnjka.js +249 -0
- package/dist/index-wk2na3t9.js +404 -0
- package/dist/index-wz9x8g7z.js +383 -373
- package/dist/index-x249gyde.js +388 -378
- package/dist/index-xkvd0nsd.js +187 -0
- package/dist/index-yedqxm1z.js +80 -0
- package/dist/index-zfjzzjkf.js +266 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +66 -35
- package/dist/lint.d.ts +1 -46
- package/dist/lint.js +3 -7
- package/dist/loader/cache.d.ts +4 -0
- package/dist/loader/find-config-file.d.ts +2 -0
- package/dist/loader/index.d.ts +5 -0
- package/dist/loader/index.js +24 -0
- package/dist/loader/load-dev-env.d.ts +5 -0
- package/dist/loader/loader.d.ts +1 -0
- package/dist/loader.d.ts +1 -45
- package/dist/loader.js +22 -20
- package/dist/prisma/index.d.ts +1 -0
- package/dist/prisma/prisma.d.ts +29 -0
- package/dist/prisma.d.ts +1 -29
- package/dist/prisma.js +6 -10
- package/dist/src/bin.js +309 -0
- package/dist/src/cli.js +5 -0
- package/dist/src/config.js +15 -0
- package/dist/src/core/docker.js +38 -0
- package/dist/src/core/index.js +130 -0
- package/dist/src/core/network.js +9 -0
- package/dist/src/core/ports.js +23 -0
- package/dist/src/core/process.js +31 -0
- package/dist/src/core/utils.js +11 -0
- package/dist/src/core/watchdog-runner.js +69 -0
- package/dist/src/core/watchdog.js +28 -0
- package/dist/src/docker/runtime.js +37 -0
- package/dist/src/docker-compose/index.js +16 -0
- package/dist/src/docker-compose/services/index.js +17 -0
- package/dist/src/environment.js +12 -0
- package/dist/src/index.js +122 -0
- package/dist/src/lint.js +3 -0
- package/dist/src/loader.js +25 -0
- package/dist/src/prisma.js +6 -0
- package/dist/src/types.js +0 -0
- package/dist/typecheck/index.d.ts +1 -0
- package/dist/typecheck/index.js +7 -0
- package/dist/typecheck/typecheck.d.ts +46 -0
- package/dist/types/all-types.d.ts +501 -0
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config.d.ts +6 -0
- package/dist/types/docker.d.ts +15 -0
- package/dist/types/environment.d.ts +8 -0
- package/dist/types/hooks.d.ts +9 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +0 -0
- package/dist/types/prisma.d.ts +1 -0
- package/dist/types.d.ts +1 -393
- package/package.json +145 -140
- package/readme.md +358 -105
- package/src/cli/bin.ts +77 -0
- package/src/cli/commands/help.ts +39 -0
- package/src/cli/commands/runtime.ts +72 -0
- package/src/cli/commands/version.ts +4 -0
- package/src/cli/index.ts +1 -0
- package/{cli.ts → src/cli/run-cli.ts} +95 -6
- package/src/config/define-config.ts +30 -0
- package/src/config/index.ts +3 -0
- package/src/config/merge-configs.ts +33 -0
- package/src/config/validate-config.ts +136 -0
- package/{core → src/core}/index.ts +2 -2
- package/{core → src/core}/ports.ts +68 -1
- package/{core → src/core}/process.ts +6 -2
- package/src/core/tunnel.ts +151 -0
- package/{core → src/core}/utils.ts +1 -0
- package/{core → src/core}/watchdog.ts +5 -1
- package/src/docker/index.ts +1 -0
- package/{core/docker.ts → src/docker/runtime.ts} +40 -4
- package/src/docker-compose/generated-file.ts +45 -0
- package/src/docker-compose/index.ts +7 -0
- package/src/docker-compose/model.ts +197 -0
- package/src/docker-compose/services/clickhouse.ts +79 -0
- package/src/docker-compose/services/define-docker-service.ts +109 -0
- package/src/docker-compose/services/index.ts +67 -0
- package/src/docker-compose/services/postgres.ts +60 -0
- package/src/docker-compose/services/redis.ts +48 -0
- package/src/docker-compose/services/shared.ts +79 -0
- package/src/docker-compose/yaml.ts +88 -0
- package/{environment.ts → src/environment/create-dev-environment.ts} +101 -146
- package/src/environment/index.ts +1 -0
- package/src/environment/logging.ts +101 -0
- package/src/environment/seeding.ts +57 -0
- package/{index.ts → src/index.ts} +49 -15
- package/src/loader/cache.ts +23 -0
- package/src/loader/find-config-file.ts +29 -0
- package/src/loader/index.ts +17 -0
- package/src/loader/load-dev-env.ts +38 -0
- package/src/prisma/index.ts +1 -0
- package/{prisma.ts → src/prisma/prisma.ts} +4 -2
- package/src/typecheck/index.ts +1 -0
- package/{types.ts → src/types/all-types.ts} +137 -6
- package/src/types/index.ts +1 -0
- package/bin.ts +0 -191
- package/config.ts +0 -194
- package/loader.ts +0 -126
- /package/{core → src/core}/network.ts +0 -0
- /package/{core → src/core}/watchdog-runner.ts +0 -0
- /package/{lint.ts → src/typecheck/typecheck.ts} +0 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logPublicUrls
|
|
3
|
+
} from "./index-bnk6nr0g.js";
|
|
4
|
+
import {
|
|
5
|
+
spawnWatchdog,
|
|
6
|
+
startHeartbeat,
|
|
7
|
+
stopHeartbeat
|
|
8
|
+
} from "./index-mam0bcyz.js";
|
|
9
|
+
import {
|
|
10
|
+
killProcessesOnAppPorts
|
|
11
|
+
} from "./index-mm412dkp.js";
|
|
12
|
+
|
|
13
|
+
// src/core/tunnel.ts
|
|
14
|
+
import { startTunnel } from "untun";
|
|
15
|
+
function parseExposeNames(exposeValue) {
|
|
16
|
+
if (exposeValue === undefined)
|
|
17
|
+
return null;
|
|
18
|
+
const names = exposeValue.split(",").map((name) => name.trim()).filter(Boolean);
|
|
19
|
+
return new Set(names);
|
|
20
|
+
}
|
|
21
|
+
function asPublicUrl(tunnel) {
|
|
22
|
+
return tunnel.url ?? tunnel.publicUrl ?? tunnel.tunnelUrl ?? null;
|
|
23
|
+
}
|
|
24
|
+
function toCloseFn(tunnel) {
|
|
25
|
+
const close = tunnel.close ?? tunnel.stop ?? tunnel.destroy;
|
|
26
|
+
if (!close)
|
|
27
|
+
return async () => {};
|
|
28
|
+
return async () => {
|
|
29
|
+
await close();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function resolveExposeTargets(env, exposeValue) {
|
|
33
|
+
const requestedNames = parseExposeNames(exposeValue);
|
|
34
|
+
const knownTargets = new Map;
|
|
35
|
+
const enabledTargets = new Map;
|
|
36
|
+
for (const [name, config] of Object.entries(env.services)) {
|
|
37
|
+
const port = env.ports[name];
|
|
38
|
+
if (port === undefined)
|
|
39
|
+
continue;
|
|
40
|
+
const target = { kind: "service", name, port };
|
|
41
|
+
knownTargets.set(name, target);
|
|
42
|
+
if (config.expose === true) {
|
|
43
|
+
enabledTargets.set(name, target);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const [name, config] of Object.entries(env.apps)) {
|
|
47
|
+
const port = env.ports[name];
|
|
48
|
+
if (port === undefined)
|
|
49
|
+
continue;
|
|
50
|
+
const target = { kind: "app", name, port };
|
|
51
|
+
knownTargets.set(name, target);
|
|
52
|
+
if (config.expose === true) {
|
|
53
|
+
enabledTargets.set(name, target);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (requestedNames === null) {
|
|
57
|
+
return {
|
|
58
|
+
targets: Array.from(enabledTargets.values()),
|
|
59
|
+
unknownNames: [],
|
|
60
|
+
notEnabledNames: []
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const unknownNames = [];
|
|
64
|
+
const notEnabledNames = [];
|
|
65
|
+
const targets = [];
|
|
66
|
+
for (const name of requestedNames) {
|
|
67
|
+
if (!knownTargets.has(name)) {
|
|
68
|
+
unknownNames.push(name);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const enabledTarget = enabledTargets.get(name);
|
|
72
|
+
if (!enabledTarget) {
|
|
73
|
+
notEnabledNames.push(name);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
targets.push(enabledTarget);
|
|
77
|
+
}
|
|
78
|
+
return { targets, unknownNames, notEnabledNames };
|
|
79
|
+
}
|
|
80
|
+
async function startPublicTunnels(targets, options = {}) {
|
|
81
|
+
const start = options.start ?? ((input) => startTunnel(input));
|
|
82
|
+
const tunnels = [];
|
|
83
|
+
try {
|
|
84
|
+
for (const target of targets) {
|
|
85
|
+
const localUrl = `http://localhost:${target.port}`;
|
|
86
|
+
const tunnel = await start({
|
|
87
|
+
url: localUrl
|
|
88
|
+
});
|
|
89
|
+
const publicUrl = asPublicUrl(tunnel);
|
|
90
|
+
if (!publicUrl) {
|
|
91
|
+
throw new Error(`Tunnel for "${target.name}" did not provide a public URL`);
|
|
92
|
+
}
|
|
93
|
+
tunnels.push({
|
|
94
|
+
kind: target.kind,
|
|
95
|
+
name: target.name,
|
|
96
|
+
localUrl,
|
|
97
|
+
publicUrl,
|
|
98
|
+
close: toCloseFn(tunnel)
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return tunnels;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
await stopPublicTunnels(tunnels);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function stopPublicTunnels(tunnels) {
|
|
108
|
+
await Promise.allSettled(tunnels.map((tunnel) => tunnel.close()));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/cli/run-cli.ts
|
|
112
|
+
import { spawn } from "node:child_process";
|
|
113
|
+
var ACCEPTED_FLAGS = [
|
|
114
|
+
"--help",
|
|
115
|
+
"--down",
|
|
116
|
+
"--reset",
|
|
117
|
+
"--migrate",
|
|
118
|
+
"--seed",
|
|
119
|
+
"--up-only",
|
|
120
|
+
"--expose"
|
|
121
|
+
];
|
|
122
|
+
function printHelp() {
|
|
123
|
+
console.log(`
|
|
124
|
+
Usage: buncargo dev [options]
|
|
125
|
+
|
|
126
|
+
Options:
|
|
127
|
+
--help Show this help message
|
|
128
|
+
--down Stop all containers
|
|
129
|
+
--reset Stop containers and remove volumes (fresh start)
|
|
130
|
+
--migrate Run migrations and exit
|
|
131
|
+
--seed Run migrations and seeders, then exit
|
|
132
|
+
--up-only Start containers and run migrations, then exit (no dev servers)
|
|
133
|
+
--expose Expose configured targets via public quick tunnels
|
|
134
|
+
|
|
135
|
+
Examples:
|
|
136
|
+
bun dev Start dev environment with all services
|
|
137
|
+
bun dev --seed Run migrations and seed the database
|
|
138
|
+
bun dev --down Stop all containers
|
|
139
|
+
bun dev --reset Stop containers and remove all data
|
|
140
|
+
bun dev --expose Expose all targets with expose: true
|
|
141
|
+
bun dev --expose=api,web Expose specific targets
|
|
142
|
+
`);
|
|
143
|
+
}
|
|
144
|
+
function getUnknownFlags(args) {
|
|
145
|
+
return args.filter((arg) => arg.startsWith("--") && !ACCEPTED_FLAGS.includes(arg.includes("=") ? arg.split("=")[0] : arg));
|
|
146
|
+
}
|
|
147
|
+
async function runCli(env, options = {}) {
|
|
148
|
+
const {
|
|
149
|
+
args = process.argv.slice(2),
|
|
150
|
+
watchdog = true,
|
|
151
|
+
watchdogTimeout = 10,
|
|
152
|
+
devServersCommand
|
|
153
|
+
} = options;
|
|
154
|
+
const exposeRequested = hasFlag(args, "--expose");
|
|
155
|
+
const exposeValue = getFlagValue(args, "--expose");
|
|
156
|
+
let tunnels = [];
|
|
157
|
+
async function cleanupTunnels() {
|
|
158
|
+
if (tunnels.length === 0)
|
|
159
|
+
return;
|
|
160
|
+
await stopPublicTunnels(tunnels);
|
|
161
|
+
tunnels = [];
|
|
162
|
+
}
|
|
163
|
+
if (args.includes("--help")) {
|
|
164
|
+
printHelp();
|
|
165
|
+
process.exit(0);
|
|
166
|
+
}
|
|
167
|
+
const unknownFlags = getUnknownFlags(args);
|
|
168
|
+
if (unknownFlags.length > 0) {
|
|
169
|
+
console.error(`❌ Unknown flag${unknownFlags.length > 1 ? "s" : ""}: ${unknownFlags.join(", ")}`);
|
|
170
|
+
console.error("");
|
|
171
|
+
printHelp();
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
if (args.includes("--down")) {
|
|
175
|
+
env.logInfo();
|
|
176
|
+
await cleanupTunnels();
|
|
177
|
+
await env.stop();
|
|
178
|
+
process.exit(0);
|
|
179
|
+
}
|
|
180
|
+
if (args.includes("--reset")) {
|
|
181
|
+
env.logInfo();
|
|
182
|
+
await cleanupTunnels();
|
|
183
|
+
await env.stop({ removeVolumes: true });
|
|
184
|
+
process.exit(0);
|
|
185
|
+
}
|
|
186
|
+
const skipSeed = args.includes("--seed");
|
|
187
|
+
await env.start({ startServers: false, wait: true, skipSeed });
|
|
188
|
+
if (exposeRequested) {
|
|
189
|
+
const { targets, unknownNames, notEnabledNames } = resolveExposeTargets(env, exposeValue);
|
|
190
|
+
if (unknownNames.length > 0) {
|
|
191
|
+
console.error(`❌ Unknown expose target${unknownNames.length > 1 ? "s" : ""}: ${unknownNames.join(", ")}`);
|
|
192
|
+
await cleanupTunnels();
|
|
193
|
+
process.exit(1);
|
|
194
|
+
}
|
|
195
|
+
if (notEnabledNames.length > 0) {
|
|
196
|
+
console.error(`❌ Target${notEnabledNames.length > 1 ? "s" : ""} missing expose: true: ${notEnabledNames.join(", ")}`);
|
|
197
|
+
console.error(" Mark these in dev.config.ts with expose: true or remove them from --expose.");
|
|
198
|
+
await cleanupTunnels();
|
|
199
|
+
process.exit(1);
|
|
200
|
+
}
|
|
201
|
+
if (targets.length === 0) {
|
|
202
|
+
console.error("❌ No expose targets selected. Add expose: true to services/apps or pass names with --expose=<name>.");
|
|
203
|
+
await cleanupTunnels();
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
tunnels = await startPublicTunnels(targets);
|
|
207
|
+
logPublicUrls(tunnels);
|
|
208
|
+
}
|
|
209
|
+
if (args.includes("--migrate")) {
|
|
210
|
+
console.log("");
|
|
211
|
+
console.log("✅ Migrations applied successfully");
|
|
212
|
+
await cleanupTunnels();
|
|
213
|
+
process.exit(0);
|
|
214
|
+
}
|
|
215
|
+
if (args.includes("--seed")) {
|
|
216
|
+
console.log("\uD83C\uDF31 Running seeders...");
|
|
217
|
+
const result = await env.exec("bun run run:seeder", {
|
|
218
|
+
throwOnError: false
|
|
219
|
+
});
|
|
220
|
+
if (result.exitCode !== 0) {
|
|
221
|
+
console.error("❌ Seeding failed");
|
|
222
|
+
if (result.stderr) {
|
|
223
|
+
console.error(result.stderr);
|
|
224
|
+
}
|
|
225
|
+
if (result.stdout) {
|
|
226
|
+
console.error(result.stdout);
|
|
227
|
+
}
|
|
228
|
+
await cleanupTunnels();
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
console.log("");
|
|
232
|
+
console.log("✅ Seeding complete");
|
|
233
|
+
await cleanupTunnels();
|
|
234
|
+
process.exit(0);
|
|
235
|
+
}
|
|
236
|
+
if (args.includes("--up-only")) {
|
|
237
|
+
console.log("");
|
|
238
|
+
console.log("✅ Containers started. Environment ready.");
|
|
239
|
+
console.log("");
|
|
240
|
+
await cleanupTunnels();
|
|
241
|
+
process.exit(0);
|
|
242
|
+
}
|
|
243
|
+
if (watchdog) {
|
|
244
|
+
await spawnWatchdog(env.projectName, env.root, {
|
|
245
|
+
timeoutMinutes: watchdogTimeout,
|
|
246
|
+
verbose: true,
|
|
247
|
+
composeFile: env.composeFile
|
|
248
|
+
});
|
|
249
|
+
startHeartbeat(env.projectName);
|
|
250
|
+
}
|
|
251
|
+
const command = devServersCommand ?? buildDevServersCommand(env.apps);
|
|
252
|
+
if (!command) {
|
|
253
|
+
console.log("✅ Containers ready. No apps configured.");
|
|
254
|
+
await new Promise(() => {});
|
|
255
|
+
await cleanupTunnels();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
await killProcessesOnAppPorts(env.apps, env.ports);
|
|
259
|
+
console.log("");
|
|
260
|
+
console.log("\uD83D\uDD27 Starting dev servers...");
|
|
261
|
+
console.log("");
|
|
262
|
+
await runCommand(command, env.root, env.buildEnvVars(), {
|
|
263
|
+
onSignal: async () => {
|
|
264
|
+
await cleanupTunnels();
|
|
265
|
+
stopHeartbeat();
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
stopHeartbeat();
|
|
269
|
+
await cleanupTunnels();
|
|
270
|
+
}
|
|
271
|
+
function buildDevServersCommand(apps) {
|
|
272
|
+
const appEntries = Object.entries(apps);
|
|
273
|
+
if (appEntries.length === 0)
|
|
274
|
+
return null;
|
|
275
|
+
const commands = [];
|
|
276
|
+
const names = [];
|
|
277
|
+
const colors = ["blue", "green", "yellow", "magenta", "cyan", "red"];
|
|
278
|
+
for (const [name, config] of appEntries) {
|
|
279
|
+
names.push(name);
|
|
280
|
+
const cwdPart = config.cwd ? `--cwd ${config.cwd}` : "";
|
|
281
|
+
commands.push(`"bun run ${cwdPart} ${config.devCommand}"`.replace(/\s+/g, " ").trim());
|
|
282
|
+
}
|
|
283
|
+
const namesArg = `-n ${names.join(",")}`;
|
|
284
|
+
const colorsArg = `-c ${colors.slice(0, names.length).join(",")}`;
|
|
285
|
+
const commandsArg = commands.join(" ");
|
|
286
|
+
return `bun concurrently ${namesArg} ${colorsArg} ${commandsArg}`;
|
|
287
|
+
}
|
|
288
|
+
function runCommand(command, cwd, envVars, options = {}) {
|
|
289
|
+
const { onSignal } = options;
|
|
290
|
+
return new Promise((resolve, reject) => {
|
|
291
|
+
const proc = spawn(command, [], {
|
|
292
|
+
cwd,
|
|
293
|
+
env: { ...process.env, ...envVars },
|
|
294
|
+
stdio: "inherit",
|
|
295
|
+
shell: true
|
|
296
|
+
});
|
|
297
|
+
proc.on("close", (code) => {
|
|
298
|
+
if (code === 0 || code === null) {
|
|
299
|
+
resolve();
|
|
300
|
+
} else {
|
|
301
|
+
reject(new Error(`Command exited with code ${code}`));
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
proc.on("error", reject);
|
|
305
|
+
const cleanup = () => {
|
|
306
|
+
if (onSignal) {
|
|
307
|
+
onSignal();
|
|
308
|
+
}
|
|
309
|
+
proc.kill("SIGTERM");
|
|
310
|
+
};
|
|
311
|
+
process.on("SIGINT", cleanup);
|
|
312
|
+
process.on("SIGTERM", cleanup);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function hasFlag(args, flag) {
|
|
316
|
+
return args.includes(flag);
|
|
317
|
+
}
|
|
318
|
+
function getFlagValue(args, flag) {
|
|
319
|
+
const prefixed = args.find((arg) => arg.startsWith(`${flag}=`));
|
|
320
|
+
if (prefixed) {
|
|
321
|
+
return prefixed.split("=")[1];
|
|
322
|
+
}
|
|
323
|
+
const index = args.indexOf(flag);
|
|
324
|
+
if (index !== -1 && index + 1 < args.length) {
|
|
325
|
+
const nextArg = args[index + 1];
|
|
326
|
+
if (nextArg !== undefined && !nextArg.startsWith("-")) {
|
|
327
|
+
return nextArg;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export { resolveExposeTargets, startPublicTunnels, stopPublicTunnels, runCli, hasFlag, getFlagValue };
|
package/dist/index-kf3dhser.js
CHANGED
|
@@ -1,160 +1,163 @@
|
|
|
1
|
+
// cli.ts
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
1
3
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
stopHeartbeat
|
|
5
|
-
} from "./index-vhs88xhe.js";
|
|
6
|
-
import {
|
|
7
|
-
getProcessOnPort,
|
|
8
|
-
killProcessOnPortAndWait
|
|
4
|
+
getProcessOnPort,
|
|
5
|
+
killProcessOnPortAndWait,
|
|
9
6
|
} from "./index-cty0bcry.js";
|
|
7
|
+
import {
|
|
8
|
+
spawnWatchdog,
|
|
9
|
+
startHeartbeat,
|
|
10
|
+
stopHeartbeat,
|
|
11
|
+
} from "./index-vhs88xhe.js";
|
|
10
12
|
|
|
11
|
-
// cli.ts
|
|
12
|
-
import { spawn } from "node:child_process";
|
|
13
13
|
async function runCli(env, options = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
14
|
+
const {
|
|
15
|
+
args = process.argv.slice(2),
|
|
16
|
+
watchdog = true,
|
|
17
|
+
watchdogTimeout = 10,
|
|
18
|
+
devServersCommand,
|
|
19
|
+
} = options;
|
|
20
|
+
env.logInfo();
|
|
21
|
+
if (args.includes("--down")) {
|
|
22
|
+
await env.stop();
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
if (args.includes("--reset")) {
|
|
26
|
+
await env.stop({ removeVolumes: true });
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
const running = await env.isRunning();
|
|
30
|
+
if (running) {
|
|
31
|
+
console.log("✓ Containers already running");
|
|
32
|
+
} else {
|
|
33
|
+
await env.start({ startServers: false, wait: true });
|
|
34
|
+
}
|
|
35
|
+
if (args.includes("--migrate")) {
|
|
36
|
+
console.log("");
|
|
37
|
+
console.log("✅ Migrations applied successfully");
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
if (args.includes("--seed")) {
|
|
41
|
+
console.log("\uD83C\uDF31 Running seeders...");
|
|
42
|
+
const result = await env.exec("bun run run:seeder", {
|
|
43
|
+
throwOnError: false,
|
|
44
|
+
});
|
|
45
|
+
if (result.exitCode !== 0) {
|
|
46
|
+
console.error("❌ Seeding failed");
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
console.log("");
|
|
50
|
+
console.log("✅ Seeding complete");
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
if (args.includes("--up-only")) {
|
|
54
|
+
console.log("");
|
|
55
|
+
console.log("✅ Containers started. Environment ready.");
|
|
56
|
+
console.log("");
|
|
57
|
+
process.exit(0);
|
|
58
|
+
}
|
|
59
|
+
if (watchdog) {
|
|
60
|
+
await spawnWatchdog(env.projectName, env.root, {
|
|
61
|
+
timeoutMinutes: watchdogTimeout,
|
|
62
|
+
verbose: true,
|
|
63
|
+
});
|
|
64
|
+
startHeartbeat(env.projectName);
|
|
65
|
+
}
|
|
66
|
+
const command = devServersCommand ?? buildDevServersCommand(env.apps);
|
|
67
|
+
if (!command) {
|
|
68
|
+
console.log("✅ Containers ready. No apps configured.");
|
|
69
|
+
await new Promise(() => {});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
await killExistingProcessesOnPorts(env.apps, env.ports);
|
|
73
|
+
console.log("");
|
|
74
|
+
console.log("\uD83D\uDD27 Starting dev servers...");
|
|
75
|
+
console.log("");
|
|
76
|
+
await runCommand(command, env.root, env.buildEnvVars());
|
|
77
|
+
stopHeartbeat();
|
|
78
78
|
}
|
|
79
79
|
async function killExistingProcessesOnPorts(apps, ports) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
80
|
+
const appNames = Object.keys(apps);
|
|
81
|
+
if (appNames.length === 0) return;
|
|
82
|
+
let killedAny = false;
|
|
83
|
+
for (const name of appNames) {
|
|
84
|
+
const port = ports[name];
|
|
85
|
+
if (port === undefined) continue;
|
|
86
|
+
const existingPid = getProcessOnPort(port);
|
|
87
|
+
if (existingPid !== null) {
|
|
88
|
+
if (!killedAny) {
|
|
89
|
+
console.log("");
|
|
90
|
+
killedAny = true;
|
|
91
|
+
}
|
|
92
|
+
console.log(
|
|
93
|
+
`⚠️ Port ${port} (${name}) is in use by process ${existingPid}`,
|
|
94
|
+
);
|
|
95
|
+
const killed = await killProcessOnPortAndWait(port, { verbose: true });
|
|
96
|
+
if (!killed) {
|
|
97
|
+
console.log(
|
|
98
|
+
` ⚠️ Could not kill process on port ${port}, server may fail to start`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
101
103
|
}
|
|
102
104
|
function buildDevServersCommand(apps) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
const appEntries = Object.entries(apps);
|
|
106
|
+
if (appEntries.length === 0) return null;
|
|
107
|
+
const commands = [];
|
|
108
|
+
const names = [];
|
|
109
|
+
const colors = ["blue", "green", "yellow", "magenta", "cyan", "red"];
|
|
110
|
+
for (const [name, config] of appEntries) {
|
|
111
|
+
names.push(name);
|
|
112
|
+
const cwdPart = config.cwd ? `--cwd ${config.cwd}` : "";
|
|
113
|
+
commands.push(
|
|
114
|
+
`"bun run ${cwdPart} ${config.devCommand}"`.replace(/\s+/g, " ").trim(),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
const namesArg = `-n ${names.join(",")}`;
|
|
118
|
+
const colorsArg = `-c ${colors.slice(0, names.length).join(",")}`;
|
|
119
|
+
const commandsArg = commands.join(" ");
|
|
120
|
+
return `bun concurrently ${namesArg} ${colorsArg} ${commandsArg}`;
|
|
118
121
|
}
|
|
119
122
|
function runCommand(command, cwd, envVars) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
const proc = spawn(command, [], {
|
|
125
|
+
cwd,
|
|
126
|
+
env: { ...process.env, ...envVars },
|
|
127
|
+
stdio: "inherit",
|
|
128
|
+
shell: true,
|
|
129
|
+
});
|
|
130
|
+
proc.on("close", (code) => {
|
|
131
|
+
if (code === 0 || code === null) {
|
|
132
|
+
resolve();
|
|
133
|
+
} else {
|
|
134
|
+
reject(new Error(`Command exited with code ${code}`));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
proc.on("error", reject);
|
|
138
|
+
const cleanup = () => {
|
|
139
|
+
proc.kill("SIGTERM");
|
|
140
|
+
};
|
|
141
|
+
process.on("SIGINT", cleanup);
|
|
142
|
+
process.on("SIGTERM", cleanup);
|
|
143
|
+
});
|
|
141
144
|
}
|
|
142
145
|
function hasFlag(args, flag) {
|
|
143
|
-
|
|
146
|
+
return args.includes(flag);
|
|
144
147
|
}
|
|
145
148
|
function getFlagValue(args, flag) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
149
|
+
const prefixed = args.find((arg) => arg.startsWith(`${flag}=`));
|
|
150
|
+
if (prefixed) {
|
|
151
|
+
return prefixed.split("=")[1];
|
|
152
|
+
}
|
|
153
|
+
const index = args.indexOf(flag);
|
|
154
|
+
if (index !== -1 && index + 1 < args.length) {
|
|
155
|
+
const nextArg = args[index + 1];
|
|
156
|
+
if (nextArg !== undefined && !nextArg.startsWith("-")) {
|
|
157
|
+
return nextArg;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
export { runCli, hasFlag, getFlagValue };
|