buncargo 1.0.29 → 3.2.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 +317 -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 +30 -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/quick-tunnel/cloudflared-process.d.ts +10 -0
- package/dist/core/quick-tunnel/constants.d.ts +9 -0
- package/dist/core/quick-tunnel/index.d.ts +17 -0
- package/dist/core/quick-tunnel/install.d.ts +1 -0
- package/dist/core/tunnel.d.ts +34 -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/only-apps.d.ts +10 -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-3eyrdxw9.js +577 -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-5aq985p4.js +250 -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-6cmex7m5.js +72 -0
- package/dist/index-6d6x175r.js +572 -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-7v19es2e.js +666 -0
- package/dist/index-8bw1cmz4.js +531 -0
- package/dist/index-8hbbj1mp.js +120 -121
- package/dist/index-8xj2p5n5.js +118 -97
- package/dist/index-9wyhzw0h.js +574 -0
- package/dist/index-ag90ry8t.js +576 -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-byeqyjrz.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-enj4zdma.js +574 -0
- 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-k370bech.js +72 -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-qa8akv6y.js +666 -0
- 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-vg55rq0y.js +250 -0
- package/dist/index-vhs88xhe.js +99 -95
- package/dist/index-vs81yaks.js +244 -0
- 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-x54nbgs7.js +355 -0
- package/dist/index-xkvd0nsd.js +187 -0
- package/dist/index-yedqxm1z.js +80 -0
- package/dist/index-yz4jfz7z.js +338 -0
- package/dist/index-zfjzzjkf.js +240 -199
- package/dist/index.d.ts +12 -8
- package/dist/index.js +56 -34
- 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 +544 -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 +55 -48
- package/readme.md +365 -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} +114 -10
- 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/quick-tunnel/cloudflared-process.ts +83 -0
- package/src/core/quick-tunnel/constants.ts +31 -0
- package/src/core/quick-tunnel/index.ts +96 -0
- package/src/core/quick-tunnel/install.ts +160 -0
- package/src/core/tunnel.ts +165 -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} +214 -141
- package/src/environment/index.ts +1 -0
- package/src/environment/logging.ts +115 -0
- package/src/environment/only-apps.ts +34 -0
- package/src/environment/seeding.ts +57 -0
- package/{index.ts → src/index.ts} +52 -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} +186 -8
- 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,428 @@
|
|
|
1
|
+
// src/docker-compose/generated-file.ts
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
// src/docker-compose/services/define-docker-service.ts
|
|
6
|
+
function defineDockerService(input) {
|
|
7
|
+
function createPresetDefinition(service) {
|
|
8
|
+
return {
|
|
9
|
+
kind: "preset",
|
|
10
|
+
preset: input.preset,
|
|
11
|
+
service
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function toServiceConfig(options = {}) {
|
|
15
|
+
const base = {
|
|
16
|
+
port: options.port ?? input.defaults.port,
|
|
17
|
+
expose: options.expose,
|
|
18
|
+
healthCheck: options.healthCheck ?? input.defaults.healthCheck,
|
|
19
|
+
database: options.database,
|
|
20
|
+
user: options.user,
|
|
21
|
+
password: options.password,
|
|
22
|
+
serviceName: options.serviceName,
|
|
23
|
+
docker: createPresetDefinition(options.docker)
|
|
24
|
+
};
|
|
25
|
+
return input.enhanceServiceConfig ? input.enhanceServiceConfig(base, options) : base;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
preset: input.preset,
|
|
29
|
+
defaults: input.defaults,
|
|
30
|
+
build: input.build,
|
|
31
|
+
createPresetDefinition,
|
|
32
|
+
toServiceConfig
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/docker-compose/services/shared.ts
|
|
37
|
+
var DEFAULT_HEALTHCHECK_SETTINGS = {
|
|
38
|
+
interval: "250ms",
|
|
39
|
+
timeout: "5s",
|
|
40
|
+
retries: 20
|
|
41
|
+
};
|
|
42
|
+
function getPortEnvName(portKey) {
|
|
43
|
+
return `${portKey.toUpperCase()}_PORT`;
|
|
44
|
+
}
|
|
45
|
+
function getDefaultPortBindings(serviceKey, config, preset) {
|
|
46
|
+
const envName = getPortEnvName(serviceKey);
|
|
47
|
+
const bindings = [];
|
|
48
|
+
const defaultInternalPort = preset === "postgres" ? 5432 : preset === "redis" ? 6379 : preset === "clickhouse" ? 8123 : config.port;
|
|
49
|
+
bindings.push(`\${${envName}:-${config.port}}:${defaultInternalPort}`);
|
|
50
|
+
if (config.secondaryPort !== undefined) {
|
|
51
|
+
const secondaryEnv = getPortEnvName(`${serviceKey}Secondary`);
|
|
52
|
+
const secondaryInternal = preset === "clickhouse" ? 9000 : config.secondaryPort;
|
|
53
|
+
bindings.push(`\${${secondaryEnv}:-${config.secondaryPort}}:${secondaryInternal}`);
|
|
54
|
+
}
|
|
55
|
+
return bindings;
|
|
56
|
+
}
|
|
57
|
+
function resolveHealthcheck(healthCheck, fallback, options) {
|
|
58
|
+
if (healthCheck === false)
|
|
59
|
+
return;
|
|
60
|
+
if (typeof healthCheck === "function")
|
|
61
|
+
return fallback;
|
|
62
|
+
if (!healthCheck)
|
|
63
|
+
return fallback;
|
|
64
|
+
switch (healthCheck) {
|
|
65
|
+
case "pg_isready":
|
|
66
|
+
return {
|
|
67
|
+
test: ["CMD-SHELL", `pg_isready -U ${options.user ?? "postgres"}`],
|
|
68
|
+
...DEFAULT_HEALTHCHECK_SETTINGS
|
|
69
|
+
};
|
|
70
|
+
case "redis-cli":
|
|
71
|
+
return {
|
|
72
|
+
test: ["CMD", "redis-cli", "ping"],
|
|
73
|
+
...DEFAULT_HEALTHCHECK_SETTINGS
|
|
74
|
+
};
|
|
75
|
+
case "http":
|
|
76
|
+
return {
|
|
77
|
+
test: [
|
|
78
|
+
"CMD-SHELL",
|
|
79
|
+
`wget -qO- http://127.0.0.1:${options.internalPort}/ping || exit 1`
|
|
80
|
+
],
|
|
81
|
+
...DEFAULT_HEALTHCHECK_SETTINGS
|
|
82
|
+
};
|
|
83
|
+
default:
|
|
84
|
+
return fallback;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/docker-compose/services/clickhouse.ts
|
|
89
|
+
var clickhouseDockerService = defineDockerService({
|
|
90
|
+
preset: "clickhouse",
|
|
91
|
+
defaults: {
|
|
92
|
+
port: 8123,
|
|
93
|
+
secondaryPort: 9000,
|
|
94
|
+
healthCheck: "http"
|
|
95
|
+
},
|
|
96
|
+
enhanceServiceConfig: (base, options) => ({
|
|
97
|
+
...base,
|
|
98
|
+
secondaryPort: options.secondaryPort ?? 9000
|
|
99
|
+
}),
|
|
100
|
+
build: ({ serviceKey, config }) => {
|
|
101
|
+
const user = config.user ?? "default";
|
|
102
|
+
const password = config.password ?? "clickhouse";
|
|
103
|
+
const database = config.database ?? "default";
|
|
104
|
+
const defaultHealthcheck = {
|
|
105
|
+
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8123/ping || exit 1"],
|
|
106
|
+
interval: "250ms",
|
|
107
|
+
timeout: "5s",
|
|
108
|
+
retries: 20
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
service: {
|
|
112
|
+
image: "clickhouse/clickhouse-server:24-alpine",
|
|
113
|
+
ports: getDefaultPortBindings(serviceKey, config, "clickhouse"),
|
|
114
|
+
volumes: [`${serviceKey}_data:/var/lib/clickhouse`],
|
|
115
|
+
environment: {
|
|
116
|
+
CLICKHOUSE_USER: user,
|
|
117
|
+
CLICKHOUSE_PASSWORD: password,
|
|
118
|
+
CLICKHOUSE_DB: database
|
|
119
|
+
},
|
|
120
|
+
ulimits: {
|
|
121
|
+
nofile: {
|
|
122
|
+
soft: 262144,
|
|
123
|
+
hard: 262144
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
healthcheck: resolveHealthcheck(config.healthCheck, defaultHealthcheck, {
|
|
127
|
+
internalPort: 8123,
|
|
128
|
+
user
|
|
129
|
+
})
|
|
130
|
+
},
|
|
131
|
+
volume: `${serviceKey}_data`
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// src/docker-compose/services/postgres.ts
|
|
137
|
+
var postgresDockerService = defineDockerService({
|
|
138
|
+
preset: "postgres",
|
|
139
|
+
defaults: {
|
|
140
|
+
port: 5432,
|
|
141
|
+
healthCheck: "pg_isready"
|
|
142
|
+
},
|
|
143
|
+
build: ({ serviceKey, config }) => {
|
|
144
|
+
const user = config.user ?? "postgres";
|
|
145
|
+
const password = config.password ?? "postgres";
|
|
146
|
+
const database = config.database ?? "postgres";
|
|
147
|
+
const defaultHealthcheck = {
|
|
148
|
+
test: ["CMD-SHELL", `pg_isready -U ${user}`],
|
|
149
|
+
interval: "250ms",
|
|
150
|
+
timeout: "5s",
|
|
151
|
+
retries: 20
|
|
152
|
+
};
|
|
153
|
+
return {
|
|
154
|
+
service: {
|
|
155
|
+
image: "pgvector/pgvector:pg16",
|
|
156
|
+
ports: getDefaultPortBindings(serviceKey, config, "postgres"),
|
|
157
|
+
volumes: [`${serviceKey}_data:/var/lib/postgresql/data`],
|
|
158
|
+
environment: {
|
|
159
|
+
POSTGRES_USER: user,
|
|
160
|
+
POSTGRES_PASSWORD: password,
|
|
161
|
+
POSTGRES_DB: database
|
|
162
|
+
},
|
|
163
|
+
healthcheck: resolveHealthcheck(config.healthCheck, defaultHealthcheck, {
|
|
164
|
+
internalPort: 5432,
|
|
165
|
+
user
|
|
166
|
+
})
|
|
167
|
+
},
|
|
168
|
+
volume: `${serviceKey}_data`
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// src/docker-compose/services/redis.ts
|
|
174
|
+
var redisDockerService = defineDockerService({
|
|
175
|
+
preset: "redis",
|
|
176
|
+
defaults: {
|
|
177
|
+
port: 6379,
|
|
178
|
+
healthCheck: "redis-cli"
|
|
179
|
+
},
|
|
180
|
+
build: ({ serviceKey, config }) => {
|
|
181
|
+
const defaultHealthcheck = {
|
|
182
|
+
test: ["CMD", "redis-cli", "ping"],
|
|
183
|
+
interval: "250ms",
|
|
184
|
+
timeout: "5s",
|
|
185
|
+
retries: 20
|
|
186
|
+
};
|
|
187
|
+
return {
|
|
188
|
+
service: {
|
|
189
|
+
image: "redis:7-alpine",
|
|
190
|
+
ports: getDefaultPortBindings(serviceKey, config, "redis"),
|
|
191
|
+
healthcheck: resolveHealthcheck(config.healthCheck, defaultHealthcheck, {
|
|
192
|
+
internalPort: 6379
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// src/docker-compose/services/index.ts
|
|
200
|
+
var PRESET_SERVICES = {
|
|
201
|
+
postgres: postgresDockerService,
|
|
202
|
+
redis: redisDockerService,
|
|
203
|
+
clickhouse: clickhouseDockerService
|
|
204
|
+
};
|
|
205
|
+
var service = {
|
|
206
|
+
postgres: postgresDockerService.toServiceConfig,
|
|
207
|
+
redis: redisDockerService.toServiceConfig,
|
|
208
|
+
clickhouse: clickhouseDockerService.toServiceConfig,
|
|
209
|
+
custom(options) {
|
|
210
|
+
return options;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
function inferDockerPreset(serviceKey) {
|
|
214
|
+
const normalized = serviceKey.toLowerCase();
|
|
215
|
+
if (Object.hasOwn(PRESET_SERVICES, normalized)) {
|
|
216
|
+
return normalized;
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
function buildPresetDockerService(preset, input) {
|
|
221
|
+
return PRESET_SERVICES[preset].build(input);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/docker-compose/model.ts
|
|
225
|
+
function isObject(value) {
|
|
226
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
227
|
+
}
|
|
228
|
+
function deepMergeNode(base, override) {
|
|
229
|
+
if (Array.isArray(base) || Array.isArray(override)) {
|
|
230
|
+
return override;
|
|
231
|
+
}
|
|
232
|
+
if (!isObject(base) || !isObject(override)) {
|
|
233
|
+
return override;
|
|
234
|
+
}
|
|
235
|
+
const merged = { ...base };
|
|
236
|
+
for (const key of Object.keys(override)) {
|
|
237
|
+
const baseValue = merged[key];
|
|
238
|
+
const overrideValue = override[key];
|
|
239
|
+
if (baseValue === undefined || overrideValue === undefined) {
|
|
240
|
+
merged[key] = overrideValue;
|
|
241
|
+
} else {
|
|
242
|
+
merged[key] = deepMergeNode(baseValue, overrideValue);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return merged;
|
|
246
|
+
}
|
|
247
|
+
function isPresetDefinition(value) {
|
|
248
|
+
return Boolean(value && typeof value === "object" && "kind" in value && value.kind === "preset");
|
|
249
|
+
}
|
|
250
|
+
function normalizeRawService(name, config, service2) {
|
|
251
|
+
const normalized = { ...service2 };
|
|
252
|
+
if (!normalized.ports || normalized.ports.length === 0) {
|
|
253
|
+
normalized.ports = getDefaultPortBindings(name, config);
|
|
254
|
+
}
|
|
255
|
+
if (config.healthCheck === false) {
|
|
256
|
+
delete normalized.healthcheck;
|
|
257
|
+
}
|
|
258
|
+
return normalized;
|
|
259
|
+
}
|
|
260
|
+
function normalizeServiceConfig(name, config) {
|
|
261
|
+
const serviceName = config.serviceName ?? name;
|
|
262
|
+
const rawDefinition = config.docker;
|
|
263
|
+
if (isPresetDefinition(rawDefinition)) {
|
|
264
|
+
return {
|
|
265
|
+
kind: "preset",
|
|
266
|
+
serviceName,
|
|
267
|
+
preset: rawDefinition.preset,
|
|
268
|
+
serviceOverride: rawDefinition.service
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
if (rawDefinition) {
|
|
272
|
+
const inferredPreset = inferDockerPreset(name);
|
|
273
|
+
if (inferredPreset) {
|
|
274
|
+
return {
|
|
275
|
+
kind: "preset",
|
|
276
|
+
serviceName,
|
|
277
|
+
preset: inferredPreset,
|
|
278
|
+
serviceOverride: rawDefinition
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
kind: "raw",
|
|
283
|
+
serviceName,
|
|
284
|
+
service: normalizeRawService(name, config, rawDefinition)
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const preset = inferDockerPreset(name);
|
|
288
|
+
if (!preset) {
|
|
289
|
+
throw new Error(`Service "${name}" has no docker preset and no docker definition. Add service.docker using helper or raw mode.`);
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
kind: "preset",
|
|
293
|
+
serviceName,
|
|
294
|
+
preset
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function resolveServiceDefinition(name, config) {
|
|
298
|
+
const normalized = normalizeServiceConfig(name, config);
|
|
299
|
+
if (normalized.kind === "raw") {
|
|
300
|
+
return {
|
|
301
|
+
serviceName: normalized.serviceName,
|
|
302
|
+
service: normalized.service
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const { service: service2, volume } = buildPresetDockerService(normalized.preset, {
|
|
306
|
+
serviceKey: name,
|
|
307
|
+
config
|
|
308
|
+
});
|
|
309
|
+
const mergedService = normalized.serviceOverride ? deepMergeNode(service2, normalized.serviceOverride) : service2;
|
|
310
|
+
return {
|
|
311
|
+
serviceName: normalized.serviceName,
|
|
312
|
+
service: mergedService,
|
|
313
|
+
volume
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function buildComposeModel(services, docker) {
|
|
317
|
+
const composeServices = {};
|
|
318
|
+
const composeVolumes = {};
|
|
319
|
+
for (const [name, serviceConfig] of Object.entries(services)) {
|
|
320
|
+
const { serviceName, service: service2, volume } = resolveServiceDefinition(name, serviceConfig);
|
|
321
|
+
composeServices[serviceName] = service2;
|
|
322
|
+
if (volume) {
|
|
323
|
+
composeVolumes[volume] = {};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
for (const [volumeName, volume] of Object.entries(docker?.volumes ?? {})) {
|
|
327
|
+
composeVolumes[volumeName] = volume;
|
|
328
|
+
}
|
|
329
|
+
const document = {
|
|
330
|
+
services: composeServices
|
|
331
|
+
};
|
|
332
|
+
if (Object.keys(composeVolumes).length > 0) {
|
|
333
|
+
document.volumes = composeVolumes;
|
|
334
|
+
}
|
|
335
|
+
return document;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/docker-compose/yaml.ts
|
|
339
|
+
function isObject2(value) {
|
|
340
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
341
|
+
}
|
|
342
|
+
function formatScalar(value) {
|
|
343
|
+
if (value === null)
|
|
344
|
+
return "null";
|
|
345
|
+
if (typeof value === "string") {
|
|
346
|
+
return JSON.stringify(value);
|
|
347
|
+
}
|
|
348
|
+
return String(value);
|
|
349
|
+
}
|
|
350
|
+
function formatKey(key) {
|
|
351
|
+
return /^[A-Za-z_][A-Za-z0-9_-]*$/.test(key) ? key : JSON.stringify(key);
|
|
352
|
+
}
|
|
353
|
+
function sortNode(node) {
|
|
354
|
+
if (Array.isArray(node)) {
|
|
355
|
+
return node.map(sortNode);
|
|
356
|
+
}
|
|
357
|
+
if (isObject2(node)) {
|
|
358
|
+
const sorted = {};
|
|
359
|
+
for (const key of Object.keys(node).sort()) {
|
|
360
|
+
const value = node[key];
|
|
361
|
+
if (value !== undefined) {
|
|
362
|
+
sorted[key] = sortNode(value);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return sorted;
|
|
366
|
+
}
|
|
367
|
+
return node;
|
|
368
|
+
}
|
|
369
|
+
function stringifyNode(node, indent = 0) {
|
|
370
|
+
const prefix = " ".repeat(indent);
|
|
371
|
+
if (typeof node === "string" || typeof node === "number" || typeof node === "boolean" || node === null) {
|
|
372
|
+
return `${prefix}${formatScalar(node)}`;
|
|
373
|
+
}
|
|
374
|
+
if (Array.isArray(node)) {
|
|
375
|
+
if (node.length === 0)
|
|
376
|
+
return `${prefix}[]`;
|
|
377
|
+
return node.map((item) => {
|
|
378
|
+
const isNested = typeof item === "object" && item !== null;
|
|
379
|
+
if (!isNested) {
|
|
380
|
+
return `${prefix}- ${formatScalar(item)}`;
|
|
381
|
+
}
|
|
382
|
+
return `${prefix}-
|
|
383
|
+
${stringifyNode(item, indent + 2)}`;
|
|
384
|
+
}).join(`
|
|
385
|
+
`);
|
|
386
|
+
}
|
|
387
|
+
const entries = Object.entries(node).filter(([, value]) => value !== undefined);
|
|
388
|
+
if (entries.length === 0)
|
|
389
|
+
return `${prefix}{}`;
|
|
390
|
+
return entries.map(([key, value]) => {
|
|
391
|
+
const formattedKey = formatKey(key);
|
|
392
|
+
const isNested = typeof value === "object" && value !== null;
|
|
393
|
+
if (!isNested) {
|
|
394
|
+
return `${prefix}${formattedKey}: ${formatScalar(value)}`;
|
|
395
|
+
}
|
|
396
|
+
return `${prefix}${formattedKey}:
|
|
397
|
+
${stringifyNode(value, indent + 2)}`;
|
|
398
|
+
}).join(`
|
|
399
|
+
`);
|
|
400
|
+
}
|
|
401
|
+
function composeToYaml(document) {
|
|
402
|
+
const sorted = sortNode(document);
|
|
403
|
+
return `${stringifyNode(sorted)}
|
|
404
|
+
`;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// src/docker-compose/generated-file.ts
|
|
408
|
+
var DEFAULT_GENERATED_COMPOSE_FILE = ".buncargo/docker-compose.generated.yml";
|
|
409
|
+
function getGeneratedComposePath(root, docker) {
|
|
410
|
+
const generatedFile = docker?.generatedFile ?? DEFAULT_GENERATED_COMPOSE_FILE;
|
|
411
|
+
const absolutePath = isAbsolute(generatedFile) ? generatedFile : resolve(root, generatedFile);
|
|
412
|
+
const relativePath = relative(root, absolutePath);
|
|
413
|
+
const composeFileArg = relativePath && !relativePath.startsWith("..") ? relativePath : absolutePath;
|
|
414
|
+
return { absolutePath, composeFileArg };
|
|
415
|
+
}
|
|
416
|
+
function writeGeneratedComposeFile(root, services, docker) {
|
|
417
|
+
const { absolutePath, composeFileArg } = getGeneratedComposePath(root, docker);
|
|
418
|
+
const writeStrategy = docker?.writeStrategy ?? "always";
|
|
419
|
+
const shouldWrite = writeStrategy === "always" || !existsSync(absolutePath);
|
|
420
|
+
if (shouldWrite) {
|
|
421
|
+
const composeModel = buildComposeModel(services, docker);
|
|
422
|
+
const yaml = composeToYaml(composeModel);
|
|
423
|
+
mkdirSync(dirname(absolutePath), { recursive: true });
|
|
424
|
+
writeFileSync(absolutePath, yaml, "utf-8");
|
|
425
|
+
}
|
|
426
|
+
return composeFileArg;
|
|
427
|
+
}
|
|
428
|
+
export { service, buildComposeModel, composeToYaml, DEFAULT_GENERATED_COMPOSE_FILE, getGeneratedComposePath, writeGeneratedComposeFile };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// src/prisma/prisma.ts
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
isContainerRunning,
|
|
6
|
+
startService,
|
|
7
|
+
waitForServiceByType,
|
|
8
|
+
} from "./index-tjbx2r2t.js";
|
|
9
|
+
|
|
10
|
+
function createPrismaRunner(env, config) {
|
|
11
|
+
const {
|
|
12
|
+
cwd = "packages/prisma",
|
|
13
|
+
service = "postgres",
|
|
14
|
+
urlEnvVar = "DATABASE_URL",
|
|
15
|
+
} = config;
|
|
16
|
+
const healthCheckTypes = {
|
|
17
|
+
postgres: "pg_isready",
|
|
18
|
+
redis: "redis-cli",
|
|
19
|
+
clickhouse: "http",
|
|
20
|
+
};
|
|
21
|
+
function getDatabaseUrl() {
|
|
22
|
+
const envVars = env.buildEnvVars();
|
|
23
|
+
const url = envVars[urlEnvVar];
|
|
24
|
+
if (!url) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Environment variable ${urlEnvVar} not found. Make sure your dev config defines it in envVars.`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
async function ensureDatabase() {
|
|
32
|
+
const alreadyRunning = await isContainerRunning(env.projectName, service);
|
|
33
|
+
if (alreadyRunning) {
|
|
34
|
+
console.log(`✓ ${service} already running`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
console.log(`\uD83D\uDC33 Starting ${service}...`);
|
|
38
|
+
const composeFile = env.ensureComposeFile();
|
|
39
|
+
const envVars = env.buildEnvVars();
|
|
40
|
+
startService(env.root, env.projectName, service, envVars, {
|
|
41
|
+
verbose: false,
|
|
42
|
+
composeFile,
|
|
43
|
+
});
|
|
44
|
+
const port = env.ports[service];
|
|
45
|
+
if (!port) {
|
|
46
|
+
throw new Error(`Service ${service} not found in dev environment ports`);
|
|
47
|
+
}
|
|
48
|
+
const healthCheckType = healthCheckTypes[service] ?? "tcp";
|
|
49
|
+
console.log(`⏳ Waiting for ${service} to be healthy...`);
|
|
50
|
+
await waitForServiceByType(service, healthCheckType, port, {
|
|
51
|
+
verbose: true,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function run(args) {
|
|
55
|
+
if (args.length === 0) {
|
|
56
|
+
console.log(`
|
|
57
|
+
Usage: bun prisma <command> [args...]
|
|
58
|
+
|
|
59
|
+
Examples:
|
|
60
|
+
bun prisma migrate dev # Create new migration
|
|
61
|
+
bun prisma migrate deploy # Apply migrations
|
|
62
|
+
bun prisma db push # Push schema changes
|
|
63
|
+
bun prisma studio # Open Prisma Studio
|
|
64
|
+
bun prisma migrate reset # Reset database
|
|
65
|
+
`);
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
const port = env.ports[service];
|
|
69
|
+
console.log(`
|
|
70
|
+
\uD83D\uDD27 Prisma CLI
|
|
71
|
+
Project: ${env.projectName}
|
|
72
|
+
Database: localhost:${port}
|
|
73
|
+
${env.portOffset > 0 ? `(port offset +${env.portOffset})` : ""}
|
|
74
|
+
`);
|
|
75
|
+
await ensureDatabase();
|
|
76
|
+
const envVars = env.buildEnvVars();
|
|
77
|
+
const workingDir = join(env.root, cwd);
|
|
78
|
+
const fullEnv = {
|
|
79
|
+
...process.env,
|
|
80
|
+
...envVars,
|
|
81
|
+
[urlEnvVar]: getDatabaseUrl(),
|
|
82
|
+
};
|
|
83
|
+
console.log(`\uD83D\uDD04 Running: prisma ${args.join(" ")}
|
|
84
|
+
`);
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
const proc = spawn("bunx", ["prisma", ...args], {
|
|
87
|
+
cwd: workingDir,
|
|
88
|
+
env: fullEnv,
|
|
89
|
+
stdio: "inherit",
|
|
90
|
+
});
|
|
91
|
+
proc.on("close", (code) => {
|
|
92
|
+
resolve(code ?? 0);
|
|
93
|
+
});
|
|
94
|
+
proc.on("error", () => {
|
|
95
|
+
resolve(1);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return { run, getDatabaseUrl, ensureDatabase };
|
|
100
|
+
}
|
|
101
|
+
export { createPrismaRunner };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDevEnvironment
|
|
3
|
+
} from "./index-qa8akv6y.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 };
|