@getmonoceros/workbench 1.7.0 → 1.7.2

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.js CHANGED
@@ -3611,7 +3611,7 @@ function warnOnDeprecatedFeatureRefs(containerFeatures, globalConfig, logger) {
3611
3611
  }
3612
3612
 
3613
3613
  // src/version.ts
3614
- var CLI_VERSION = true ? "1.7.0" : "dev";
3614
+ var CLI_VERSION = true ? "1.7.2" : "dev";
3615
3615
 
3616
3616
  // src/commands/_dispatch.ts
3617
3617
  import { consola as consola12 } from "consola";
@@ -4046,7 +4046,7 @@ var SCHEMA_HEADER = [
4046
4046
  "# under `features:` also accepts options not shown here \u2014 check",
4047
4047
  "# the feature's `devcontainer-feature.json` for the full list."
4048
4048
  ];
4049
- function generateComposedYml(name, components, lookupManifest, repoUrls = []) {
4049
+ function generateComposedYml(name, components, lookupManifest, repoUrls = [], ports = []) {
4050
4050
  const merged = mergeComponents(components);
4051
4051
  const lines = [];
4052
4052
  for (const h of SCHEMA_HEADER) lines.push(h);
@@ -4085,9 +4085,12 @@ function generateComposedYml(name, components, lookupManifest, repoUrls = []) {
4085
4085
  false
4086
4086
  );
4087
4087
  }
4088
+ if (ports.length > 0) {
4089
+ renderActiveRoutingBlock(lines, name, ports);
4090
+ }
4088
4091
  return ensureTrailingNewline(lines.join("\n"));
4089
4092
  }
4090
- function generateDocumentedYml(name, catalog, lookupManifest, repoUrls = []) {
4093
+ function generateDocumentedYml(name, catalog, lookupManifest, repoUrls = [], ports = []) {
4091
4094
  const byCategory = groupByCategory(catalog);
4092
4095
  const lines = [];
4093
4096
  for (const h of SCHEMA_HEADER) lines.push(h);
@@ -4194,7 +4197,11 @@ function generateDocumentedYml(name, catalog, lookupManifest, repoUrls = []) {
4194
4197
  /* commented */
4195
4198
  repoUrls.length === 0
4196
4199
  );
4197
- renderRoutingBlock(lines);
4200
+ if (ports.length > 0) {
4201
+ renderActiveRoutingBlock(lines, name, ports);
4202
+ } else {
4203
+ renderRoutingHintBlock(lines);
4204
+ }
4198
4205
  return ensureTrailingNewline(lines.join("\n"));
4199
4206
  }
4200
4207
  var COMMENT_WIDTH = 72;
@@ -4294,13 +4301,14 @@ function renderReposBlock(out, urls, commented) {
4294
4301
  }
4295
4302
  out.push("");
4296
4303
  }
4297
- function renderRoutingBlock(out) {
4304
+ function renderRoutingHintBlock(out) {
4298
4305
  out.push("# Routing \u2014 expose container ports to the host through the");
4299
4306
  out.push("# shared Traefik singleton. Once any port is declared the");
4300
4307
  out.push("# container joins the monoceros-proxy network and the proxy");
4301
4308
  out.push("# routes <name>.localhost (default port) and");
4302
4309
  out.push("# <name>-<port>.localhost (explicit). `monoceros add-port`");
4303
- out.push("# manages the list; the block appears on first add.");
4310
+ out.push("# manages the list; the block appears on first add. You can");
4311
+ out.push("# also pre-seed at init time via `--with-ports=3000,5173,\u2026`.");
4304
4312
  out.push("#");
4305
4313
  out.push("# routing:");
4306
4314
  out.push("# ports: # internal container ports");
@@ -4319,6 +4327,23 @@ function renderRoutingBlock(out) {
4319
4327
  );
4320
4328
  out.push("");
4321
4329
  }
4330
+ function renderActiveRoutingBlock(out, name, ports) {
4331
+ out.push("# Routing \u2014 expose these container ports to the host through");
4332
+ out.push("# the shared Traefik singleton. First entry doubles as");
4333
+ out.push(`# http://${name}.localhost (the default route). See ADR 0007.`);
4334
+ out.push("routing:");
4335
+ out.push(" ports:");
4336
+ ports.forEach((port, idx) => {
4337
+ if (idx === 0) {
4338
+ out.push(` - ${port} # default \u2192 http://${name}.localhost`);
4339
+ } else {
4340
+ out.push(` - ${port}`);
4341
+ }
4342
+ });
4343
+ out.push(" # vscodeAutoForward: false # set true to keep VS Code's");
4344
+ out.push(" # # port-panel alongside Traefik");
4345
+ out.push("");
4346
+ }
4322
4347
  function deriveDefaultPath(url) {
4323
4348
  let last = url;
4324
4349
  const slash = url.lastIndexOf("/");
@@ -4482,13 +4507,26 @@ async function runInit(opts) {
4482
4507
  );
4483
4508
  }
4484
4509
  }
