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,187 @@
|
|
|
1
|
+
// core/ports.ts
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
function findMonorepoRoot(startDir) {
|
|
6
|
+
let dir = startDir ?? process.cwd();
|
|
7
|
+
while (dir !== "/") {
|
|
8
|
+
try {
|
|
9
|
+
const pkgPath = resolve(dir, "package.json");
|
|
10
|
+
if (existsSync(pkgPath)) {
|
|
11
|
+
const content = readFileSync(pkgPath, "utf-8");
|
|
12
|
+
const pkg = JSON.parse(content);
|
|
13
|
+
if (pkg.workspaces) {
|
|
14
|
+
return dir;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
} catch {}
|
|
18
|
+
dir = dirname(dir);
|
|
19
|
+
}
|
|
20
|
+
return process.cwd();
|
|
21
|
+
}
|
|
22
|
+
function getWorktreeName(root) {
|
|
23
|
+
const monorepoRoot = root ?? findMonorepoRoot();
|
|
24
|
+
const gitPath = resolve(monorepoRoot, ".git");
|
|
25
|
+
try {
|
|
26
|
+
if (!existsSync(gitPath) || !statSync(gitPath).isFile()) return null;
|
|
27
|
+
const content = readFileSync(gitPath, "utf-8").trim();
|
|
28
|
+
const match = content.match(/^gitdir:\s*(.+)$/);
|
|
29
|
+
if (!match?.[1]) return null;
|
|
30
|
+
return basename(match[1]);
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function isWorktree(root) {
|
|
36
|
+
return getWorktreeName(root) !== null;
|
|
37
|
+
}
|
|
38
|
+
function sanitizeProjectSuffix(value) {
|
|
39
|
+
return value
|
|
40
|
+
.toLowerCase()
|
|
41
|
+
.replace(/[^a-z0-9-]/g, "-")
|
|
42
|
+
.replace(/-+/g, "-")
|
|
43
|
+
.replace(/^-+|-+$/g, "");
|
|
44
|
+
}
|
|
45
|
+
function getWorktreeProjectSuffix(root) {
|
|
46
|
+
const worktreeName = getWorktreeName(root);
|
|
47
|
+
if (!worktreeName) return null;
|
|
48
|
+
const sanitized = sanitizeProjectSuffix(worktreeName);
|
|
49
|
+
return sanitized || "worktree";
|
|
50
|
+
}
|
|
51
|
+
function simpleHash(str) {
|
|
52
|
+
let hash = 0;
|
|
53
|
+
for (let i = 0; i < str.length; i++) {
|
|
54
|
+
const char = str.charCodeAt(i);
|
|
55
|
+
hash = (hash << 5) - hash + char;
|
|
56
|
+
hash = hash & hash;
|
|
57
|
+
}
|
|
58
|
+
return Math.abs(hash);
|
|
59
|
+
}
|
|
60
|
+
function calculatePortOffset(suffix, root) {
|
|
61
|
+
const worktreeName = getWorktreeName(root);
|
|
62
|
+
if (!worktreeName) return 0;
|
|
63
|
+
const hashInput = suffix ? `${worktreeName}-${suffix}` : worktreeName;
|
|
64
|
+
return 10 + (simpleHash(hashInput) % 90);
|
|
65
|
+
}
|
|
66
|
+
function getProjectName(prefix, suffix, root) {
|
|
67
|
+
const monorepoRoot = root ?? findMonorepoRoot();
|
|
68
|
+
const dirName = basename(monorepoRoot);
|
|
69
|
+
const baseName = `${prefix}-${dirName.toLowerCase().replace(/[^a-z0-9-]/g, "-")}`;
|
|
70
|
+
return suffix ? `${baseName}-${suffix}` : baseName;
|
|
71
|
+
}
|
|
72
|
+
function computeDevIdentity(options) {
|
|
73
|
+
const {
|
|
74
|
+
projectPrefix,
|
|
75
|
+
suffix,
|
|
76
|
+
root: providedRoot,
|
|
77
|
+
worktreeIsolation = true,
|
|
78
|
+
} = options;
|
|
79
|
+
const root = providedRoot ?? findMonorepoRoot();
|
|
80
|
+
const worktree = isWorktree(root);
|
|
81
|
+
const worktreeSuffix =
|
|
82
|
+
worktree && worktreeIsolation ? getWorktreeProjectSuffix(root) : null;
|
|
83
|
+
const projectSuffix =
|
|
84
|
+
[suffix, worktreeSuffix].filter(Boolean).join("-") || undefined;
|
|
85
|
+
const projectName = getProjectName(projectPrefix, projectSuffix, root);
|
|
86
|
+
const portOffset = calculatePortOffset(suffix, root);
|
|
87
|
+
return {
|
|
88
|
+
worktree,
|
|
89
|
+
worktreeSuffix,
|
|
90
|
+
projectSuffix,
|
|
91
|
+
projectName,
|
|
92
|
+
portOffset,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function computePorts(services, apps, offset) {
|
|
96
|
+
const ports = {};
|
|
97
|
+
for (const [name, config] of Object.entries(services)) {
|
|
98
|
+
ports[name] = config.port + offset;
|
|
99
|
+
if (config.secondaryPort) {
|
|
100
|
+
ports[`${name}Secondary`] = config.secondaryPort + offset;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (apps) {
|
|
104
|
+
for (const [name, config] of Object.entries(apps)) {
|
|
105
|
+
ports[name] = config.port + offset;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return ports;
|
|
109
|
+
}
|
|
110
|
+
var SERVICE_DEFAULTS = {
|
|
111
|
+
postgres: { user: "postgres", password: "postgres", database: "postgres" },
|
|
112
|
+
postgresql: { user: "postgres", password: "postgres", database: "postgres" },
|
|
113
|
+
redis: { user: "", password: "", database: "" },
|
|
114
|
+
clickhouse: { user: "default", password: "clickhouse", database: "default" },
|
|
115
|
+
mysql: { user: "root", password: "root", database: "mysql" },
|
|
116
|
+
mongodb: { user: "", password: "", database: "" },
|
|
117
|
+
};
|
|
118
|
+
function buildServiceUrl(serviceName, ctx, config) {
|
|
119
|
+
const defaults = SERVICE_DEFAULTS[serviceName];
|
|
120
|
+
if (!defaults && !config.database) return null;
|
|
121
|
+
const user = config.user ?? defaults?.user ?? "";
|
|
122
|
+
const password = config.password ?? defaults?.password ?? "";
|
|
123
|
+
const database = config.database ?? defaults?.database ?? "";
|
|
124
|
+
switch (serviceName) {
|
|
125
|
+
case "postgres":
|
|
126
|
+
case "postgresql":
|
|
127
|
+
return `postgresql://${user}:${password}@${ctx.host}:${ctx.port}/${database}`;
|
|
128
|
+
case "redis":
|
|
129
|
+
return `redis://${ctx.host}:${ctx.port}`;
|
|
130
|
+
case "clickhouse":
|
|
131
|
+
return `http://${user}:${password}@${ctx.host}:${ctx.port}/${database}`;
|
|
132
|
+
case "mysql":
|
|
133
|
+
return `mysql://${user}:${password}@${ctx.host}:${ctx.port}/${database}`;
|
|
134
|
+
case "mongodb":
|
|
135
|
+
return `mongodb://${ctx.host}:${ctx.port}/${database}`;
|
|
136
|
+
default:
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function computeUrls(services, apps, ports, localIp) {
|
|
141
|
+
const urls = {};
|
|
142
|
+
const host = "localhost";
|
|
143
|
+
for (const [name, config] of Object.entries(services)) {
|
|
144
|
+
const port = ports[name];
|
|
145
|
+
const secondaryPort = ports[`${name}Secondary`];
|
|
146
|
+
if (port === undefined) continue;
|
|
147
|
+
const ctx = { port, secondaryPort, host, localIp };
|
|
148
|
+
if (config.urlTemplate) {
|
|
149
|
+
urls[name] = config.urlTemplate(ctx);
|
|
150
|
+
} else {
|
|
151
|
+
const builtUrl = buildServiceUrl(
|
|
152
|
+
name,
|
|
153
|
+
{ port, host },
|
|
154
|
+
{
|
|
155
|
+
database: config.database,
|
|
156
|
+
user: config.user,
|
|
157
|
+
password: config.password,
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
if (builtUrl) {
|
|
161
|
+
urls[name] = builtUrl;
|
|
162
|
+
} else {
|
|
163
|
+
urls[name] = `http://${host}:${port}`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (apps) {
|
|
168
|
+
for (const [name, _config] of Object.entries(apps)) {
|
|
169
|
+
const port = ports[name];
|
|
170
|
+
urls[name] = `http://${host}:${port}`;
|
|
171
|
+
urls[`${name}Local`] = `http://${localIp}:${port}`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return urls;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
findMonorepoRoot,
|
|
179
|
+
getWorktreeName,
|
|
180
|
+
isWorktree,
|
|
181
|
+
getWorktreeProjectSuffix,
|
|
182
|
+
calculatePortOffset,
|
|
183
|
+
getProjectName,
|
|
184
|
+
computeDevIdentity,
|
|
185
|
+
computePorts,
|
|
186
|
+
computeUrls,
|
|
187
|
+
};
|
package/dist/index-75y4cg2z.js
CHANGED
|
@@ -1,58 +1,66 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createDevEnvironment
|
|
3
|
-
} from "./index-ndnmnsej.js";
|
|
4
|
-
|
|
5
1
|
// loader.ts
|
|
6
2
|
import { existsSync } from "node:fs";
|
|
7
3
|
import { dirname, join } from "node:path";
|
|
4
|
+
import { createDevEnvironment } from "./index-ndnmnsej.js";
|
|
5
|
+
|
|
8
6
|
var CONFIG_FILES = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
"dev.config.ts",
|
|
8
|
+
"dev.config.js",
|
|
9
|
+
"dev-tools.config.ts",
|
|
10
|
+
"dev-tools.config.js",
|
|
13
11
|
];
|
|
14
12
|
function findConfigFile(startDir) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
let currentDir = startDir;
|
|
14
|
+
while (true) {
|
|
15
|
+
for (const file of CONFIG_FILES) {
|
|
16
|
+
const configPath = join(currentDir, file);
|
|
17
|
+
if (existsSync(configPath)) {
|
|
18
|
+
return configPath;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const parentDir = dirname(currentDir);
|
|
22
|
+
if (parentDir === currentDir) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
currentDir = parentDir;
|
|
26
|
+
}
|
|
29
27
|
}
|
|
30
28
|
var cachedEnv = null;
|
|
31
29
|
async function loadDevEnv(options) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
if (cachedEnv && !options?.reload) {
|
|
31
|
+
return cachedEnv;
|
|
32
|
+
}
|
|
33
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
34
|
+
const configPath = findConfigFile(cwd);
|
|
35
|
+
if (configPath) {
|
|
36
|
+
const mod = await import(configPath);
|
|
37
|
+
const config = mod.default;
|
|
38
|
+
if (!config?.projectPrefix || !config?.services) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Invalid config in "${configPath}". Use defineDevConfig() and export as default.`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
cachedEnv = createDevEnvironment(config);
|
|
44
|
+
return cachedEnv;
|
|
45
|
+
}
|
|
46
|
+
throw new Error(
|
|
47
|
+
`No config file found. Create dev.config.ts with: export default defineDevConfig({ ... })`,
|
|
48
|
+
);
|
|
47
49
|
}
|
|
48
50
|
function getDevEnv() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
if (!cachedEnv) {
|
|
52
|
+
throw new Error("Dev environment not loaded. Call loadDevEnv() first.");
|
|
53
|
+
}
|
|
54
|
+
return cachedEnv;
|
|
53
55
|
}
|
|
54
56
|
function clearDevEnvCache() {
|
|
55
|
-
|
|
57
|
+
cachedEnv = null;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
export {
|
|
60
|
+
export {
|
|
61
|
+
CONFIG_FILES,
|
|
62
|
+
findConfigFile,
|
|
63
|
+
loadDevEnv,
|
|
64
|
+
getDevEnv,
|
|
65
|
+
clearDevEnvCache,
|
|
66
|
+
};
|
package/dist/index-7ja4ywyj.js
CHANGED
|
@@ -1,142 +1,141 @@
|
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
if (result.stderr) {
|
|
45
|
+
console.error(result.stderr);
|
|
46
|
+
}
|
|
47
|
+
if (result.stdout) {
|
|
48
|
+
console.error(result.stdout);
|
|
49
|
+
}
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
console.log("");
|
|
53
|
+
console.log("✅ Seeding complete");
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
if (args.includes("--up-only")) {
|
|
57
|
+
console.log("");
|
|
58
|
+
console.log("✅ Containers started. Environment ready.");
|
|
59
|
+
console.log("");
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
if (watchdog) {
|
|
63
|
+
await spawnWatchdog(env.projectName, env.root, {
|
|
64
|
+
timeoutMinutes: watchdogTimeout,
|
|
65
|
+
verbose: true,
|
|
66
|
+
});
|
|
67
|
+
startHeartbeat(env.projectName);
|
|
68
|
+
}
|
|
69
|
+
const command = devServersCommand ?? buildDevServersCommand(env.apps);
|
|
70
|
+
if (!command) {
|
|
71
|
+
console.log("✅ Containers ready. No apps configured.");
|
|
72
|
+
await new Promise(() => {});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
await killProcessesOnAppPorts(env.apps, env.ports);
|
|
76
|
+
console.log("");
|
|
77
|
+
console.log("\uD83D\uDD27 Starting dev servers...");
|
|
78
|
+
console.log("");
|
|
79
|
+
await runCommand(command, env.root, env.buildEnvVars());
|
|
80
|
+
stopHeartbeat();
|
|
83
81
|
}
|
|
84
82
|
function buildDevServersCommand(apps) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
const appEntries = Object.entries(apps);
|
|
84
|
+
if (appEntries.length === 0) return null;
|
|
85
|
+
const commands = [];
|
|
86
|
+
const names = [];
|
|
87
|
+
const colors = ["blue", "green", "yellow", "magenta", "cyan", "red"];
|
|
88
|
+
for (const [name, config] of appEntries) {
|
|
89
|
+
names.push(name);
|
|
90
|
+
const cwdPart = config.cwd ? `--cwd ${config.cwd}` : "";
|
|
91
|
+
commands.push(
|
|
92
|
+
`"bun run ${cwdPart} ${config.devCommand}"`.replace(/\s+/g, " ").trim(),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const namesArg = `-n ${names.join(",")}`;
|
|
96
|
+
const colorsArg = `-c ${colors.slice(0, names.length).join(",")}`;
|
|
97
|
+
const commandsArg = commands.join(" ");
|
|
98
|
+
return `bun concurrently ${namesArg} ${colorsArg} ${commandsArg}`;
|
|
100
99
|
}
|
|
101
100
|
function runCommand(command, cwd, envVars) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
const proc = spawn(command, [], {
|
|
103
|
+
cwd,
|
|
104
|
+
env: { ...process.env, ...envVars },
|
|
105
|
+
stdio: "inherit",
|
|
106
|
+
shell: true,
|
|
107
|
+
});
|
|
108
|
+
proc.on("close", (code) => {
|
|
109
|
+
if (code === 0 || code === null) {
|
|
110
|
+
resolve();
|
|
111
|
+
} else {
|
|
112
|
+
reject(new Error(`Command exited with code ${code}`));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
proc.on("error", reject);
|
|
116
|
+
const cleanup = () => {
|
|
117
|
+
proc.kill("SIGTERM");
|
|
118
|
+
};
|
|
119
|
+
process.on("SIGINT", cleanup);
|
|
120
|
+
process.on("SIGTERM", cleanup);
|
|
121
|
+
});
|
|
123
122
|
}
|
|
124
123
|
function hasFlag(args, flag) {
|
|
125
|
-
|
|
124
|
+
return args.includes(flag);
|
|
126
125
|
}
|
|
127
126
|
function getFlagValue(args, flag) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
const prefixed = args.find((arg) => arg.startsWith(`${flag}=`));
|
|
128
|
+
if (prefixed) {
|
|
129
|
+
return prefixed.split("=")[1];
|
|
130
|
+
}
|
|
131
|
+
const index = args.indexOf(flag);
|
|
132
|
+
if (index !== -1 && index + 1 < args.length) {
|
|
133
|
+
const nextArg = args[index + 1];
|
|
134
|
+
if (nextArg !== undefined && !nextArg.startsWith("-")) {
|
|
135
|
+
return nextArg;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
140
139
|
}
|
|
141
140
|
|
|
142
141
|
export { runCli, hasFlag, getFlagValue };
|