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
package/config.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AppConfig,
|
|
3
|
-
DevConfig,
|
|
4
|
-
DevHooks,
|
|
5
|
-
DevOptions,
|
|
6
|
-
EnvVarsBuilder,
|
|
7
|
-
MigrationConfig,
|
|
8
|
-
PrismaConfig,
|
|
9
|
-
SeedConfig,
|
|
10
|
-
ServiceConfig,
|
|
11
|
-
} from "./types";
|
|
12
|
-
|
|
13
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
14
|
-
// Config Factory
|
|
15
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Define a dev environment configuration with full TypeScript inference.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const config = defineDevConfig({
|
|
23
|
-
* projectPrefix: 'myapp',
|
|
24
|
-
* services: {
|
|
25
|
-
* postgres: { port: 5432, healthCheck: 'pg_isready' },
|
|
26
|
-
* redis: { port: 6379 },
|
|
27
|
-
* },
|
|
28
|
-
* apps: {
|
|
29
|
-
* api: { port: 3000, devCommand: 'bun run dev', cwd: 'apps/backend' },
|
|
30
|
-
* web: { port: 5173, devCommand: 'bun run dev', cwd: 'apps/frontend' },
|
|
31
|
-
* },
|
|
32
|
-
* envVars: (ports, urls) => ({
|
|
33
|
-
* DATABASE_URL: urls.postgres,
|
|
34
|
-
* REDIS_URL: urls.redis,
|
|
35
|
-
* API_PORT: String(ports.api),
|
|
36
|
-
* }),
|
|
37
|
-
* })
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export function defineDevConfig<
|
|
41
|
-
TServices extends Record<string, ServiceConfig>,
|
|
42
|
-
TApps extends Record<string, AppConfig> = Record<string, never>,
|
|
43
|
-
>(config: {
|
|
44
|
-
/** Prefix for Docker project name (e.g., 'myapp' -> 'myapp-main') */
|
|
45
|
-
projectPrefix: string;
|
|
46
|
-
/** Docker Compose services to manage */
|
|
47
|
-
services: TServices;
|
|
48
|
-
/** Applications to start (optional) */
|
|
49
|
-
apps?: TApps;
|
|
50
|
-
/**
|
|
51
|
-
* Environment variables builder. Define all env vars here.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* envVars: (ports, urls, { localIp }) => ({
|
|
56
|
-
* DATABASE_URL: urls.postgres,
|
|
57
|
-
* BASE_URL: urls.api,
|
|
58
|
-
* VITE_PORT: ports.platform,
|
|
59
|
-
* EXPO_API_URL: `http://${localIp}:${ports.api}`
|
|
60
|
-
* })
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
envVars?: EnvVarsBuilder<TServices, TApps>;
|
|
64
|
-
/** Lifecycle hooks (optional) */
|
|
65
|
-
hooks?: DevHooks<TServices, TApps>;
|
|
66
|
-
/** Migrations to run after containers are ready (optional). Runs in parallel. */
|
|
67
|
-
migrations?: MigrationConfig[];
|
|
68
|
-
/** Seed configuration (optional). Runs after migrations, before servers. */
|
|
69
|
-
seed?: SeedConfig<TServices, TApps>;
|
|
70
|
-
/** Prisma configuration (optional). When set, dev.prisma is available. */
|
|
71
|
-
prisma?: PrismaConfig;
|
|
72
|
-
/** Additional options (optional) */
|
|
73
|
-
options?: DevOptions;
|
|
74
|
-
}): DevConfig<TServices, TApps> {
|
|
75
|
-
return config as DevConfig<TServices, TApps>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
79
|
-
// Config Validation
|
|
80
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Validate a dev config and return any errors.
|
|
84
|
-
*/
|
|
85
|
-
export function validateConfig<
|
|
86
|
-
TServices extends Record<string, ServiceConfig>,
|
|
87
|
-
TApps extends Record<string, AppConfig>,
|
|
88
|
-
>(config: DevConfig<TServices, TApps>): string[] {
|
|
89
|
-
const errors: string[] = [];
|
|
90
|
-
|
|
91
|
-
// Check project prefix
|
|
92
|
-
if (!config.projectPrefix) {
|
|
93
|
-
errors.push("projectPrefix is required");
|
|
94
|
-
} else if (!/^[a-z][a-z0-9-]*$/.test(config.projectPrefix)) {
|
|
95
|
-
errors.push(
|
|
96
|
-
"projectPrefix must start with a letter and contain only lowercase letters, numbers, and hyphens",
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Check services
|
|
101
|
-
if (!config.services || Object.keys(config.services).length === 0) {
|
|
102
|
-
errors.push("At least one service is required");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
for (const [name, service] of Object.entries(config.services ?? {})) {
|
|
106
|
-
if (!service.port || typeof service.port !== "number") {
|
|
107
|
-
errors.push(`Service "${name}" must have a valid port number`);
|
|
108
|
-
}
|
|
109
|
-
if (service.port < 1 || service.port > 65535) {
|
|
110
|
-
errors.push(`Service "${name}" port must be between 1 and 65535`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Check apps
|
|
115
|
-
for (const [name, app] of Object.entries(config.apps ?? {})) {
|
|
116
|
-
if (!app.port || typeof app.port !== "number") {
|
|
117
|
-
errors.push(`App "${name}" must have a valid port number`);
|
|
118
|
-
}
|
|
119
|
-
if (!app.devCommand) {
|
|
120
|
-
errors.push(`App "${name}" must have a devCommand`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Check migrations
|
|
125
|
-
for (const migration of config.migrations ?? []) {
|
|
126
|
-
if (!migration.name) {
|
|
127
|
-
errors.push("Migration must have a name");
|
|
128
|
-
}
|
|
129
|
-
if (!migration.command) {
|
|
130
|
-
errors.push(`Migration "${migration.name}" must have a command`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Check seed
|
|
135
|
-
if (config.seed && !config.seed.command) {
|
|
136
|
-
errors.push("Seed must have a command");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return errors;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Validate config and throw if invalid.
|
|
144
|
-
*/
|
|
145
|
-
export function assertValidConfig<
|
|
146
|
-
TServices extends Record<string, ServiceConfig>,
|
|
147
|
-
TApps extends Record<string, AppConfig>,
|
|
148
|
-
>(config: DevConfig<TServices, TApps>): void {
|
|
149
|
-
const errors = validateConfig(config);
|
|
150
|
-
if (errors.length > 0) {
|
|
151
|
-
throw new Error(`Invalid dev config:\n - ${errors.join("\n - ")}`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
156
|
-
// Config Helpers
|
|
157
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Merge two configs, with the second taking precedence.
|
|
161
|
-
*/
|
|
162
|
-
export function mergeConfigs<
|
|
163
|
-
TServices extends Record<string, ServiceConfig>,
|
|
164
|
-
TApps extends Record<string, AppConfig>,
|
|
165
|
-
>(
|
|
166
|
-
base: DevConfig<TServices, TApps>,
|
|
167
|
-
overrides: Partial<DevConfig<TServices, TApps>>,
|
|
168
|
-
): DevConfig<TServices, TApps> {
|
|
169
|
-
return {
|
|
170
|
-
...base,
|
|
171
|
-
...overrides,
|
|
172
|
-
services: { ...base.services, ...overrides.services } as TServices,
|
|
173
|
-
apps: { ...base.apps, ...overrides.apps } as TApps,
|
|
174
|
-
hooks: { ...base.hooks, ...overrides.hooks },
|
|
175
|
-
migrations: overrides.migrations ?? base.migrations,
|
|
176
|
-
seed: overrides.seed ?? base.seed,
|
|
177
|
-
options: { ...base.options, ...overrides.options },
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Create a partial config that can be merged later.
|
|
183
|
-
*/
|
|
184
|
-
export function definePartialConfig<
|
|
185
|
-
TServices extends Record<string, ServiceConfig> = Record<
|
|
186
|
-
string,
|
|
187
|
-
ServiceConfig
|
|
188
|
-
>,
|
|
189
|
-
TApps extends Record<string, AppConfig> = Record<string, AppConfig>,
|
|
190
|
-
>(
|
|
191
|
-
config: Partial<DevConfig<TServices, TApps>>,
|
|
192
|
-
): Partial<DevConfig<TServices, TApps>> {
|
|
193
|
-
return config;
|
|
194
|
-
}
|
package/loader.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
import { createDevEnvironment } from "./environment";
|
|
4
|
-
import type { AppConfig, DevEnvironment, ServiceConfig } from "./types";
|
|
5
|
-
|
|
6
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
7
|
-
// Config Loader
|
|
8
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
9
|
-
|
|
10
|
-
export const CONFIG_FILES = [
|
|
11
|
-
"dev.config.ts",
|
|
12
|
-
"dev.config.js",
|
|
13
|
-
"dev-tools.config.ts",
|
|
14
|
-
"dev-tools.config.js",
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Find a config file by traversing up from the starting directory.
|
|
19
|
-
* Returns the full path to the config file, or null if not found.
|
|
20
|
-
*/
|
|
21
|
-
export function findConfigFile(startDir: string): string | null {
|
|
22
|
-
let currentDir = startDir;
|
|
23
|
-
|
|
24
|
-
while (true) {
|
|
25
|
-
// Check for any config file in the current directory
|
|
26
|
-
for (const file of CONFIG_FILES) {
|
|
27
|
-
const configPath = join(currentDir, file);
|
|
28
|
-
if (existsSync(configPath)) {
|
|
29
|
-
return configPath;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Move to parent directory
|
|
34
|
-
const parentDir = dirname(currentDir);
|
|
35
|
-
|
|
36
|
-
// Stop if we've reached the root (parent equals current)
|
|
37
|
-
if (parentDir === currentDir) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
currentDir = parentDir;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let cachedEnv: DevEnvironment<
|
|
46
|
-
Record<string, ServiceConfig>,
|
|
47
|
-
Record<string, AppConfig>
|
|
48
|
-
> | null = null;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Load the dev environment from the config file.
|
|
52
|
-
* Caches the result for subsequent calls.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* import { loadDevEnv } from 'buncargo'
|
|
57
|
-
*
|
|
58
|
-
* const env = await loadDevEnv()
|
|
59
|
-
* console.log(env.ports.postgres) // 5432 (or offset port)
|
|
60
|
-
* console.log(env.urls.api) // http://localhost:3000
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export async function loadDevEnv(options?: {
|
|
64
|
-
/** Directory to search for config file. Defaults to process.cwd() */
|
|
65
|
-
cwd?: string;
|
|
66
|
-
/** Skip cache and reload config */
|
|
67
|
-
reload?: boolean;
|
|
68
|
-
}): Promise<
|
|
69
|
-
DevEnvironment<Record<string, ServiceConfig>, Record<string, AppConfig>>
|
|
70
|
-
> {
|
|
71
|
-
if (cachedEnv && !options?.reload) {
|
|
72
|
-
return cachedEnv;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const cwd = options?.cwd ?? process.cwd();
|
|
76
|
-
const configPath = findConfigFile(cwd);
|
|
77
|
-
|
|
78
|
-
if (configPath) {
|
|
79
|
-
const mod = await import(configPath);
|
|
80
|
-
const config = mod.default;
|
|
81
|
-
|
|
82
|
-
if (!config?.projectPrefix || !config?.services) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
`Invalid config in "${configPath}". Use defineDevConfig() and export as default.`,
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
cachedEnv = createDevEnvironment(config);
|
|
89
|
-
return cachedEnv;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
throw new Error(
|
|
93
|
-
`No config file found. Create dev.config.ts with: export default defineDevConfig({ ... })`,
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Get the cached dev environment synchronously.
|
|
99
|
-
* Throws if loadDevEnv() hasn't been called yet.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* // First load async
|
|
104
|
-
* await loadDevEnv()
|
|
105
|
-
*
|
|
106
|
-
* // Then use sync getter anywhere
|
|
107
|
-
* import { getDevEnv } from 'buncargo'
|
|
108
|
-
* const env = getDevEnv()
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
export function getDevEnv(): DevEnvironment<
|
|
112
|
-
Record<string, ServiceConfig>,
|
|
113
|
-
Record<string, AppConfig>
|
|
114
|
-
> {
|
|
115
|
-
if (!cachedEnv) {
|
|
116
|
-
throw new Error("Dev environment not loaded. Call loadDevEnv() first.");
|
|
117
|
-
}
|
|
118
|
-
return cachedEnv;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Clear the cached environment.
|
|
123
|
-
*/
|
|
124
|
-
export function clearDevEnvCache(): void {
|
|
125
|
-
cachedEnv = null;
|
|
126
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|