4510
+ const portsRaw = opts.withPorts ?? [];
4511
+ const ports = [];
4512
+ const seenPorts = /* @__PURE__ */ new Set();
4513
+ for (const raw of portsRaw) {
4514
+ if (!Number.isInteger(raw) || raw < 1 || raw > 65535) {
4515
+ throw new Error(
4516
+ `Invalid port in --with-ports: ${JSON.stringify(raw)}. Expected integers between 1 and 65535.`
4517
+ );
4518
+ }
4519
+ if (seenPorts.has(raw)) continue;
4520
+ seenPorts.add(raw);
4521
+ ports.push(raw);
4522
+ }
4485
4523
  let text;
4486
4524
  const requested = opts.with ?? [];
4487
4525
  if (requested.length === 0) {
4488
- text = generateDocumentedYml(opts.name, catalog, lookup, repos);
4526
+ text = generateDocumentedYml(opts.name, catalog, lookup, repos, ports);
4489
4527
  } else {
4490
4528
  const components = resolveComponents(catalog, requested);
4491
- text = generateComposedYml(opts.name, components, lookup, repos);
4529
+ text = generateComposedYml(opts.name, components, lookup, repos, ports);
4492
4530
  }
4493
4531
  await fs12.mkdir(containerConfigsDir(home), { recursive: true });
4494
4532
  await fs12.writeFile(dest, text, "utf8");
@@ -4531,16 +4569,23 @@ var initCommand = defineCommand10({
4531
4569
  type: "string",
4532
4570
  description: "Git URL of a repo to clone into projects/ on first apply. Repeatable: pass --with-repo=URL1 --with-repo=URL2 for multiple repos. Folder name derived from URL (foo.git \u2192 projects/foo/); use `monoceros add-repo --path=...` post-init for subfolder paths.",
4533
4571
  required: false
4572
+ },
4573
+ "with-ports": {
4574
+ type: "string",
4575
+ description: "Comma-separated list of container-internal ports to expose via Traefik, e.g. --with-ports=3000,5173,6006. First entry doubles as http://<name>.localhost (default route). Equivalent to `monoceros add-port` after init. Each must be an integer in 1\u201365535.",
4576
+ required: false
4534
4577
  }
4535
4578
  },
4536
4579
  async run({ args, rawArgs }) {
4537
4580
  try {
4538
4581
  const withList = collectWithList(args.with, rawArgs);
4539
4582
  const withRepoList = collectWithRepoList(rawArgs);
4583
+ const withPortsList = collectWithPortsList(args["with-ports"], rawArgs);
4540
4584
  await runInit({
4541
4585
  name: args.name,
4542
4586
  ...withList ? { with: withList } : {},
4543
- ...withRepoList.length > 0 ? { withRepo: withRepoList } : {}
4587
+ ...withRepoList.length > 0 ? { withRepo: withRepoList } : {},
4588
+ ...withPortsList && withPortsList.length > 0 ? { withPorts: withPortsList } : {}
4544
4589
  });
4545
4590
  } catch (err) {
4546
4591
  consola14.error(err instanceof Error ? err.message : String(err));
@@ -4548,6 +4593,41 @@ var initCommand = defineCommand10({
4548
4593
  }
4549
4594
  }
4550
4595
  });
4596
+ function collectWithPortsList(_withPortsArg, rawArgs) {
4597
+ const pieces = [];
4598
+ for (let i = 0; i < rawArgs.length; i += 1) {
4599
+ const t = rawArgs[i];
4600
+ let scanStart = -1;
4601
+ if (t === "--with-ports") {
4602
+ scanStart = i + 1;
4603
+ } else if (t.startsWith("--with-ports=")) {
4604
+ pieces.push(t.slice("--with-ports=".length));
4605
+ scanStart = i + 1;
4606
+ }
4607
+ if (scanStart < 0) continue;
4608
+ let j = scanStart;
4609
+ while (j < rawArgs.length) {
4610
+ const u = rawArgs[j];
4611
+ if (u.startsWith("-")) break;
4612
+ pieces.push(u);
4613
+ j += 1;
4614
+ }
4615
+ i = j - 1;
4616
+ }
4617
+ const parts = pieces.flatMap((s) => s.split(",")).map((s) => s.trim()).filter((s) => s.length > 0);
4618
+ if (parts.length === 0) return void 0;
4619
+ const out = [];
4620
+ for (const p of parts) {
4621
+ const n = Number(p);
4622
+ if (!Number.isInteger(n) || n < 1 || n > 65535) {
4623
+ throw new Error(
4624
+ `Invalid port in --with-ports: ${JSON.stringify(p)}. Expected integers between 1 and 65535, comma-separated.`
4625
+ );
4626
+ }
4627
+ out.push(n);
4628
+ }
4629
+ return out;
4630
+ }
4551
4631
  function collectWithRepoList(rawArgs) {
4552
4632
  const urls = [];
4553
4633
  for (let i = 0; i < rawArgs.length; i += 1) {