@topogram/cli 0.3.57 → 0.3.58

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topogram/cli",
3
- "version": "0.3.57",
3
+ "version": "0.3.58",
4
4
  "description": "Topogram CLI for checking Topogram workspaces and generating app bundles.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -370,16 +370,26 @@ function componentScriptOptions() {
370
370
  };
371
371
  }
372
372
 
373
+ function runtimePortExpression(plan, runtimes, component, sharedEnvName) {
374
+ const runtimeEnvName = `${component.id.toUpperCase()}_PORT`;
375
+ const primaryRuntime = runtimes[0];
376
+ const fallback = primaryRuntime?.id === component.id
377
+ ? `\${${sharedEnvName}:-${component.port}}`
378
+ : `${component.port}`;
379
+ return `\${${runtimeEnvName}:-${fallback}}`;
380
+ }
381
+
373
382
  function renderEnvironmentServerDevScript(plan, component = plan.runtimes.apis[0], options = {}) {
374
383
  if (!component) {
375
384
  return renderEnvAwareShellScript(['echo "No API runtimes are configured."']);
376
385
  }
377
386
  const guardPortsScript = options.componentScript ? '"$ROOT_DIR/scripts/guard-ports.mjs"' : '"$SCRIPT_DIR/guard-ports.mjs"';
387
+ const serverPortExpression = runtimePortExpression(plan, plan.runtimes.apis, component, "SERVER_PORT");
378
388
  return renderEnvAwareShellScript([
379
389
  `node ${guardPortsScript} api`,
380
390
  "",
381
391
  ...apiDatabaseExportLines(component),
382
- `export PORT="\${${component.id.toUpperCase()}_PORT:-\${SERVER_PORT:-${component.port}}}"`,
392
+ `export PORT="${serverPortExpression}"`,
383
393
  `export TOPOGRAM_CORS_ORIGINS="\${TOPOGRAM_CORS_ORIGINS:-http://localhost:\${WEB_PORT:-${plan.ports.web}},http://127.0.0.1:\${WEB_PORT:-${plan.ports.web}}}"`,
384
394
  "",
385
395
  `cd "$ROOT_DIR/${component.dir}"`,
@@ -395,15 +405,16 @@ function renderEnvironmentWebDevScript(plan, component = plan.runtimes.webs[0],
395
405
  }
396
406
  const apiRuntime = plan.runtimes.apis.find((entry) => entry.id === component.uses_api) || plan.runtimes.apis[0];
397
407
  const guardPortsScript = options.componentScript ? '"$ROOT_DIR/scripts/guard-ports.mjs"' : '"$SCRIPT_DIR/guard-ports.mjs"';
408
+ const webPortExpression = runtimePortExpression(plan, plan.runtimes.webs, component, "WEB_PORT");
398
409
  return renderEnvAwareShellScript([
399
410
  `node ${guardPortsScript} web`,
400
411
  "",
401
412
  ...(apiRuntime ? [`export PUBLIC_TOPOGRAM_API_BASE_URL="\${PUBLIC_TOPOGRAM_API_BASE_URL:-http://localhost:\${${apiRuntime.id.toUpperCase()}_PORT:-\${SERVER_PORT:-${apiRuntime.port}}}}"`] : []),
402
- `export TOPOGRAM_CORS_ORIGINS="\${TOPOGRAM_CORS_ORIGINS:-http://localhost:\${${component.id.toUpperCase()}_PORT:-\${WEB_PORT:-${component.port}}},http://127.0.0.1:\${${component.id.toUpperCase()}_PORT:-\${WEB_PORT:-${component.port}}}}"`,
413
+ `export TOPOGRAM_CORS_ORIGINS="\${TOPOGRAM_CORS_ORIGINS:-http://localhost:${webPortExpression},http://127.0.0.1:${webPortExpression}}"`,
403
414
  "",
404
415
  `cd "$ROOT_DIR/${component.dir}"`,
405
416
  "npm install",
406
- `npm run dev -- --host "\${WEB_HOST:-127.0.0.1}" --port "\${${component.id.toUpperCase()}_PORT:-\${WEB_PORT:-${component.port}}}"`,
417
+ `npm run dev -- --host "\${WEB_HOST:-127.0.0.1}" --port "${webPortExpression}"`,
407
418
  ], options.componentScript ? componentScriptOptions() : {});
408
419
  }
409
420
 
@@ -450,8 +461,8 @@ ${startLines.length ? "wait" : ""}
450
461
 
451
462
  function renderEnvironmentGuardPortsScript(plan) {
452
463
  const ports = [
453
- ...plan.runtimes.apis.map((component) => ({ id: component.id, type: "api", env: `${component.id.toUpperCase()}_PORT`, fallbackEnv: "SERVER_PORT", port: component.port })),
454
- ...plan.runtimes.webs.map((component) => ({ id: component.id, type: "web", env: `${component.id.toUpperCase()}_PORT`, fallbackEnv: "WEB_PORT", port: component.port }))
464
+ ...plan.runtimes.apis.map((component, index) => ({ id: component.id, type: "api", env: `${component.id.toUpperCase()}_PORT`, fallbackEnv: index === 0 ? "SERVER_PORT" : null, port: component.port })),
465
+ ...plan.runtimes.webs.map((component, index) => ({ id: component.id, type: "web", env: `${component.id.toUpperCase()}_PORT`, fallbackEnv: index === 0 ? "WEB_PORT" : null, port: component.port }))
455
466
  ];
456
467
  return `#!/usr/bin/env node
457
468
  import net from "node:net";
@@ -461,7 +472,7 @@ const ports = ${JSON.stringify(ports, null, 2)};
461
472
  const expectedService = ${JSON.stringify(plan.runtimeReference.serviceName || "")};
462
473
 
463
474
  function effectivePort(entry) {
464
- return Number(process.env[entry.env] || process.env[entry.fallbackEnv] || entry.port);
475
+ return Number(process.env[entry.env] || (entry.fallbackEnv ? process.env[entry.fallbackEnv] : "") || entry.port);
465
476
  }
466
477
 
467
478
  function portInUse(port) {