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
package/dist/index-8hbbj1mp.js
CHANGED
|
@@ -1,136 +1,135 @@
|
|
|
1
|
+
// cli.ts
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { killProcessesOnAppPorts } from "./index-1yvbwj4k.js";
|
|
1
4
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
spawnWatchdog,
|
|
6
|
+
startHeartbeat,
|
|
7
|
+
stopHeartbeat,
|
|
5
8
|
} from "./index-ggq3yryx.js";
|
|
6
|
-
import {
|
|
7
|
-
killProcessesOnAppPorts
|
|
8
|
-
} from "./index-1yvbwj4k.js";
|
|
9
9
|
|
|
10
|
-
// cli.ts
|
|
11
|
-
import { spawn } from "node:child_process";
|
|
12
10
|
async function runCli(env, options = {}) {
|
|
13
|
-
|
|
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
|
-
|
|
11
|
+
const {
|
|
12
|
+
args = process.argv.slice(2),
|
|
13
|
+
watchdog = true,
|
|
14
|
+
watchdogTimeout = 10,
|
|
15
|
+
devServersCommand,
|
|
16
|
+
} = options;
|
|
17
|
+
env.logInfo();
|
|
18
|
+
if (args.includes("--down")) {
|
|
19
|
+
await env.stop();
|
|
20
|
+
process.exit(0);
|
|
21
|
+
}
|
|
22
|
+
if (args.includes("--reset")) {
|
|
23
|
+
await env.stop({ removeVolumes: true });
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
const running = await env.isRunning();
|
|
27
|
+
if (running) {
|
|
28
|
+
console.log("✓ Containers already running");
|
|
29
|
+
} else {
|
|
30
|
+
await env.start({ startServers: false, wait: true });
|
|
31
|
+
}
|
|
32
|
+
if (args.includes("--migrate")) {
|
|
33
|
+
console.log("");
|
|
34
|
+
console.log("✅ Migrations applied successfully");
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
if (args.includes("--seed")) {
|
|
38
|
+
console.log("\uD83C\uDF31 Running seeders...");
|
|
39
|
+
const result = await env.exec("bun run run:seeder", {
|
|
40
|
+
throwOnError: false,
|
|
41
|
+
});
|
|
42
|
+
if (result.exitCode !== 0) {
|
|
43
|
+
console.error("❌ Seeding failed");
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
console.log("");
|
|
47
|
+
console.log("✅ Seeding complete");
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
if (args.includes("--up-only")) {
|
|
51
|
+
console.log("");
|
|
52
|
+
console.log("✅ Containers started. Environment ready.");
|
|
53
|
+
console.log("");
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
if (watchdog) {
|
|
57
|
+
await spawnWatchdog(env.projectName, env.root, {
|
|
58
|
+
timeoutMinutes: watchdogTimeout,
|
|
59
|
+
verbose: true,
|
|
60
|
+
});
|
|
61
|
+
startHeartbeat(env.projectName);
|
|
62
|
+
}
|
|
63
|
+
const command = devServersCommand ?? buildDevServersCommand(env.apps);
|
|
64
|
+
if (!command) {
|
|
65
|
+
console.log("✅ Containers ready. No apps configured.");
|
|
66
|
+
await new Promise(() => {});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
await killProcessesOnAppPorts(env.apps, env.ports);
|
|
70
|
+
console.log("");
|
|
71
|
+
console.log("\uD83D\uDD27 Starting dev servers...");
|
|
72
|
+
console.log("");
|
|
73
|
+
await runCommand(command, env.root, env.buildEnvVars());
|
|
74
|
+
stopHeartbeat();
|
|
77
75
|
}
|
|
78
76
|
function buildDevServersCommand(apps) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
77
|
+
const appEntries = Object.entries(apps);
|
|
78
|
+
if (appEntries.length === 0) return null;
|
|
79
|
+
const commands = [];
|
|
80
|
+
const names = [];
|
|
81
|
+
const colors = ["blue", "green", "yellow", "magenta", "cyan", "red"];
|
|
82
|
+
for (const [name, config] of appEntries) {
|
|
83
|
+
names.push(name);
|
|
84
|
+
const cwdPart = config.cwd ? `--cwd ${config.cwd}` : "";
|
|
85
|
+
commands.push(
|
|
86
|
+
`"bun run ${cwdPart} ${config.devCommand}"`.replace(/\s+/g, " ").trim(),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const namesArg = `-n ${names.join(",")}`;
|
|
90
|
+
const colorsArg = `-c ${colors.slice(0, names.length).join(",")}`;
|
|
91
|
+
const commandsArg = commands.join(" ");
|
|
92
|
+
return `bun concurrently ${namesArg} ${colorsArg} ${commandsArg}`;
|
|
94
93
|
}
|
|
95
94
|
function runCommand(command, cwd, envVars) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const proc = spawn(command, [], {
|
|
97
|
+
cwd,
|
|
98
|
+
env: { ...process.env, ...envVars },
|
|
99
|
+
stdio: "inherit",
|
|
100
|
+
shell: true,
|
|
101
|
+
});
|
|
102
|
+
proc.on("close", (code) => {
|
|
103
|
+
if (code === 0 || code === null) {
|
|
104
|
+
resolve();
|
|
105
|
+
} else {
|
|
106
|
+
reject(new Error(`Command exited with code ${code}`));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
proc.on("error", reject);
|
|
110
|
+
const cleanup = () => {
|
|
111
|
+
proc.kill("SIGTERM");
|
|
112
|
+
};
|
|
113
|
+
process.on("SIGINT", cleanup);
|
|
114
|
+
process.on("SIGTERM", cleanup);
|
|
115
|
+
});
|
|
117
116
|
}
|
|
118
117
|
function hasFlag(args, flag) {
|
|
119
|
-
|
|
118
|
+
return args.includes(flag);
|
|
120
119
|
}
|
|
121
120
|
function getFlagValue(args, flag) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
const prefixed = args.find((arg) => arg.startsWith(`${flag}=`));
|
|
122
|
+
if (prefixed) {
|
|
123
|
+
return prefixed.split("=")[1];
|
|
124
|
+
}
|
|
125
|
+
const index = args.indexOf(flag);
|
|
126
|
+
if (index !== -1 && index + 1 < args.length) {
|
|
127
|
+
const nextArg = args[index + 1];
|
|
128
|
+
if (nextArg !== undefined && !nextArg.startsWith("-")) {
|
|
129
|
+
return nextArg;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
134
133
|
}
|
|
135
134
|
|
|
136
135
|
export { runCli, hasFlag, getFlagValue };
|
package/dist/index-8xj2p5n5.js
CHANGED
|
@@ -1,124 +1,145 @@
|
|
|
1
|
-
import {
|
|
2
|
-
calculatePortOffset,
|
|
3
|
-
computePorts,
|
|
4
|
-
computeUrls
|
|
5
|
-
} from "./index-731rzzfp.js";
|
|
6
|
-
|
|
7
1
|
// core/network.ts
|
|
8
2
|
import { networkInterfaces } from "node:os";
|
|
3
|
+
import {
|
|
4
|
+
calculatePortOffset,
|
|
5
|
+
computePorts,
|
|
6
|
+
computeUrls,
|
|
7
|
+
} from "./index-731rzzfp.js";
|
|
9
8
|
|
|
10
9
|
// core/utils.ts
|
|
11
10
|
function sleep(ms) {
|
|
12
|
-
|
|
11
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
13
12
|
}
|
|
14
13
|
function isCI() {
|
|
15
|
-
|
|
14
|
+
return (
|
|
15
|
+
process.env.CI === "true" ||
|
|
16
|
+
process.env.CI === "1" ||
|
|
17
|
+
process.env.GITHUB_ACTIONS === "true" ||
|
|
18
|
+
process.env.GITLAB_CI === "true" ||
|
|
19
|
+
process.env.CIRCLECI === "true" ||
|
|
20
|
+
process.env.JENKINS_URL !== undefined
|
|
21
|
+
);
|
|
16
22
|
}
|
|
17
23
|
function logFrontendPort(port) {
|
|
18
|
-
|
|
24
|
+
console.log(`using_frontend_port:${port}`);
|
|
19
25
|
}
|
|
20
26
|
function getEnvVar(config, name, options = {}) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
const { log = true } = options;
|
|
28
|
+
const offset = calculatePortOffset();
|
|
29
|
+
const localIp = getLocalIp();
|
|
30
|
+
const ports = computePorts(config.services, config.apps, offset);
|
|
31
|
+
const urls = computeUrls(config.services, config.apps, ports, localIp);
|
|
32
|
+
const envVars = config.envVars?.(ports, urls, {
|
|
33
|
+
projectName: config.projectPrefix,
|
|
34
|
+
localIp,
|
|
35
|
+
portOffset: offset,
|
|
36
|
+
});
|
|
37
|
+
const value = envVars?.[name];
|
|
38
|
+
if (log && name === "VITE_PORT" && typeof value === "number") {
|
|
39
|
+
logFrontendPort(value);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
36
42
|
}
|
|
37
43
|
function logApiUrl(url) {
|
|
38
|
-
|
|
44
|
+
console.log(`using_api_url:${url}`);
|
|
39
45
|
}
|
|
40
46
|
function logExpoApiUrl(url) {
|
|
41
|
-
|
|
47
|
+
console.log(`using_expo_api_url:${url}`);
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
// core/network.ts
|
|
45
51
|
function getLocalIp() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return "127.0.0.1";
|
|
52
|
+
const interfaces = networkInterfaces();
|
|
53
|
+
for (const name of Object.keys(interfaces)) {
|
|
54
|
+
const nets = interfaces[name];
|
|
55
|
+
if (!nets) continue;
|
|
56
|
+
for (const net of nets) {
|
|
57
|
+
if (net.family === "IPv4" && !net.internal) {
|
|
58
|
+
return net.address;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return "127.0.0.1";
|
|
58
63
|
}
|
|
59
64
|
async function waitForServer(url, options = {}) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
const { timeout = 30000, interval = 2000, verbose = false } = options;
|
|
66
|
+
const start = Date.now();
|
|
67
|
+
let attempts = 0;
|
|
68
|
+
while (Date.now() - start < timeout) {
|
|
69
|
+
attempts++;
|
|
70
|
+
const controller = new AbortController();
|
|
71
|
+
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
72
|
+
try {
|
|
73
|
+
const response = await fetch(url, {
|
|
74
|
+
signal: controller.signal,
|
|
75
|
+
});
|
|
76
|
+
clearTimeout(timeoutId);
|
|
77
|
+
if (response.ok || response.status === 404) {
|
|
78
|
+
if (verbose) {
|
|
79
|
+
console.log(` ✓ ${url} ready after ${attempts} attempts`);
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
} catch {
|
|
84
|
+
clearTimeout(timeoutId);
|
|
85
|
+
if (verbose && attempts % 5 === 0) {
|
|
86
|
+
console.log(
|
|
87
|
+
` ⏳ Waiting for ${url}... (${Math.round((Date.now() - start) / 1000)}s)`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
await sleep(interval);
|
|
92
|
+
}
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Server at ${url} did not respond within ${timeout}ms after ${attempts} attempts`,
|
|
95
|
+
);
|
|
87
96
|
}
|
|
88
97
|
async function waitForDevServers(apps, ports, options = {}) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (verbose)
|
|
102
|
-
console.log("✓ All servers ready");
|
|
98
|
+
const { timeout = 60000, verbose = true } = options;
|
|
99
|
+
if (verbose) console.log("⏳ Waiting for servers to be ready...");
|
|
100
|
+
const promises = [];
|
|
101
|
+
for (const [name, config] of Object.entries(apps)) {
|
|
102
|
+
const port = ports[name];
|
|
103
|
+
const healthPath = config.healthEndpoint ?? "/";
|
|
104
|
+
const url = `http://localhost:${port}${healthPath}`;
|
|
105
|
+
const appTimeout = config.healthTimeout ?? timeout;
|
|
106
|
+
promises.push(waitForServer(url, { timeout: appTimeout, verbose }));
|
|
107
|
+
}
|
|
108
|
+
await Promise.all(promises);
|
|
109
|
+
if (verbose) console.log("✓ All servers ready");
|
|
103
110
|
}
|
|
104
111
|
async function isPortAvailable(port) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
const timeoutId = setTimeout(() => controller.abort(), 500);
|
|
114
|
+
try {
|
|
115
|
+
const _response = await fetch(`http://localhost:${port}/`, {
|
|
116
|
+
signal: controller.signal,
|
|
117
|
+
});
|
|
118
|
+
clearTimeout(timeoutId);
|
|
119
|
+
return false;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
clearTimeout(timeoutId);
|
|
122
|
+
if (error instanceof Error) {
|
|
123
|
+
if (
|
|
124
|
+
error.message.includes("ECONNREFUSED") ||
|
|
125
|
+
error.message.includes("fetch failed")
|
|
126
|
+
) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
122
132
|
}
|
|
123
133
|
|
|
124
|
-
export {
|
|
134
|
+
export {
|
|
135
|
+
getLocalIp,
|
|
136
|
+
waitForServer,
|
|
137
|
+
waitForDevServers,
|
|
138
|
+
isPortAvailable,
|
|
139
|
+
sleep,
|
|
140
|
+
isCI,
|
|
141
|
+
logFrontendPort,
|
|
142
|
+
getEnvVar,
|
|
143
|
+
logApiUrl,
|
|
144
|
+
logExpoApiUrl,
|
|
145
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/environment/logging.ts
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
function formatUrl(url) {
|
|
4
|
+
return pc.cyan(url.replace(/:(\d+)(\/?)/, (_, port, slash) => `:${pc.bold(port)}${slash}`));
|
|
5
|
+
}
|
|
6
|
+
function formatLabel(label, value, arrow = "➜") {
|
|
7
|
+
return ` ${pc.green(arrow)} ${pc.bold(label.padEnd(10))} ${value}`;
|
|
8
|
+
}
|
|
9
|
+
function formatDimLabel(label, value) {
|
|
10
|
+
return ` ${pc.dim("•")} ${pc.dim(label.padEnd(10))} ${pc.dim(value)}`;
|
|
11
|
+
}
|
|
12
|
+
function logEnvironmentInfo(input) {
|
|
13
|
+
const {
|
|
14
|
+
label,
|
|
15
|
+
projectName,
|
|
16
|
+
services,
|
|
17
|
+
apps,
|
|
18
|
+
ports,
|
|
19
|
+
localIp,
|
|
20
|
+
worktree,
|
|
21
|
+
portOffset,
|
|
22
|
+
projectSuffix
|
|
23
|
+
} = input;
|
|
24
|
+
const serviceNames = Object.keys(services);
|
|
25
|
+
const appNames = Object.keys(apps);
|
|
26
|
+
console.log("");
|
|
27
|
+
console.log(` ${pc.cyan(pc.bold(`\uD83D\uDC33 ${label}`))}`);
|
|
28
|
+
console.log(formatLabel("Project:", pc.white(projectName)));
|
|
29
|
+
if (serviceNames.length > 0) {
|
|
30
|
+
console.log("");
|
|
31
|
+
console.log(` ${pc.dim("─── Services ───")}`);
|
|
32
|
+
for (const name of serviceNames) {
|
|
33
|
+
const port = ports[name];
|
|
34
|
+
const url = `localhost:${port}`;
|
|
35
|
+
console.log(formatLabel(`${name}:`, formatUrl(`http://${url}`)));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (appNames.length > 0) {
|
|
39
|
+
console.log("");
|
|
40
|
+
console.log(` ${pc.dim("─── Applications ───")}`);
|
|
41
|
+
for (const name of appNames) {
|
|
42
|
+
const port = ports[name];
|
|
43
|
+
const localUrl = `http://localhost:${port}`;
|
|
44
|
+
const networkUrl = `http://${localIp}:${port}`;
|
|
45
|
+
console.log(` ${pc.green("➜")} ${pc.bold(pc.cyan(name))}`);
|
|
46
|
+
console.log(` ${pc.dim("Local:")} ${formatUrl(localUrl)}`);
|
|
47
|
+
console.log(` ${pc.dim("Network:")} ${formatUrl(networkUrl)}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log("");
|
|
51
|
+
console.log(` ${pc.dim("─── Environment ───")}`);
|
|
52
|
+
console.log(formatDimLabel("Worktree:", worktree ? "yes" : "no"));
|
|
53
|
+
console.log(formatDimLabel("Port offset:", portOffset > 0 ? `+${portOffset}` : "none"));
|
|
54
|
+
if (projectSuffix) {
|
|
55
|
+
console.log(formatDimLabel("Suffix:", projectSuffix));
|
|
56
|
+
}
|
|
57
|
+
console.log(formatDimLabel("Local IP:", localIp));
|
|
58
|
+
console.log("");
|
|
59
|
+
}
|
|
60
|
+
function logPublicUrls(tunnels) {
|
|
61
|
+
if (tunnels.length === 0)
|
|
62
|
+
return;
|
|
63
|
+
console.log("");
|
|
64
|
+
console.log(` ${pc.dim("─── Public URLs (Quick Tunnel) ───")}`);
|
|
65
|
+
for (const tunnel of tunnels) {
|
|
66
|
+
const label = `${tunnel.name} (${tunnel.kind})`;
|
|
67
|
+
console.log(formatLabel(`${label}:`, formatUrl(tunnel.publicUrl), "\uD83C\uDF10"));
|
|
68
|
+
console.log(formatDimLabel("Local target:", tunnel.localUrl));
|
|
69
|
+
}
|
|
70
|
+
console.log("");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { logEnvironmentInfo, logPublicUrls };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDevEnvironment
|
|
3
|
+
} from "./index-23ev345g.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 };
|