@geekmidas/cli 0.18.0 → 0.20.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/{bundler-C74EKlNa.cjs → bundler-CyHg1v_T.cjs} +3 -3
- package/dist/{bundler-C74EKlNa.cjs.map → bundler-CyHg1v_T.cjs.map} +1 -1
- package/dist/{bundler-B6z6HEeh.mjs → bundler-DQIuE3Kn.mjs} +3 -3
- package/dist/{bundler-B6z6HEeh.mjs.map → bundler-DQIuE3Kn.mjs.map} +1 -1
- package/dist/{config-DYULeEv8.mjs → config-BaYqrF3n.mjs} +48 -10
- package/dist/config-BaYqrF3n.mjs.map +1 -0
- package/dist/{config-AmInkU7k.cjs → config-CxrLu8ia.cjs} +53 -9
- package/dist/config-CxrLu8ia.cjs.map +1 -0
- package/dist/config.cjs +4 -1
- package/dist/config.d.cts +27 -2
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +27 -2
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +3 -2
- package/dist/dokploy-api-B0w17y4_.mjs +3 -0
- package/dist/{dokploy-api-CaETb2L6.mjs → dokploy-api-B9qR2Yn1.mjs} +1 -1
- package/dist/{dokploy-api-CaETb2L6.mjs.map → dokploy-api-B9qR2Yn1.mjs.map} +1 -1
- package/dist/dokploy-api-BnGeUqN4.cjs +3 -0
- package/dist/{dokploy-api-C7F9VykY.cjs → dokploy-api-C5czOZoc.cjs} +1 -1
- package/dist/{dokploy-api-C7F9VykY.cjs.map → dokploy-api-C5czOZoc.cjs.map} +1 -1
- package/dist/{encryption-D7Efcdi9.cjs → encryption-BAz0xQ1Q.cjs} +1 -1
- package/dist/{encryption-D7Efcdi9.cjs.map → encryption-BAz0xQ1Q.cjs.map} +1 -1
- package/dist/{encryption-h4Nb6W-M.mjs → encryption-JtMsiGNp.mjs} +2 -2
- package/dist/{encryption-h4Nb6W-M.mjs.map → encryption-JtMsiGNp.mjs.map} +1 -1
- package/dist/index-CWN-bgrO.d.mts +495 -0
- package/dist/index-CWN-bgrO.d.mts.map +1 -0
- package/dist/index-DEWYvYvg.d.cts +495 -0
- package/dist/index-DEWYvYvg.d.cts.map +1 -0
- package/dist/index.cjs +2640 -564
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2635 -564
- package/dist/index.mjs.map +1 -1
- package/dist/{openapi-CZVcfxk-.mjs → openapi-CgqR6Jkw.mjs} +3 -3
- package/dist/{openapi-CZVcfxk-.mjs.map → openapi-CgqR6Jkw.mjs.map} +1 -1
- package/dist/{openapi-C89hhkZC.cjs → openapi-DfpxS0xv.cjs} +8 -2
- package/dist/{openapi-C89hhkZC.cjs.map → openapi-DfpxS0xv.cjs.map} +1 -1
- package/dist/{openapi-react-query-CM2_qlW9.mjs → openapi-react-query-5rSortLH.mjs} +1 -1
- package/dist/{openapi-react-query-CM2_qlW9.mjs.map → openapi-react-query-5rSortLH.mjs.map} +1 -1
- package/dist/{openapi-react-query-iKjfLzff.cjs → openapi-react-query-DvNpdDpM.cjs} +1 -1
- package/dist/{openapi-react-query-iKjfLzff.cjs.map → openapi-react-query-DvNpdDpM.cjs.map} +1 -1
- package/dist/openapi-react-query.cjs +1 -1
- package/dist/openapi-react-query.mjs +1 -1
- package/dist/openapi.cjs +3 -2
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.mjs +3 -2
- package/dist/{storage-Bn3K9Ccu.cjs → storage-BPRgh3DU.cjs} +136 -5
- package/dist/storage-BPRgh3DU.cjs.map +1 -0
- package/dist/{storage-nkGIjeXt.mjs → storage-DNj_I11J.mjs} +1 -1
- package/dist/storage-Dhst7BhI.mjs +272 -0
- package/dist/storage-Dhst7BhI.mjs.map +1 -0
- package/dist/{storage-UfyTn7Zm.cjs → storage-fOR8dMu5.cjs} +1 -1
- package/dist/{types-iFk5ms7y.d.mts → types-K2uQJ-FO.d.mts} +2 -2
- package/dist/{types-BgaMXsUa.d.cts.map → types-K2uQJ-FO.d.mts.map} +1 -1
- package/dist/{types-BgaMXsUa.d.cts → types-l53qUmGt.d.cts} +2 -2
- package/dist/{types-iFk5ms7y.d.mts.map → types-l53qUmGt.d.cts.map} +1 -1
- package/dist/workspace/index.cjs +19 -0
- package/dist/workspace/index.d.cts +3 -0
- package/dist/workspace/index.d.mts +3 -0
- package/dist/workspace/index.mjs +3 -0
- package/dist/workspace-CPLEZDZf.mjs +3788 -0
- package/dist/workspace-CPLEZDZf.mjs.map +1 -0
- package/dist/workspace-iWgBlX6h.cjs +3885 -0
- package/dist/workspace-iWgBlX6h.cjs.map +1 -0
- package/package.json +9 -4
- package/src/build/__tests__/workspace-build.spec.ts +215 -0
- package/src/build/index.ts +189 -1
- package/src/config.ts +71 -14
- package/src/deploy/__tests__/docker.spec.ts +1 -1
- package/src/deploy/__tests__/index.spec.ts +305 -1
- package/src/deploy/index.ts +426 -4
- package/src/deploy/types.ts +32 -0
- package/src/dev/__tests__/index.spec.ts +572 -1
- package/src/dev/index.ts +582 -2
- package/src/docker/__tests__/compose.spec.ts +425 -0
- package/src/docker/__tests__/templates.spec.ts +145 -0
- package/src/docker/compose.ts +248 -0
- package/src/docker/index.ts +159 -3
- package/src/docker/templates.ts +219 -4
- package/src/index.ts +24 -0
- package/src/init/__tests__/generators.spec.ts +17 -24
- package/src/init/__tests__/init.spec.ts +157 -5
- package/src/init/generators/auth.ts +220 -0
- package/src/init/generators/config.ts +61 -4
- package/src/init/generators/docker.ts +115 -8
- package/src/init/generators/env.ts +7 -127
- package/src/init/generators/index.ts +1 -0
- package/src/init/generators/models.ts +3 -1
- package/src/init/generators/monorepo.ts +154 -10
- package/src/init/generators/package.ts +5 -3
- package/src/init/generators/web.ts +213 -0
- package/src/init/index.ts +290 -58
- package/src/init/templates/api.ts +38 -29
- package/src/init/templates/index.ts +132 -4
- package/src/init/templates/minimal.ts +33 -35
- package/src/init/templates/serverless.ts +16 -19
- package/src/init/templates/worker.ts +50 -25
- package/src/init/versions.ts +47 -0
- package/src/secrets/keystore.ts +144 -0
- package/src/secrets/storage.ts +109 -6
- package/src/test/index.ts +97 -0
- package/src/workspace/__tests__/client-generator.spec.ts +357 -0
- package/src/workspace/__tests__/index.spec.ts +543 -0
- package/src/workspace/__tests__/schema.spec.ts +519 -0
- package/src/workspace/__tests__/type-inference.spec.ts +251 -0
- package/src/workspace/client-generator.ts +307 -0
- package/src/workspace/index.ts +372 -0
- package/src/workspace/schema.ts +368 -0
- package/src/workspace/types.ts +336 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/tsdown.config.ts +1 -0
- package/dist/config-AmInkU7k.cjs.map +0 -1
- package/dist/config-DYULeEv8.mjs.map +0 -1
- package/dist/dokploy-api-B7KxOQr3.cjs +0 -3
- package/dist/dokploy-api-DHvfmWbi.mjs +0 -3
- package/dist/storage-BaOP55oq.mjs +0 -147
- package/dist/storage-BaOP55oq.mjs.map +0 -1
- package/dist/storage-Bn3K9Ccu.cjs.map +0 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import type { GkmConfig } from '../types.js';
|
|
3
|
+
import {
|
|
4
|
+
formatValidationErrors,
|
|
5
|
+
safeValidateWorkspaceConfig,
|
|
6
|
+
} from './schema.js';
|
|
7
|
+
import type {
|
|
8
|
+
AppConfig,
|
|
9
|
+
AppsRecord,
|
|
10
|
+
DeployTarget,
|
|
11
|
+
InferredWorkspaceConfig,
|
|
12
|
+
LoadedConfig,
|
|
13
|
+
NormalizedAppConfig,
|
|
14
|
+
NormalizedWorkspace,
|
|
15
|
+
WorkspaceConfig,
|
|
16
|
+
WorkspaceInput,
|
|
17
|
+
} from './types.js';
|
|
18
|
+
import { isWorkspaceConfig } from './types.js';
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
formatValidationErrors,
|
|
22
|
+
getDeployTargetError,
|
|
23
|
+
isDeployTargetSupported,
|
|
24
|
+
isPhase2DeployTarget,
|
|
25
|
+
PHASE_2_DEPLOY_TARGETS,
|
|
26
|
+
SUPPORTED_DEPLOY_TARGETS,
|
|
27
|
+
safeValidateWorkspaceConfig,
|
|
28
|
+
validateWorkspaceConfig,
|
|
29
|
+
WorkspaceConfigSchema,
|
|
30
|
+
} from './schema.js';
|
|
31
|
+
// Re-export types
|
|
32
|
+
export type {
|
|
33
|
+
AppConfig,
|
|
34
|
+
AppConfigInput,
|
|
35
|
+
AppInput,
|
|
36
|
+
AppsRecord,
|
|
37
|
+
ClientConfig,
|
|
38
|
+
ConstrainedApps,
|
|
39
|
+
DeployConfig,
|
|
40
|
+
DeployTarget,
|
|
41
|
+
DokployWorkspaceConfig,
|
|
42
|
+
InferAppNames,
|
|
43
|
+
InferredWorkspaceConfig,
|
|
44
|
+
LoadedConfig,
|
|
45
|
+
MailServiceConfig,
|
|
46
|
+
ModelsConfig,
|
|
47
|
+
NormalizedAppConfig,
|
|
48
|
+
NormalizedWorkspace,
|
|
49
|
+
SecretsConfig,
|
|
50
|
+
ServiceImageConfig,
|
|
51
|
+
ServicesConfig,
|
|
52
|
+
SharedConfig,
|
|
53
|
+
WorkspaceConfig,
|
|
54
|
+
WorkspaceInput,
|
|
55
|
+
} from './types.js';
|
|
56
|
+
export { isWorkspaceConfig } from './types.js';
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Validate that all dependencies reference existing apps.
|
|
60
|
+
* Returns the config if valid, throws otherwise.
|
|
61
|
+
*/
|
|
62
|
+
function validateDependencies<TApps extends AppsRecord>(apps: TApps): void {
|
|
63
|
+
const appNames = new Set(Object.keys(apps));
|
|
64
|
+
|
|
65
|
+
for (const [appName, app] of Object.entries(apps)) {
|
|
66
|
+
for (const dep of app.dependencies ?? []) {
|
|
67
|
+
if (!appNames.has(dep)) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Invalid dependency: App "${appName}" depends on "${dep}" which does not exist. ` +
|
|
70
|
+
`Valid apps are: ${[...appNames].join(', ')}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (dep === appName) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Invalid dependency: App "${appName}" cannot depend on itself.`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Define workspace configuration with full TypeScript support and type inference.
|
|
84
|
+
*
|
|
85
|
+
* Uses `const` type parameter to infer literal app names, providing:
|
|
86
|
+
* - Autocomplete for app names in dependencies
|
|
87
|
+
* - Type errors for invalid dependency references
|
|
88
|
+
* - Full type inference for the returned config
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* // gkm.config.ts
|
|
93
|
+
* import { defineWorkspace } from '@geekmidas/cli';
|
|
94
|
+
*
|
|
95
|
+
* export default defineWorkspace({
|
|
96
|
+
* name: 'my-saas',
|
|
97
|
+
* apps: {
|
|
98
|
+
* api: {
|
|
99
|
+
* type: 'backend',
|
|
100
|
+
* path: 'apps/api',
|
|
101
|
+
* port: 3000,
|
|
102
|
+
* routes: './src/endpoints/**\/*.ts',
|
|
103
|
+
* envParser: './src/config/env',
|
|
104
|
+
* logger: './src/logger',
|
|
105
|
+
* },
|
|
106
|
+
* web: {
|
|
107
|
+
* type: 'frontend',
|
|
108
|
+
* framework: 'nextjs',
|
|
109
|
+
* path: 'apps/web',
|
|
110
|
+
* port: 3001,
|
|
111
|
+
* dependencies: ['api'], // <- autocomplete shows 'api' | 'web'
|
|
112
|
+
* },
|
|
113
|
+
* },
|
|
114
|
+
* services: {
|
|
115
|
+
* db: true,
|
|
116
|
+
* cache: true,
|
|
117
|
+
* },
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // config.apps.api <- full type inference
|
|
121
|
+
* // config.apps.foo <- TypeScript error
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export function defineWorkspace<const TApps extends AppsRecord>(
|
|
125
|
+
config: WorkspaceInput<TApps>,
|
|
126
|
+
): InferredWorkspaceConfig<TApps> {
|
|
127
|
+
// Validate dependencies at runtime
|
|
128
|
+
validateDependencies(config.apps as unknown as TApps);
|
|
129
|
+
|
|
130
|
+
// Validate with Zod schema
|
|
131
|
+
const result = safeValidateWorkspaceConfig(config);
|
|
132
|
+
if (!result.success && result.error) {
|
|
133
|
+
throw new Error(formatValidationErrors(result.error));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return config as unknown as InferredWorkspaceConfig<TApps>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Get the package name from package.json in the given directory.
|
|
141
|
+
*/
|
|
142
|
+
function getPackageName(cwd: string): string | undefined {
|
|
143
|
+
try {
|
|
144
|
+
// Dynamic import would be async, so we use require for sync operation
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
146
|
+
const pkg = require(`${cwd}/package.json`);
|
|
147
|
+
return pkg.name?.replace(/^@[^/]+\//, ''); // Remove scope
|
|
148
|
+
} catch {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Normalize a workspace configuration with resolved defaults.
|
|
155
|
+
*/
|
|
156
|
+
export function normalizeWorkspace(
|
|
157
|
+
config: WorkspaceConfig,
|
|
158
|
+
cwd: string,
|
|
159
|
+
): NormalizedWorkspace {
|
|
160
|
+
const name = config.name ?? getPackageName(cwd) ?? basename(cwd);
|
|
161
|
+
const defaultTarget = config.deploy?.default ?? 'dokploy';
|
|
162
|
+
|
|
163
|
+
const normalizedApps: Record<string, NormalizedAppConfig> = {};
|
|
164
|
+
|
|
165
|
+
for (const [appName, app] of Object.entries(config.apps)) {
|
|
166
|
+
normalizedApps[appName] = normalizeAppConfig(app, defaultTarget);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
name,
|
|
171
|
+
root: cwd,
|
|
172
|
+
apps: normalizedApps,
|
|
173
|
+
services: config.services ?? {},
|
|
174
|
+
deploy: config.deploy ?? { default: 'dokploy' },
|
|
175
|
+
shared: config.shared ?? { packages: ['packages/*'] },
|
|
176
|
+
secrets: config.secrets ?? {},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Normalize an app configuration with resolved defaults.
|
|
182
|
+
* @param app - App configuration
|
|
183
|
+
* @param defaultTarget - Default deploy target from workspace config
|
|
184
|
+
*/
|
|
185
|
+
function normalizeAppConfig(
|
|
186
|
+
app: AppConfig,
|
|
187
|
+
defaultTarget: DeployTarget,
|
|
188
|
+
): NormalizedAppConfig {
|
|
189
|
+
return {
|
|
190
|
+
...app,
|
|
191
|
+
type: app.type ?? 'backend',
|
|
192
|
+
port: app.port,
|
|
193
|
+
path: app.path,
|
|
194
|
+
dependencies: app.dependencies ?? [],
|
|
195
|
+
resolvedDeployTarget: app.deploy ?? defaultTarget,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Wrap a single-app GkmConfig as a workspace.
|
|
201
|
+
* This allows existing single-app configs to work seamlessly.
|
|
202
|
+
*/
|
|
203
|
+
export function wrapSingleAppAsWorkspace(
|
|
204
|
+
config: GkmConfig,
|
|
205
|
+
cwd: string,
|
|
206
|
+
): NormalizedWorkspace {
|
|
207
|
+
const name = getPackageName(cwd) ?? basename(cwd);
|
|
208
|
+
|
|
209
|
+
// Extract docker compose services if configured
|
|
210
|
+
const services = config.docker?.compose?.services;
|
|
211
|
+
const normalizedServices: NormalizedWorkspace['services'] = {};
|
|
212
|
+
|
|
213
|
+
if (services) {
|
|
214
|
+
if (Array.isArray(services)) {
|
|
215
|
+
// Legacy array format
|
|
216
|
+
for (const svc of services) {
|
|
217
|
+
if (svc === 'postgres') normalizedServices.db = true;
|
|
218
|
+
if (svc === 'redis') normalizedServices.cache = true;
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
// Object format
|
|
222
|
+
if (services.postgres) normalizedServices.db = services.postgres;
|
|
223
|
+
if (services.redis) normalizedServices.cache = services.redis;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const apiApp: NormalizedAppConfig = {
|
|
228
|
+
type: 'backend',
|
|
229
|
+
path: '.',
|
|
230
|
+
port: 3000,
|
|
231
|
+
dependencies: [],
|
|
232
|
+
resolvedDeployTarget: 'dokploy',
|
|
233
|
+
routes: config.routes,
|
|
234
|
+
functions: config.functions,
|
|
235
|
+
crons: config.crons,
|
|
236
|
+
subscribers: config.subscribers,
|
|
237
|
+
envParser: config.envParser,
|
|
238
|
+
logger: config.logger,
|
|
239
|
+
providers: config.providers,
|
|
240
|
+
hooks: config.hooks,
|
|
241
|
+
telescope: config.telescope,
|
|
242
|
+
studio: config.studio,
|
|
243
|
+
openapi: config.openapi,
|
|
244
|
+
runtime: config.runtime,
|
|
245
|
+
env: config.env,
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
name,
|
|
250
|
+
root: cwd,
|
|
251
|
+
apps: { api: apiApp },
|
|
252
|
+
services: normalizedServices,
|
|
253
|
+
deploy: { default: 'dokploy' },
|
|
254
|
+
shared: { packages: [] },
|
|
255
|
+
secrets: {},
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Process a loaded configuration (either single-app or workspace).
|
|
261
|
+
* Returns a normalized workspace in both cases.
|
|
262
|
+
*/
|
|
263
|
+
export function processConfig(
|
|
264
|
+
config: GkmConfig | WorkspaceConfig,
|
|
265
|
+
cwd: string,
|
|
266
|
+
): LoadedConfig {
|
|
267
|
+
if (isWorkspaceConfig(config)) {
|
|
268
|
+
// Validate workspace config
|
|
269
|
+
const result = safeValidateWorkspaceConfig(config);
|
|
270
|
+
if (!result.success && result.error) {
|
|
271
|
+
throw new Error(formatValidationErrors(result.error));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
type: 'workspace',
|
|
276
|
+
raw: config,
|
|
277
|
+
workspace: normalizeWorkspace(config, cwd),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Single-app config - wrap as workspace
|
|
282
|
+
return {
|
|
283
|
+
type: 'single',
|
|
284
|
+
raw: config,
|
|
285
|
+
workspace: wrapSingleAppAsWorkspace(config, cwd),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Get the GkmConfig for a specific app in a workspace.
|
|
291
|
+
* Useful for running existing single-app commands on a specific app.
|
|
292
|
+
*/
|
|
293
|
+
export function getAppGkmConfig(
|
|
294
|
+
workspace: NormalizedWorkspace,
|
|
295
|
+
appName: string,
|
|
296
|
+
): GkmConfig | undefined {
|
|
297
|
+
const app = workspace.apps[appName];
|
|
298
|
+
if (!app || app.type !== 'backend') {
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
routes: app.routes ?? '',
|
|
304
|
+
functions: app.functions,
|
|
305
|
+
crons: app.crons,
|
|
306
|
+
subscribers: app.subscribers,
|
|
307
|
+
envParser: app.envParser ?? '',
|
|
308
|
+
logger: app.logger ?? '',
|
|
309
|
+
providers: app.providers,
|
|
310
|
+
hooks: app.hooks,
|
|
311
|
+
telescope: app.telescope,
|
|
312
|
+
studio: app.studio,
|
|
313
|
+
openapi: app.openapi,
|
|
314
|
+
runtime: app.runtime,
|
|
315
|
+
env: app.env,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Get topologically sorted app names based on dependencies.
|
|
321
|
+
* Apps with no dependencies come first, then apps that depend on them.
|
|
322
|
+
*/
|
|
323
|
+
export function getAppBuildOrder(workspace: NormalizedWorkspace): string[] {
|
|
324
|
+
const appNames = Object.keys(workspace.apps);
|
|
325
|
+
const visited = new Set<string>();
|
|
326
|
+
const result: string[] = [];
|
|
327
|
+
|
|
328
|
+
function visit(name: string) {
|
|
329
|
+
if (visited.has(name)) return;
|
|
330
|
+
visited.add(name);
|
|
331
|
+
|
|
332
|
+
const app = workspace.apps[name];
|
|
333
|
+
if (app) {
|
|
334
|
+
for (const dep of app.dependencies) {
|
|
335
|
+
visit(dep);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
result.push(name);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
for (const name of appNames) {
|
|
343
|
+
visit(name);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return result;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Generate environment variables for app dependencies.
|
|
351
|
+
* Each dependency gets a {DEP_NAME}_URL variable.
|
|
352
|
+
*/
|
|
353
|
+
export function getDependencyEnvVars(
|
|
354
|
+
workspace: NormalizedWorkspace,
|
|
355
|
+
appName: string,
|
|
356
|
+
urlPrefix = 'http://localhost',
|
|
357
|
+
): Record<string, string> {
|
|
358
|
+
const app = workspace.apps[appName];
|
|
359
|
+
if (!app) return {};
|
|
360
|
+
|
|
361
|
+
const env: Record<string, string> = {};
|
|
362
|
+
|
|
363
|
+
for (const depName of app.dependencies) {
|
|
364
|
+
const dep = workspace.apps[depName];
|
|
365
|
+
if (dep) {
|
|
366
|
+
const envKey = `${depName.toUpperCase()}_URL`;
|
|
367
|
+
env[envKey] = `${urlPrefix}:${dep.port}`;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return env;
|
|
372
|
+
}
|