buncargo 1.0.29 → 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 -253
- 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 -83
- package/dist/core/docker.js +35 -32
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +123 -118
- package/dist/core/network.js +2 -2
- package/dist/core/ports.js +1 -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 +51 -43
- 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 +157 -142
- 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 +118 -97
- 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 +78 -76
- 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 +385 -375
- 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 +240 -199
- package/dist/index.d.ts +12 -8
- package/dist/index.js +56 -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 -399
- package/package.json +145 -140
- package/readme.md +349 -109
- 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 +5 -2
- 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} +11 -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} +93 -130
- 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 -20
- 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} +130 -5
- package/src/types/index.ts +1 -0
- package/bin.ts +0 -192
- 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,531 @@
|
|
|
1
|
+
import {
|
|
2
|
+
areContainersRunning,
|
|
3
|
+
isContainerRunning,
|
|
4
|
+
startContainers,
|
|
5
|
+
startService,
|
|
6
|
+
stopContainers,
|
|
7
|
+
waitForServiceByType
|
|
8
|
+
} from "./index-2ckr49sf.js";
|
|
9
|
+
import {
|
|
10
|
+
getLocalIp,
|
|
11
|
+
isCI,
|
|
12
|
+
logExpoApiUrl,
|
|
13
|
+
logFrontendPort,
|
|
14
|
+
waitForDevServers,
|
|
15
|
+
waitForServer
|
|
16
|
+
} from "./index-thdkwnv7.js";
|
|
17
|
+
import {
|
|
18
|
+
computeDevIdentity,
|
|
19
|
+
computePorts,
|
|
20
|
+
computeUrls,
|
|
21
|
+
findMonorepoRoot
|
|
22
|
+
} from "./index-fb29934k.js";
|
|
23
|
+
import {
|
|
24
|
+
getGeneratedComposePath,
|
|
25
|
+
writeGeneratedComposeFile
|
|
26
|
+
} from "./index-etfmqjjf.js";
|
|
27
|
+
import {
|
|
28
|
+
spawnWatchdog,
|
|
29
|
+
startHeartbeat,
|
|
30
|
+
stopHeartbeat,
|
|
31
|
+
stopWatchdog
|
|
32
|
+
} from "./index-mam0bcyz.js";
|
|
33
|
+
import {
|
|
34
|
+
buildApps,
|
|
35
|
+
execAsync,
|
|
36
|
+
startDevServers,
|
|
37
|
+
stopProcess
|
|
38
|
+
} from "./index-mm412dkp.js";
|
|
39
|
+
import {
|
|
40
|
+
assertValidConfig
|
|
41
|
+
} from "./index-t0fj6gg1.js";
|
|
42
|
+
|
|
43
|
+
// src/prisma/prisma.ts
|
|
44
|
+
import { spawn } from "node:child_process";
|
|
45
|
+
import { join } from "node:path";
|
|
46
|
+
function createPrismaRunner(env, config) {
|
|
47
|
+
const {
|
|
48
|
+
cwd = "packages/prisma",
|
|
49
|
+
service = "postgres",
|
|
50
|
+
urlEnvVar = "DATABASE_URL"
|
|
51
|
+
} = config;
|
|
52
|
+
const healthCheckTypes = {
|
|
53
|
+
postgres: "pg_isready",
|
|
54
|
+
redis: "redis-cli",
|
|
55
|
+
clickhouse: "http"
|
|
56
|
+
};
|
|
57
|
+
function getDatabaseUrl() {
|
|
58
|
+
const envVars = env.buildEnvVars();
|
|
59
|
+
const url = envVars[urlEnvVar];
|
|
60
|
+
if (!url) {
|
|
61
|
+
throw new Error(`Environment variable ${urlEnvVar} not found. Make sure your dev config defines it in envVars.`);
|
|
62
|
+
}
|
|
63
|
+
return url;
|
|
64
|
+
}
|
|
65
|
+
async function ensureDatabase() {
|
|
66
|
+
const alreadyRunning = await isContainerRunning(env.projectName, service);
|
|
67
|
+
if (alreadyRunning) {
|
|
68
|
+
console.log(`✓ ${service} already running`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(`\uD83D\uDC33 Starting ${service}...`);
|
|
72
|
+
const composeFile = env.ensureComposeFile();
|
|
73
|
+
const envVars = env.buildEnvVars();
|
|
74
|
+
startService(env.root, env.projectName, service, envVars, {
|
|
75
|
+
verbose: false,
|
|
76
|
+
composeFile
|
|
77
|
+
});
|
|
78
|
+
const port = env.ports[service];
|
|
79
|
+
if (!port) {
|
|
80
|
+
throw new Error(`Service ${service} not found in dev environment ports`);
|
|
81
|
+
}
|
|
82
|
+
const healthCheckType = healthCheckTypes[service] ?? "tcp";
|
|
83
|
+
console.log(`⏳ Waiting for ${service} to be healthy...`);
|
|
84
|
+
await waitForServiceByType(service, healthCheckType, port, {
|
|
85
|
+
verbose: true
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function run(args) {
|
|
89
|
+
if (args.length === 0) {
|
|
90
|
+
console.log(`
|
|
91
|
+
Usage: bun prisma <command> [args...]
|
|
92
|
+
|
|
93
|
+
Examples:
|
|
94
|
+
bun prisma migrate dev # Create new migration
|
|
95
|
+
bun prisma migrate deploy # Apply migrations
|
|
96
|
+
bun prisma db push # Push schema changes
|
|
97
|
+
bun prisma studio # Open Prisma Studio
|
|
98
|
+
bun prisma migrate reset # Reset database
|
|
99
|
+
`);
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
const port = env.ports[service];
|
|
103
|
+
console.log(`
|
|
104
|
+
\uD83D\uDD27 Prisma CLI
|
|
105
|
+
Project: ${env.projectName}
|
|
106
|
+
Database: localhost:${port}
|
|
107
|
+
${env.portOffset > 0 ? `(port offset +${env.portOffset})` : ""}
|
|
108
|
+
`);
|
|
109
|
+
await ensureDatabase();
|
|
110
|
+
const envVars = env.buildEnvVars();
|
|
111
|
+
const workingDir = join(env.root, cwd);
|
|
112
|
+
const fullEnv = {
|
|
113
|
+
...process.env,
|
|
114
|
+
...envVars,
|
|
115
|
+
[urlEnvVar]: getDatabaseUrl()
|
|
116
|
+
};
|
|
117
|
+
console.log(`\uD83D\uDD04 Running: prisma ${args.join(" ")}
|
|
118
|
+
`);
|
|
119
|
+
return new Promise((resolve) => {
|
|
120
|
+
const proc = spawn("bunx", ["prisma", ...args], {
|
|
121
|
+
cwd: workingDir,
|
|
122
|
+
env: fullEnv,
|
|
123
|
+
stdio: "inherit"
|
|
124
|
+
});
|
|
125
|
+
proc.on("close", (code) => {
|
|
126
|
+
resolve(code ?? 0);
|
|
127
|
+
});
|
|
128
|
+
proc.on("error", () => {
|
|
129
|
+
resolve(1);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return { run, getDatabaseUrl, ensureDatabase };
|
|
134
|
+
}
|
|
135
|
+
// src/environment/logging.ts
|
|
136
|
+
import pc from "picocolors";
|
|
137
|
+
function formatUrl(url) {
|
|
138
|
+
return pc.cyan(url.replace(/:(\d+)(\/?)/, (_, port, slash) => `:${pc.bold(port)}${slash}`));
|
|
139
|
+
}
|
|
140
|
+
function formatLabel(label, value, arrow = "➜") {
|
|
141
|
+
return ` ${pc.green(arrow)} ${pc.bold(label.padEnd(10))} ${value}`;
|
|
142
|
+
}
|
|
143
|
+
function formatDimLabel(label, value) {
|
|
144
|
+
return ` ${pc.dim("•")} ${pc.dim(label.padEnd(10))} ${pc.dim(value)}`;
|
|
145
|
+
}
|
|
146
|
+
function logEnvironmentInfo(input) {
|
|
147
|
+
const {
|
|
148
|
+
label,
|
|
149
|
+
projectName,
|
|
150
|
+
services,
|
|
151
|
+
apps,
|
|
152
|
+
ports,
|
|
153
|
+
localIp,
|
|
154
|
+
worktree,
|
|
155
|
+
portOffset,
|
|
156
|
+
projectSuffix
|
|
157
|
+
} = input;
|
|
158
|
+
const serviceNames = Object.keys(services);
|
|
159
|
+
const appNames = Object.keys(apps);
|
|
160
|
+
console.log("");
|
|
161
|
+
console.log(` ${pc.cyan(pc.bold(`\uD83D\uDC33 ${label}`))}`);
|
|
162
|
+
console.log(formatLabel("Project:", pc.white(projectName)));
|
|
163
|
+
if (serviceNames.length > 0) {
|
|
164
|
+
console.log("");
|
|
165
|
+
console.log(` ${pc.dim("─── Services ───")}`);
|
|
166
|
+
for (const name of serviceNames) {
|
|
167
|
+
const port = ports[name];
|
|
168
|
+
const url = `localhost:${port}`;
|
|
169
|
+
console.log(formatLabel(`${name}:`, formatUrl(`http://${url}`)));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (appNames.length > 0) {
|
|
173
|
+
console.log("");
|
|
174
|
+
console.log(` ${pc.dim("─── Applications ───")}`);
|
|
175
|
+
for (const name of appNames) {
|
|
176
|
+
const port = ports[name];
|
|
177
|
+
const localUrl = `http://localhost:${port}`;
|
|
178
|
+
const networkUrl = `http://${localIp}:${port}`;
|
|
179
|
+
console.log(` ${pc.green("➜")} ${pc.bold(pc.cyan(name))}`);
|
|
180
|
+
console.log(` ${pc.dim("Local:")} ${formatUrl(localUrl)}`);
|
|
181
|
+
console.log(` ${pc.dim("Network:")} ${formatUrl(networkUrl)}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
console.log("");
|
|
185
|
+
console.log(` ${pc.dim("─── Environment ───")}`);
|
|
186
|
+
console.log(formatDimLabel("Worktree:", worktree ? "yes" : "no"));
|
|
187
|
+
console.log(formatDimLabel("Port offset:", portOffset > 0 ? `+${portOffset}` : "none"));
|
|
188
|
+
if (projectSuffix) {
|
|
189
|
+
console.log(formatDimLabel("Suffix:", projectSuffix));
|
|
190
|
+
}
|
|
191
|
+
console.log(formatDimLabel("Local IP:", localIp));
|
|
192
|
+
console.log("");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/environment/seeding.ts
|
|
196
|
+
function createCheckTableHelper(urls, exec) {
|
|
197
|
+
return async (tableName, service) => {
|
|
198
|
+
const serviceName = service ?? "postgres";
|
|
199
|
+
const serviceUrl = urls[serviceName];
|
|
200
|
+
if (!serviceUrl) {
|
|
201
|
+
console.warn(`⚠️ Service "${serviceName}" not found for checkTable`);
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
const checkResult = await exec(`psql "${serviceUrl}" -tAc 'SELECT COUNT(*) FROM "${tableName}" LIMIT 1'`, { throwOnError: false });
|
|
205
|
+
const count = checkResult.stdout.trim();
|
|
206
|
+
const shouldSeed = checkResult.exitCode !== 0 || count === "0" || count === "";
|
|
207
|
+
if (!shouldSeed) {
|
|
208
|
+
console.log(` \uD83D\uDCCA Table "${tableName}" has ${count} rows`);
|
|
209
|
+
}
|
|
210
|
+
return shouldSeed;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function createSeedCheckContext(baseContext, checkTable) {
|
|
214
|
+
return {
|
|
215
|
+
...baseContext,
|
|
216
|
+
checkTable
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/environment/create-dev-environment.ts
|
|
221
|
+
function createDevEnvironment(config, options = {}) {
|
|
222
|
+
assertValidConfig(config);
|
|
223
|
+
const root = findMonorepoRoot();
|
|
224
|
+
const suffix = options.suffix;
|
|
225
|
+
const identity = computeDevIdentity({
|
|
226
|
+
projectPrefix: config.projectPrefix,
|
|
227
|
+
suffix,
|
|
228
|
+
root,
|
|
229
|
+
worktreeIsolation: config.options?.worktreeIsolation
|
|
230
|
+
});
|
|
231
|
+
const { worktree, projectSuffix, portOffset, projectName } = identity;
|
|
232
|
+
const localIp = getLocalIp();
|
|
233
|
+
const services = config.services;
|
|
234
|
+
const apps = config.apps ?? {};
|
|
235
|
+
const composeFile = getGeneratedComposePath(root, config.docker).composeFileArg;
|
|
236
|
+
function ensureComposeFile() {
|
|
237
|
+
return writeGeneratedComposeFile(root, services, config.docker);
|
|
238
|
+
}
|
|
239
|
+
const ports = computePorts(services, apps, portOffset);
|
|
240
|
+
const urls = computeUrls(services, apps, ports, localIp);
|
|
241
|
+
function buildEnvVars(production = false) {
|
|
242
|
+
const baseEnv = {
|
|
243
|
+
COMPOSE_PROJECT_NAME: projectName,
|
|
244
|
+
NODE_ENV: production ? "production" : "development"
|
|
245
|
+
};
|
|
246
|
+
for (const [name, port] of Object.entries(ports)) {
|
|
247
|
+
const envName = `${name.toUpperCase()}_PORT`;
|
|
248
|
+
baseEnv[envName] = String(port);
|
|
249
|
+
}
|
|
250
|
+
for (const [name, url] of Object.entries(urls)) {
|
|
251
|
+
const envName = `${name.toUpperCase()}_URL`;
|
|
252
|
+
baseEnv[envName] = url;
|
|
253
|
+
}
|
|
254
|
+
if (config.envVars) {
|
|
255
|
+
const userEnv = config.envVars(ports, urls, {
|
|
256
|
+
projectName,
|
|
257
|
+
localIp,
|
|
258
|
+
portOffset
|
|
259
|
+
});
|
|
260
|
+
for (const [key, value] of Object.entries(userEnv)) {
|
|
261
|
+
baseEnv[key] = String(value);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return baseEnv;
|
|
265
|
+
}
|
|
266
|
+
let hookContext = null;
|
|
267
|
+
function getHookContext() {
|
|
268
|
+
if (!hookContext) {
|
|
269
|
+
hookContext = {
|
|
270
|
+
projectName,
|
|
271
|
+
ports,
|
|
272
|
+
urls,
|
|
273
|
+
root,
|
|
274
|
+
isCI: isCI(),
|
|
275
|
+
portOffset,
|
|
276
|
+
localIp,
|
|
277
|
+
exec: async (cmd, opts) => {
|
|
278
|
+
const envVars = buildEnvVars();
|
|
279
|
+
return execAsync(cmd, root, envVars, opts);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return hookContext;
|
|
284
|
+
}
|
|
285
|
+
function exec(cmd, options2) {
|
|
286
|
+
const envVars = buildEnvVars();
|
|
287
|
+
return execAsync(cmd, root, envVars, options2);
|
|
288
|
+
}
|
|
289
|
+
async function start(startOptions = {}) {
|
|
290
|
+
const isCI2 = process.env.CI === "true";
|
|
291
|
+
const {
|
|
292
|
+
verbose = config.options?.verbose ?? true,
|
|
293
|
+
wait = true,
|
|
294
|
+
startServers: shouldStartServers = true,
|
|
295
|
+
productionBuild = isCI2,
|
|
296
|
+
skipSeed = false
|
|
297
|
+
} = startOptions;
|
|
298
|
+
const envVars = buildEnvVars(productionBuild);
|
|
299
|
+
ensureComposeFile();
|
|
300
|
+
if (verbose) {
|
|
301
|
+
logInfo(productionBuild ? "Production Environment" : "Dev Environment");
|
|
302
|
+
}
|
|
303
|
+
const serviceCount = Object.keys(services).length;
|
|
304
|
+
const alreadyRunning = await areContainersRunning(projectName, serviceCount);
|
|
305
|
+
if (alreadyRunning) {
|
|
306
|
+
if (verbose)
|
|
307
|
+
console.log("✓ Containers already running");
|
|
308
|
+
} else {
|
|
309
|
+
startContainers(root, projectName, envVars, {
|
|
310
|
+
verbose,
|
|
311
|
+
wait,
|
|
312
|
+
composeFile
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
const allMigrations = [
|
|
316
|
+
...config.prisma ? [
|
|
317
|
+
{
|
|
318
|
+
name: "prisma",
|
|
319
|
+
command: "bunx prisma migrate deploy",
|
|
320
|
+
cwd: config.prisma.cwd ?? "packages/prisma"
|
|
321
|
+
}
|
|
322
|
+
] : [],
|
|
323
|
+
...config.migrations ?? []
|
|
324
|
+
];
|
|
325
|
+
if (allMigrations.length > 0) {
|
|
326
|
+
if (verbose)
|
|
327
|
+
console.log("\uD83D\uDCE6 Running migrations...");
|
|
328
|
+
const migrationResults = await Promise.all(allMigrations.map(async (migration) => {
|
|
329
|
+
const result = await exec(migration.command, {
|
|
330
|
+
cwd: migration.cwd,
|
|
331
|
+
throwOnError: false
|
|
332
|
+
});
|
|
333
|
+
return { name: migration.name, result };
|
|
334
|
+
}));
|
|
335
|
+
for (const { name, result } of migrationResults) {
|
|
336
|
+
if (result.exitCode !== 0) {
|
|
337
|
+
console.error(`❌ Migration "${name}" failed`);
|
|
338
|
+
if (result.stdout) {
|
|
339
|
+
console.error(result.stdout);
|
|
340
|
+
}
|
|
341
|
+
if (result.stderr) {
|
|
342
|
+
console.error(result.stderr);
|
|
343
|
+
}
|
|
344
|
+
throw new Error(`Migration "${name}" failed`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (verbose)
|
|
348
|
+
console.log("✓ Migrations complete");
|
|
349
|
+
}
|
|
350
|
+
if (config.hooks?.afterContainersReady) {
|
|
351
|
+
await config.hooks.afterContainersReady(getHookContext());
|
|
352
|
+
}
|
|
353
|
+
if (config.seed && !skipSeed) {
|
|
354
|
+
let shouldSeed = true;
|
|
355
|
+
if (config.seed.check) {
|
|
356
|
+
const checkTable = createCheckTableHelper(urls, exec);
|
|
357
|
+
const seedCheckContext = createSeedCheckContext(getHookContext(), checkTable);
|
|
358
|
+
shouldSeed = await config.seed.check(seedCheckContext);
|
|
359
|
+
}
|
|
360
|
+
if (shouldSeed) {
|
|
361
|
+
if (verbose)
|
|
362
|
+
console.log("\uD83C\uDF31 Running seeders...");
|
|
363
|
+
const seedResult = await exec(config.seed.command, {
|
|
364
|
+
cwd: config.seed.cwd,
|
|
365
|
+
verbose,
|
|
366
|
+
throwOnError: false
|
|
367
|
+
});
|
|
368
|
+
if (seedResult.exitCode !== 0) {
|
|
369
|
+
console.error("❌ Seeding failed");
|
|
370
|
+
console.error(seedResult.stderr);
|
|
371
|
+
} else {
|
|
372
|
+
if (verbose)
|
|
373
|
+
console.log("✓ Seeding complete");
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
if (verbose)
|
|
377
|
+
console.log("✓ Database already has data, skipping seeders");
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (shouldStartServers && Object.keys(apps).length > 0) {
|
|
381
|
+
if (config.hooks?.beforeServers) {
|
|
382
|
+
await config.hooks.beforeServers(getHookContext());
|
|
383
|
+
}
|
|
384
|
+
if (productionBuild) {
|
|
385
|
+
buildApps(apps, root, envVars, { verbose });
|
|
386
|
+
}
|
|
387
|
+
const pids = await startDevServers(apps, root, envVars, ports, {
|
|
388
|
+
verbose,
|
|
389
|
+
productionBuild,
|
|
390
|
+
isCI: isCI2
|
|
391
|
+
});
|
|
392
|
+
if (verbose)
|
|
393
|
+
console.log("⏳ Waiting for servers to be ready...");
|
|
394
|
+
await waitForDevServers(apps, ports, {
|
|
395
|
+
timeout: isCI2 ? 120000 : 60000,
|
|
396
|
+
verbose,
|
|
397
|
+
productionBuild
|
|
398
|
+
});
|
|
399
|
+
if (config.hooks?.afterServers) {
|
|
400
|
+
await config.hooks.afterServers(getHookContext());
|
|
401
|
+
}
|
|
402
|
+
if (verbose)
|
|
403
|
+
console.log(`✅ Environment ready
|
|
404
|
+
`);
|
|
405
|
+
return pids;
|
|
406
|
+
}
|
|
407
|
+
if (verbose)
|
|
408
|
+
console.log(`✅ Containers ready
|
|
409
|
+
`);
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
async function stop(stopOptions = {}) {
|
|
413
|
+
const { verbose = true, removeVolumes = false } = stopOptions;
|
|
414
|
+
ensureComposeFile();
|
|
415
|
+
if (config.hooks?.beforeStop) {
|
|
416
|
+
await config.hooks.beforeStop(getHookContext());
|
|
417
|
+
}
|
|
418
|
+
stopContainers(root, projectName, {
|
|
419
|
+
verbose,
|
|
420
|
+
removeVolumes,
|
|
421
|
+
composeFile
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
async function restart() {
|
|
425
|
+
await stop();
|
|
426
|
+
await start({ startServers: false });
|
|
427
|
+
}
|
|
428
|
+
async function isRunning() {
|
|
429
|
+
const serviceCount = Object.keys(services).length;
|
|
430
|
+
return areContainersRunning(projectName, serviceCount);
|
|
431
|
+
}
|
|
432
|
+
async function startServersOnly(options2 = {}) {
|
|
433
|
+
const { productionBuild = false, verbose = true } = options2;
|
|
434
|
+
const envVars = buildEnvVars(productionBuild);
|
|
435
|
+
const isCI2 = process.env.CI === "true";
|
|
436
|
+
if (productionBuild) {
|
|
437
|
+
buildApps(apps, root, envVars, { verbose });
|
|
438
|
+
}
|
|
439
|
+
return startDevServers(apps, root, envVars, ports, {
|
|
440
|
+
verbose,
|
|
441
|
+
productionBuild,
|
|
442
|
+
isCI: isCI2
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
async function waitForServersReady(options2 = {}) {
|
|
446
|
+
const { timeout = 60000, productionBuild = false } = options2;
|
|
447
|
+
await waitForDevServers(apps, ports, { timeout, productionBuild });
|
|
448
|
+
}
|
|
449
|
+
function logInfo(label = "Docker Dev") {
|
|
450
|
+
logEnvironmentInfo({
|
|
451
|
+
label,
|
|
452
|
+
projectName,
|
|
453
|
+
services,
|
|
454
|
+
apps,
|
|
455
|
+
ports,
|
|
456
|
+
localIp,
|
|
457
|
+
worktree,
|
|
458
|
+
portOffset,
|
|
459
|
+
projectSuffix
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
async function waitForServerUrl(url, timeout) {
|
|
463
|
+
await waitForServer(url, { timeout });
|
|
464
|
+
}
|
|
465
|
+
function startHeartbeat2(intervalMs) {
|
|
466
|
+
startHeartbeat(projectName, intervalMs);
|
|
467
|
+
}
|
|
468
|
+
function stopHeartbeat2() {
|
|
469
|
+
stopHeartbeat();
|
|
470
|
+
}
|
|
471
|
+
async function spawnWatchdog2(timeoutMinutes) {
|
|
472
|
+
await spawnWatchdog(projectName, root, {
|
|
473
|
+
timeoutMinutes,
|
|
474
|
+
verbose: true,
|
|
475
|
+
composeFile
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
function stopWatchdog2() {
|
|
479
|
+
stopWatchdog(projectName);
|
|
480
|
+
}
|
|
481
|
+
function getExpoApiUrl() {
|
|
482
|
+
const apiPort = ports.api;
|
|
483
|
+
const url = `http://${localIp}:${apiPort}`;
|
|
484
|
+
logExpoApiUrl(url);
|
|
485
|
+
return url;
|
|
486
|
+
}
|
|
487
|
+
function getFrontendPort() {
|
|
488
|
+
const port = ports.platform;
|
|
489
|
+
logFrontendPort(port);
|
|
490
|
+
return port;
|
|
491
|
+
}
|
|
492
|
+
function withSuffix(newSuffix) {
|
|
493
|
+
return createDevEnvironment(config, { suffix: newSuffix });
|
|
494
|
+
}
|
|
495
|
+
const env = {
|
|
496
|
+
projectName,
|
|
497
|
+
ports,
|
|
498
|
+
urls,
|
|
499
|
+
apps,
|
|
500
|
+
portOffset,
|
|
501
|
+
isWorktree: worktree,
|
|
502
|
+
localIp,
|
|
503
|
+
root,
|
|
504
|
+
composeFile,
|
|
505
|
+
start,
|
|
506
|
+
stop,
|
|
507
|
+
restart,
|
|
508
|
+
isRunning,
|
|
509
|
+
startServers: startServersOnly,
|
|
510
|
+
stopProcess,
|
|
511
|
+
waitForServers: waitForServersReady,
|
|
512
|
+
buildEnvVars,
|
|
513
|
+
ensureComposeFile,
|
|
514
|
+
exec,
|
|
515
|
+
waitForServer: waitForServerUrl,
|
|
516
|
+
logInfo,
|
|
517
|
+
getExpoApiUrl,
|
|
518
|
+
getFrontendPort,
|
|
519
|
+
startHeartbeat: startHeartbeat2,
|
|
520
|
+
stopHeartbeat: stopHeartbeat2,
|
|
521
|
+
spawnWatchdog: spawnWatchdog2,
|
|
522
|
+
stopWatchdog: stopWatchdog2,
|
|
523
|
+
prisma: undefined,
|
|
524
|
+
withSuffix
|
|
525
|
+
};
|
|
526
|
+
if (config.prisma) {
|
|
527
|
+
env.prisma = createPrismaRunner(env, config.prisma);
|
|
528
|
+
}
|
|
529
|
+
return env;
|
|
530
|
+
}
|
|
531
|
+
export { createDevEnvironment };
|