@fabioplunser/epd 0.5.17 → 0.5.18

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.
Files changed (2) hide show
  1. package/dist/cli.js +286 -116
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -29,6 +29,12 @@ function redact(text) {
29
29
  out = out.replace(re, replacement);
30
30
  return out;
31
31
  }
32
+ function hostColor(name) {
33
+ let h = 0;
34
+ for (const ch of name)
35
+ h = h * 31 + ch.charCodeAt(0) >>> 0;
36
+ return HOST_COLORS[h % HOST_COLORS.length];
37
+ }
32
38
  function setVerbose(v) {
33
39
  verbose = v;
34
40
  }
@@ -93,25 +99,31 @@ function redactArgv(argv) {
93
99
  return argv.map((a, i) => /password|token|secret|key/i.test(argv[i - 1] ?? "") ? "***" : a);
94
100
  }
95
101
  function stamp(t) {
96
- return c.gray(`${(t / 1000).toFixed(1).padStart(5, " ")}s`);
102
+ return c.dim(c.gray(`${(t / 1000).toFixed(1).padStart(5, " ")}s`));
97
103
  }
98
104
  function render(e) {
99
105
  const s = stamp(e.t);
100
106
  switch (e.level) {
101
107
  case "step":
102
- return `${s} ${c.blue("\u203A")} ${c.bold(e.msg)}`;
108
+ return `${stepsShown++ ? `
109
+ ` : ""}${s} ${c.cyan(glyph.step)} ${c.bold(e.msg)}`;
103
110
  case "ok":
104
- return `${s} ${c.green("\u2713")} ${e.msg}`;
111
+ return `${s} ${c.green(glyph.ok)} ${e.msg}`;
105
112
  case "warn":
106
- return `${s} ${c.yellow("!")} ${e.msg}`;
107
- case "error":
108
- return `${s} ${c.red("\u2717")} ${e.msg}${e.hint ? `
109
-
110
- ${c.gray(e.hint)}` : ""}`;
113
+ return `${s} ${c.yellow(glyph.warn)} ${c.yellow(e.msg)}`;
114
+ case "error": {
115
+ const hint = e.hint ? `
116
+ ${e.hint.split(`
117
+ `).map((l) => ` ${c.gray(glyph.pipe)} ${c.gray(l)}`).join(`
118
+ `)}` : "";
119
+ return `${s} ${c.red(glyph.error)} ${c.bold(c.red(e.msg))}${hint}`;
120
+ }
111
121
  case "debug":
112
- return `${s} ${c.gray("\xB7")} ${c.gray(e.msg)}`;
113
- case "host":
114
- return `${s} ${c.magenta((e.host ?? "").padEnd(15).slice(0, 15))} ${e.msg}`;
122
+ return `${s} ${c.gray(glyph.debug)} ${c.gray(e.msg)}`;
123
+ case "host": {
124
+ const name = e.host ?? "";
125
+ return `${s} ${hostColor(name)(name.padEnd(15).slice(0, 15))} ${c.gray(glyph.pipe)} ${e.msg}`;
126
+ }
115
127
  case "output":
116
128
  return e.msg;
117
129
  case "plain":
@@ -172,7 +184,7 @@ function emitLines(level, args) {
172
184
  `))
173
185
  emit({ level, msg: line });
174
186
  }
175
- var knownSecrets, REDACTED = "[REDACTED]", SECRET_PATTERNS, format, colorOn, wrap = (code) => (s) => colorOn ? `\x1B[${code}m${s}\x1B[0m` : s, c, verbose = false, started, ANSI, stripAnsi = (s) => s.replace(ANSI, ""), fileFd = null, filePath = null, TAIL_MAX = 60, tail, listeners, realLog, realError, log, EpdError;
187
+ var knownSecrets, REDACTED = "[REDACTED]", SECRET_PATTERNS, format, colorOn, wrap = (code) => (s) => colorOn ? `\x1B[${code}m${s.replaceAll("\x1B[0m", `\x1B[0m\x1B[${code}m`)}\x1B[0m` : s, c, unicode, glyph, HOST_COLORS, verbose = false, started, ANSI, stripAnsi = (s) => s.replace(ANSI, ""), fileFd = null, filePath = null, TAIL_MAX = 60, tail, listeners, realLog, realError, stepsShown = 0, log, EpdError;
176
188
  var init_log = __esm(() => {
177
189
  knownSecrets = new Set;
178
190
  SECRET_PATTERNS = [
@@ -188,6 +200,8 @@ var init_log = __esm(() => {
188
200
  c = {
189
201
  dim: wrap("2"),
190
202
  bold: wrap("1"),
203
+ italic: wrap("3"),
204
+ underline: wrap("4"),
191
205
  red: wrap("31"),
192
206
  green: wrap("32"),
193
207
  yellow: wrap("33"),
@@ -196,6 +210,45 @@ var init_log = __esm(() => {
196
210
  cyan: wrap("36"),
197
211
  gray: wrap("90")
198
212
  };
213
+ unicode = process.env.EPD_ASCII !== "1" && (process.platform !== "win32" || Boolean(process.env.WT_SESSION || process.env.TERM_PROGRAM || process.env.ConEmuANSI));
214
+ glyph = unicode ? {
215
+ step: "\u25C6",
216
+ ok: "\u2714",
217
+ warn: "\u25B2",
218
+ error: "\u2716",
219
+ debug: "\xB7",
220
+ info: " ",
221
+ pipe: "\u2502",
222
+ arrow: "\u2192",
223
+ bullet: "\u2022",
224
+ rule: "\u2500",
225
+ dotOn: "\u25CF",
226
+ dotOff: "\u25CB",
227
+ barFull: "\u2588",
228
+ barEmpty: "\u2591",
229
+ prompt: "?",
230
+ enter: "\u21B5",
231
+ box: { tl: "\u256D", tr: "\u256E", bl: "\u2570", br: "\u256F", h: "\u2500", v: "\u2502" }
232
+ } : {
233
+ step: ">",
234
+ ok: "+",
235
+ warn: "!",
236
+ error: "x",
237
+ debug: ".",
238
+ info: " ",
239
+ pipe: "|",
240
+ arrow: "->",
241
+ bullet: "*",
242
+ rule: "-",
243
+ dotOn: "*",
244
+ dotOff: "o",
245
+ barFull: "#",
246
+ barEmpty: "-",
247
+ prompt: "?",
248
+ enter: ">",
249
+ box: { tl: "+", tr: "+", bl: "+", br: "+", h: "-", v: "|" }
250
+ };
251
+ HOST_COLORS = [c.magenta, c.cyan, c.blue, c.yellow, c.green];
199
252
  started = Date.now();
200
253
  ANSI = /\x1b\[[0-9;?]*[A-Za-z]/g;
201
254
  tail = [];
@@ -344,6 +397,64 @@ var init_misc = __esm(() => {
344
397
  init_log();
345
398
  });
346
399
 
400
+ // src/util/ui.ts
401
+ function stripAnsi2(s) {
402
+ return s.replace(ANSI2, "");
403
+ }
404
+ function visibleLength(s) {
405
+ return [...stripAnsi2(s)].length;
406
+ }
407
+ function padVisible(s, width) {
408
+ return s + " ".repeat(Math.max(0, width - visibleLength(s)));
409
+ }
410
+ function termWidth(max = 100) {
411
+ const cols = process.stdout.columns || 80;
412
+ return Math.max(40, Math.min(cols, max));
413
+ }
414
+ function heading(title) {
415
+ const rule = glyph.rule.repeat(Math.max(4, Math.min(48, termWidth() - visibleLength(title) - 4)));
416
+ return `${c.bold(title)} ${c.gray(rule)}`;
417
+ }
418
+ function section(title) {
419
+ log.plain("");
420
+ log.plain(heading(title));
421
+ }
422
+ function kv(rows, indent = 2) {
423
+ const shown = rows.filter((r) => Boolean(r[1]));
424
+ const width = Math.max(0, ...shown.map(([k]) => visibleLength(k)));
425
+ return shown.map(([k, v]) => `${" ".repeat(indent)}${c.gray(padVisible(k, width))} ${v}`).join(`
426
+ `);
427
+ }
428
+ function table(head, rows, indent = 2) {
429
+ const all = [head, ...rows];
430
+ const widths = head.map((_, i) => Math.max(...all.map((r) => visibleLength(r[i] ?? ""))));
431
+ const pad = " ".repeat(indent);
432
+ const line = (r) => (pad + r.map((cell, i) => padVisible(cell ?? "", widths[i])).join(" ")).trimEnd();
433
+ return [c.gray(line(head)), ...rows.map(line)].join(`
434
+ `);
435
+ }
436
+ function box(lines, opts = {}) {
437
+ const color = opts.color ?? c.gray;
438
+ const pad = " ".repeat(opts.padding ?? 1);
439
+ const title = opts.title ? ` ${opts.title} ` : "";
440
+ const inner = Math.max(visibleLength(title) + 2, ...lines.map((l) => visibleLength(l) + pad.length * 2));
441
+ const b = glyph.box;
442
+ const top = color(b.tl + b.h) + title + color(b.h.repeat(Math.max(0, inner - visibleLength(title) - 1)) + b.tr);
443
+ const body = lines.map((l) => `${color(b.v)}${pad}${padVisible(l, inner - pad.length * 2)}${pad}${color(b.v)}`);
444
+ const bottom = color(b.bl + b.h.repeat(inner) + b.br);
445
+ return [top, ...body, bottom].join(`
446
+ `);
447
+ }
448
+ function dot(ok) {
449
+ return ok ? c.green(glyph.dotOn) : c.red(glyph.dotOff);
450
+ }
451
+ var ANSI2;
452
+ var init_ui = __esm(() => {
453
+ init_log();
454
+ init_log();
455
+ ANSI2 = /\x1b\[[0-9;?]*[A-Za-z]/g;
456
+ });
457
+
347
458
  // src/util/prompt.ts
348
459
  function interactive() {
349
460
  return Boolean(process.stdin.isTTY && process.stdout.isTTY) && logFormat() !== "json" && !process.env.CI;
@@ -356,21 +467,21 @@ async function readLine() {
356
467
  async function ask(question, dflt) {
357
468
  if (!interactive())
358
469
  return dflt ?? "";
359
- process.stdout.write(`${c.cyan("?")} ${question}${dflt ? c.gray(` (${dflt})`) : ""} `);
470
+ process.stdout.write(`${mark()} ${c.bold(question)}${dflt ? c.gray(` (${dflt})`) : ""} ${c.gray(glyph.arrow)} `);
360
471
  const answer = (await readLine()).trim();
361
472
  return answer || dflt || "";
362
473
  }
363
474
  async function askSecret(question) {
364
475
  if (!interactive())
365
476
  return "";
366
- process.stdout.write(`${c.cyan("?")} ${question} `);
477
+ process.stdout.write(`${mark()} ${c.bold(question)} ${c.gray(glyph.arrow)} `);
367
478
  const answer = (await readLine()).trim();
368
479
  return answer;
369
480
  }
370
481
  async function askPassword(question) {
371
482
  if (!interactive())
372
483
  return "";
373
- process.stdout.write(`${c.cyan("?")} ${question} `);
484
+ process.stdout.write(`${mark()} ${c.bold(question)} ${c.gray(glyph.arrow)} `);
374
485
  const echo = await setEcho(false);
375
486
  try {
376
487
  return (await readLine()).trim();
@@ -392,13 +503,13 @@ async function setEcho(on) {
392
503
  async function pressEnter(message) {
393
504
  if (!interactive())
394
505
  return;
395
- process.stdout.write(`${c.cyan("\u21B5")} ${message} ${c.gray("[Press Enter]")} `);
506
+ process.stdout.write(`${c.cyan(glyph.enter)} ${message} ${c.gray("[press Enter]")} `);
396
507
  await readLine();
397
508
  }
398
509
  async function confirm(question, dflt = false) {
399
510
  if (!interactive())
400
511
  return dflt;
401
- const answer = (await ask(`${question} ${dflt ? "[Y/n]" : "[y/N]"}`)).toLowerCase();
512
+ const answer = (await ask(`${question} ${c.gray(dflt ? "[Y/n]" : "[y/N]")}`)).toLowerCase();
402
513
  if (!answer)
403
514
  return dflt;
404
515
  return answer === "y" || answer === "yes";
@@ -406,12 +517,17 @@ async function confirm(question, dflt = false) {
406
517
  async function choose(question, options, dflt) {
407
518
  if (!interactive())
408
519
  return dflt;
409
- console.log(`${c.cyan("?")} ${question}`);
410
- options.forEach((o, i) => console.log(` ${i + 1}) ${o.label}${o.value === dflt ? c.gray(" (default)") : ""}`));
520
+ console.log(`${mark()} ${c.bold(question)}`);
521
+ options.forEach((o, i) => {
522
+ const isDefault = o.value === dflt;
523
+ const num = c.cyan(String(i + 1).padStart(String(options.length).length));
524
+ console.log(` ${num} ${isDefault ? c.cyan(glyph.step) : " "} ${isDefault ? c.bold(o.label) : o.label}${isDefault ? c.gray(" default") : ""}`);
525
+ });
411
526
  const answer = (await ask("Choose", String(options.findIndex((o) => o.value === dflt) + 1))).trim();
412
527
  const idx = Number(answer) - 1;
413
528
  return options[idx]?.value ?? dflt;
414
529
  }
530
+ var mark = () => c.bold(c.cyan(glyph.prompt));
415
531
  var init_prompt = __esm(() => {
416
532
  init_log();
417
533
  });
@@ -6786,58 +6902,50 @@ async function deploy(loaded, opts = {}) {
6786
6902
  const version = (await resolveVersion(cfg, opts.version)).id;
6787
6903
  log.step(`Deploying ${c.bold(cfg.name)} ${c.cyan(version)}${cfg.destination ? ` \u2192 ${cfg.destination}` : ""} to ${targetHosts.length} host(s)`, "plan");
6788
6904
  if (opts.dryRun) {
6789
- log.step(`[dry-run] Simulating deployment plan for ${c.bold(cfg.name)} ${c.cyan(version)}`);
6790
- log.plain(`
6791
- ${c.bold("Deployment Plan")}`);
6792
- log.plain(` App: ${cfg.name}`);
6793
- log.plain(` Mode: ${cfg.mode}`);
6794
- log.plain(` Version: ${version}`);
6795
- log.plain(` Target hosts: ${targetHosts.join(", ")}`);
6796
- log.plain(` Services: ${services.map((s) => s.name).join(", ")}`);
6797
- if (cfg.mode === "docker") {
6798
- log.plain(` Image: ${cfg.image}:${version}${cfg.registry ? ` (push to ${cfg.registry.server ?? "docker.io"})` : " (ship over SSH)"}`);
6799
- } else {
6800
- log.plain(` Process: ${cfg.process.start}`);
6801
- }
6802
- log.plain(`
6803
- ${c.bold("Host & Service Details")}`);
6905
+ section(`Deployment plan ${c.yellow("(dry run)")}`);
6906
+ log.plain(kv([
6907
+ ["App", c.bold(cfg.name)],
6908
+ ["Mode", cfg.mode],
6909
+ ["Version", c.cyan(version)],
6910
+ ["Destination", cfg.destination],
6911
+ ["Target hosts", targetHosts.map((h) => hostColor(h)(h)).join(c.gray(", "))],
6912
+ ["Services", services.map((s) => s.name).join(", ")],
6913
+ cfg.mode === "docker" ? ["Image", `${cfg.image}:${version} ${c.gray(cfg.registry ? `(push to ${cfg.registry.server ?? "docker.io"})` : "(ship over SSH)")}`] : ["Process", cfg.process.start]
6914
+ ]));
6915
+ section("Hosts & services");
6804
6916
  for (const h of targetHosts) {
6805
- log.plain(` ${c.cyan(h)}:`);
6917
+ log.plain(` ${hostColor(h)(c.bold(h))}`);
6806
6918
  for (const svc of services) {
6807
- log.plain(` \u2022 Service: ${c.bold(svc.name)} (${svc.replicas} replica(s) on port ${svc.port})`);
6808
- if (usesHostPorts(cfg)) {
6809
- log.plain(` Host ports: blue=${hostPort(cfg, svc, "blue", 0)}, green=${hostPort(cfg, svc, "green", 0)}`);
6810
- }
6811
- log.plain(` Health check: ${svc.health.path ?? "tcp connect"} (status ${svc.health.status}, timeout ${svc.health.timeout}s)`);
6812
- for (const r of svc.routes) {
6813
- log.plain(` Route: ${r.ssl ? "https" : "http"}://${r.hosts.join(", ")}${r.path ?? ""} -> :${r.port}`);
6814
- }
6919
+ log.plain(` ${c.cyan(glyph.bullet)} ${c.bold(svc.name)} ${c.gray(`${svc.replicas} replica(s) on port ${svc.port}`)}`);
6920
+ const rows = [
6921
+ ["health", `${svc.health.path ?? "tcp connect"} ${c.gray(`(status ${svc.health.status}, timeout ${svc.health.timeout}s)`)}`],
6922
+ ["host ports", usesHostPorts(cfg) ? `blue=${hostPort(cfg, svc, "blue", 0)}, green=${hostPort(cfg, svc, "green", 0)}` : undefined],
6923
+ ...svc.routes.map((r) => ["route", `${c.underline(`${r.ssl ? "https" : "http"}://${r.hosts.join(", ")}${r.path ?? ""}`)} ${c.gray(`${glyph.arrow} :${r.port}`)}`])
6924
+ ];
6925
+ log.plain(kv(rows, 6));
6815
6926
  }
6816
6927
  }
6817
6928
  if (cfg.accessories.length) {
6818
- log.plain(`
6819
- ${c.bold("Accessories")}`);
6820
- for (const acc of cfg.accessories) {
6821
- log.plain(` \u2022 ${c.bold(acc.name)}: ${acc.image} on ${acc.host}`);
6822
- }
6929
+ section("Accessories");
6930
+ log.plain(kv(cfg.accessories.map((acc) => [acc.name, `${acc.image} ${c.gray(`on ${acc.host}`)}`])));
6823
6931
  }
6824
6932
  if (cfg.proxy.enabled) {
6825
- log.plain(`
6826
- ${c.bold("Proxy & Routing")}`);
6827
- log.plain(` Traefik proxy enabled across: ${proxyHosts(cfg).join(", ")}`);
6828
- log.plain(` Network: ${cfg.proxy.network}, SSL: ${cfg.proxy.ssl ? "enabled" : "disabled"}`);
6933
+ section("Proxy & routing");
6934
+ log.plain(kv([
6935
+ ["Traefik on", proxyHosts(cfg).join(", ")],
6936
+ ["Network", cfg.proxy.network],
6937
+ ["SSL", cfg.proxy.ssl ? c.green("enabled") : c.yellow("disabled")]
6938
+ ]));
6829
6939
  } else {
6830
- log.plain(`
6831
- ${c.bold("External Proxy")}`);
6832
- log.plain(` External proxy synchronization enabled (Caddy / Nginx / Traefik)`);
6940
+ section("External proxy");
6941
+ log.plain(" External proxy synchronization enabled (Caddy / Nginx / Traefik)");
6833
6942
  }
6834
6943
  if (cfg.dns?.enabled && cfg.dns.autoSync || cfg.cloudflare?.enabled && cfg.cloudflare.autoSync) {
6835
- log.plain(`
6836
- ${c.bold("DNS Synchronization")}`);
6837
- log.plain(` Auto-sync configured for ${cfg.dns?.provider || "cloudflare"}`);
6944
+ section("DNS");
6945
+ log.plain(kv([["Auto-sync", cfg.dns?.provider || "cloudflare"]]));
6838
6946
  }
6839
- log.plain(`
6840
- ${c.green("\u2713")} [dry-run] Plan validated successfully. No changes were made.`);
6947
+ log.plain("");
6948
+ log.ok(`[dry-run] Plan validated successfully. ${c.gray("No changes were made.")}`);
6841
6949
  return;
6842
6950
  }
6843
6951
  log.step(`Connecting to ${hosts.map((h) => h.target).join(", ")}`, "connect");
@@ -6879,7 +6987,7 @@ ${c.green("\u2713")} [dry-run] Plan validated successfully. No changes were made
6879
6987
  if (!opts.skipHooks && cfg.hooks.postDeploy)
6880
6988
  await hook(cfg, "post_deploy", cfg.hooks.postDeploy, version);
6881
6989
  log.ok(`Deployed ${cfg.name} ${version} in ${dur(Date.now() - started)}`);
6882
- printUrls(cfg);
6990
+ printUrls(cfg, `${c.green(glyph.ok)} ${c.bold(cfg.name)} ${c.cyan(version)} is live ${c.gray(`(${dur(Date.now() - started)})`)}`);
6883
6991
  }
6884
6992
  async function deployLocked(cfg, hosts, services, version, opts, fx, prep) {
6885
6993
  const snapshot = await snapshotLive(cfg, fx, true);
@@ -7340,7 +7448,7 @@ async function hook(cfg, name, script, version) {
7340
7448
  label: `hook ${name}`
7341
7449
  });
7342
7450
  }
7343
- function printUrls(cfg) {
7451
+ function printUrls(cfg, title) {
7344
7452
  const urls = new Set;
7345
7453
  for (const svc of cfg.services) {
7346
7454
  for (const route of svc.routes) {
@@ -7354,12 +7462,19 @@ function printUrls(cfg) {
7354
7462
  urls.add(`${route.ssl ? "https" : "http"}://${h}${route.path ?? ""}`);
7355
7463
  }
7356
7464
  }
7357
- for (const u of urls)
7358
- log.info(c.cyan(u));
7465
+ if (logFormat() === "json" || !title) {
7466
+ for (const u of urls)
7467
+ log.info(c.cyan(u));
7468
+ return;
7469
+ }
7470
+ const lines = urls.size ? [...urls].map((u) => `${c.cyan(glyph.arrow)} ${c.underline(u)}`) : [c.gray("no public routes configured")];
7471
+ log.plain("");
7472
+ log.plain(box(lines, { title, color: c.green, padding: 2 }));
7359
7473
  }
7360
7474
  var errMsg = (e) => e instanceof Error ? e.message : String(e);
7361
7475
  var init_deploy = __esm(() => {
7362
7476
  init_log();
7477
+ init_ui();
7363
7478
  init_misc();
7364
7479
  init_proc();
7365
7480
  init_bootstrap();
@@ -7637,19 +7752,13 @@ Options
7637
7752
  });
7638
7753
 
7639
7754
  // src/commands/status.ts
7640
- function table(rows, head) {
7641
- const all = [head, ...rows];
7642
- const widths = head.map((_, i) => Math.max(...all.map((r) => stripAnsi2(r[i] ?? "").length)));
7643
- const line = (r) => r.map((cell, i) => cell + " ".repeat(Math.max(0, widths[i] - stripAnsi2(cell).length))).join(" ").trimEnd();
7644
- return [c.gray(line(head)), ...rows.map(line)].join(`
7645
- `);
7646
- }
7647
- function stripAnsi2(s) {
7648
- return s.replace(/\x1b\[[0-9;]*m/g, "");
7755
+ function table2(rows, head) {
7756
+ return table(head, rows);
7649
7757
  }
7650
7758
  var status;
7651
7759
  var init_status = __esm(() => {
7652
7760
  init_log();
7761
+ init_ui();
7653
7762
  init_misc();
7654
7763
  init_state();
7655
7764
  init_ssh();
@@ -7690,20 +7799,24 @@ Options
7690
7799
  console.log(JSON.stringify({ app: cfg.name, mode: cfg.mode, hosts: report }, null, 2));
7691
7800
  return;
7692
7801
  }
7693
- log.plain(`${c.bold(cfg.name)} ${c.gray(`(${cfg.mode}${cfg.destination ? `, ${cfg.destination}` : ""})`)}`);
7802
+ log.plain("");
7803
+ log.plain(`${c.cyan(glyph.step)} ${c.bold(cfg.name)} ${c.gray(`${cfg.mode}${cfg.destination ? ` \xB7 ${cfg.destination}` : ""} \xB7 ${report.length} host(s)`)}`);
7694
7804
  for (const r of report) {
7695
7805
  log.plain("");
7696
7806
  if (!r.ok) {
7697
- log.plain(`${c.magenta(r.name)} ${c.red("unreachable")} ${c.gray(r.error)}`);
7807
+ log.plain(heading(hostColor(r.name)(r.name)));
7808
+ log.plain(` ${dot(false)} ${c.red("unreachable")} ${c.gray(r.error)}`);
7698
7809
  continue;
7699
7810
  }
7700
7811
  const version = r.state?.version ? c.cyan(r.state.version) : c.gray("nothing deployed");
7701
7812
  const proxyBit = r.proxy ? r.proxy.running ? c.green("proxy up") : c.red(`proxy ${r.proxy.status}`) : c.gray("no proxy");
7702
- log.plain(`${c.magenta(r.name)} ${version} ${proxyBit}`);
7813
+ log.plain(heading(hostColor(r.name)(r.name)));
7814
+ log.plain(kv([["version", version], ["proxy", proxyBit]]));
7815
+ log.plain("");
7703
7816
  if (cfg.mode === "docker") {
7704
7817
  const live = new Set(Object.values(r.state?.services ?? {}).map((s) => s.slot));
7705
7818
  const rows = r.containers.filter((ct) => ct.service).sort((a, b) => a.name.localeCompare(b.name)).map((ct) => [
7706
- ct.running ? c.green("\u25CF") : c.red("\u25CB"),
7819
+ dot(ct.running),
7707
7820
  ct.service,
7708
7821
  live.has(ct.slot) ? c.bold(ct.slot) : c.gray(ct.slot),
7709
7822
  ct.version,
@@ -7711,33 +7824,32 @@ Options
7711
7824
  ]);
7712
7825
  const accessories = r.containers.filter((ct) => !ct.service && ct.name.includes("-acc-"));
7713
7826
  for (const a of accessories)
7714
- rows.push([a.running ? c.green("\u25CF") : c.red("\u25CB"), c.gray("accessory"), a.name.split("-acc-")[1] ?? "", "", a.status]);
7715
- log.plain(rows.length ? table(rows, ["", "server", "slot", "version", "status"]) : c.gray(" no containers"));
7827
+ rows.push([dot(a.running), c.gray("accessory"), a.name.split("-acc-")[1] ?? "", "", a.status]);
7828
+ log.plain(rows.length ? table2(rows, ["", "server", "slot", "version", "status"]) : c.gray(" no containers"));
7716
7829
  } else {
7717
7830
  const rows = r.processes.map((p) => [
7718
- p.status === "online" ? c.green("\u25CF") : c.red("\u25CB"),
7831
+ dot(p.status === "online"),
7719
7832
  p.name.replace(`epd-${cfg.name}-`, ""),
7720
7833
  p.status,
7721
7834
  `${p.restarts} restarts`,
7722
7835
  `${Math.round(p.memory / 1024 / 1024)}MB`
7723
7836
  ]);
7724
- log.plain(rows.length ? table(rows, ["", "process", "status", "", "memory"]) : c.gray(" no processes"));
7837
+ log.plain(rows.length ? table2(rows, ["", "process", "status", "", "memory"]) : c.gray(" no processes"));
7725
7838
  }
7726
7839
  }
7727
7840
  const urls = new Set;
7728
7841
  for (const svc of cfg.services)
7729
7842
  for (const route of svc.routes)
7730
7843
  for (const h of route.hosts)
7731
- urls.add(`${route.ssl ? "https" : "http"}://${h}${route.path ?? ""} ${c.gray(`\u2192 ${svc.name}:${route.port}`)}`);
7844
+ urls.add(`${route.ssl ? "https" : "http"}://${h}${route.path ?? ""} ${c.gray(`${glyph.arrow} ${svc.name}:${route.port}`)}`);
7732
7845
  for (const acc of cfg.accessories)
7733
7846
  for (const route of acc.routes)
7734
7847
  for (const h of route.hosts)
7735
- urls.add(`${route.ssl ? "https" : "http"}://${h}${route.path ?? ""} ${c.gray(`\u2192 ${acc.name}:${route.port}`)}`);
7848
+ urls.add(`${route.ssl ? "https" : "http"}://${h}${route.path ?? ""} ${c.gray(`${glyph.arrow} ${acc.name}:${route.port}`)}`);
7736
7849
  if (urls.size) {
7737
- log.plain(`
7738
- ${c.bold("Routes")}`);
7850
+ section("Routes");
7739
7851
  for (const u of urls)
7740
- log.plain(` ${u}`);
7852
+ log.plain(` ${c.cyan(glyph.arrow)} ${u}`);
7741
7853
  }
7742
7854
  }
7743
7855
  };
@@ -9628,7 +9740,7 @@ var init_update = __esm(() => {
9628
9740
  });
9629
9741
 
9630
9742
  // package.json
9631
- var version = "0.5.17";
9743
+ var version = "0.5.18";
9632
9744
  var init_package = () => {};
9633
9745
 
9634
9746
  // src/version.ts
@@ -11568,6 +11680,7 @@ var init_commands = __esm(() => {
11568
11680
  init_log();
11569
11681
  init_interrupt();
11570
11682
  init_misc();
11683
+ init_ui();
11571
11684
  init_prompt();
11572
11685
  init_load();
11573
11686
  init_commands();
@@ -11596,45 +11709,99 @@ var CATEGORIES = [
11596
11709
  commands: ["doctor", "completion", "update"]
11597
11710
  }
11598
11711
  ];
11712
+ var GLOBAL_OPTIONS = [
11713
+ ["-c, --config <file>", "Path to epd.yml"],
11714
+ ["-d, --destination <d>", "Overlay epd.<d>.yml (staging, production, \u2026)"],
11715
+ ["-v, --verbose", "Show every command epd runs"],
11716
+ [" --log-format <f>", `pretty (default) or json: one JSON event per line on stdout,
11717
+ ending with a "result" event (EPD_LOG_FORMAT)`],
11718
+ ["-h, --help", "Show help for a command"],
11719
+ [" --version", "Print the epd version"]
11720
+ ];
11721
+ var EXAMPLES = [
11722
+ ["epd init", "Create an epd.yml for this project"],
11723
+ ["epd doctor", "Run pre-flight health & config diagnostics"],
11724
+ ["epd setup", "Prepare the servers, then deploy"],
11725
+ ["epd deploy", "Build and deploy the current commit"],
11726
+ ["epd deploy --dry-run", "Simulate deployment plan without making changes"],
11727
+ ["epd deploy -d staging", "Deploy with the staging overlay"],
11728
+ ["epd rollback", "Go back to the previous version"],
11729
+ ["epd logs -f", "Follow logs from every server"],
11730
+ ["epd docker-command", "Print the docker run command epd would use"],
11731
+ ["epd completion zsh", "Generate shell autocompletion"]
11732
+ ];
11733
+ function columns(rows, color, indent = 4, minWidth = 0) {
11734
+ const width = Math.max(minWidth, ...rows.map(([l]) => l.length + 3));
11735
+ return rows.map(([left, right]) => {
11736
+ const [first, ...more] = right.split(`
11737
+ `);
11738
+ const cont = more.map((l) => `
11739
+ ${" ".repeat(indent + width)}${l}`).join("");
11740
+ return `${" ".repeat(indent)}${color(left.padEnd(width))}${first}${cont}`;
11741
+ }).join(`
11742
+ `);
11743
+ }
11744
+ function banner() {
11745
+ return `${c.cyan(c.bold(`${glyph.step} epd`))} ${c.bold("Easy Project Deployer")} ${c.gray(`v${VERSION}`)}`;
11746
+ }
11599
11747
  function renderUsage() {
11748
+ const nameWidth = Math.max(...commands.filter((cmd) => !cmd.hidden).map((cmd) => cmd.name.length)) + 3;
11600
11749
  const renderedCategories = CATEGORIES.map((cat) => {
11601
- const lines = cat.commands.map((name) => commands.find((cmd) => cmd.name === name)).filter((cmd) => Boolean(cmd && !cmd.hidden)).map((cmd) => ` ${cmd.name.padEnd(16)}${cmd.summary}`);
11750
+ const cmds = cat.commands.map((name) => commands.find((cmd) => cmd.name === name)).filter((cmd) => Boolean(cmd && !cmd.hidden));
11751
+ const rows = cmds.map((cmd) => [
11752
+ cmd.name,
11753
+ cmd.summary + (cmd.aliases?.length ? c.gray(` (${cmd.aliases.join(", ")})`) : "")
11754
+ ]);
11602
11755
  return ` ${c.bold(cat.title)}
11603
- ${lines.join(`
11604
- `)}`;
11756
+ ${columns(rows, c.cyan, 4, nameWidth)}`;
11605
11757
  }).join(`
11606
11758
 
11607
11759
  `);
11608
- return `${c.bold("epd")} \u2014 Easy Project Deployer ${c.gray(`v${VERSION}`)}
11760
+ const examples = columns(EXAMPLES.map(([cmd, desc]) => [cmd, c.gray(desc)]), (s) => `${c.gray("$")} ${s}`, 2);
11761
+ return `
11762
+ ${banner()}
11763
+ ${c.gray("Zero-downtime deploys to your own servers, with Docker or PM2 behind Traefik.")}
11609
11764
 
11610
- ${c.bold("Usage")}
11611
- epd <command> [options]
11765
+ ${heading("Usage")}
11766
+ ${c.gray("$")} epd ${c.cyan("<command>")} ${c.gray("[options]")}
11612
11767
 
11613
- ${c.bold("Commands")}
11768
+ ${heading("Commands")}
11614
11769
  ${renderedCategories}
11615
11770
 
11616
- ${c.bold("Global options")}
11617
- -c, --config <file> Path to epd.yml
11618
- -d, --destination <d> Overlay epd.<d>.yml (staging, production, \u2026)
11619
- -v, --verbose Show every command epd runs
11620
- --log-format <f> pretty (default) or json: one JSON event per line on
11621
- stdout, ending with a "result" event (EPD_LOG_FORMAT)
11622
- -h, --help Show help for a command
11623
- --version Print the epd version
11624
-
11625
- ${c.bold("Examples")}
11626
- epd init Create an epd.yml for this project
11627
- epd doctor Run pre-flight health & config diagnostics
11628
- epd setup Prepare the servers, then deploy
11629
- epd deploy Build and deploy the current commit
11630
- epd deploy --dry-run Simulate deployment plan without making changes
11631
- epd deploy -d staging Deploy with the staging overlay
11632
- epd rollback Go back to the previous version
11633
- epd logs -f Follow logs from every server
11634
- epd docker-command Print the docker run command epd would use
11635
- epd completion zsh Generate shell autocompletion
11771
+ ${heading("Global options")}
11772
+ ${columns(GLOBAL_OPTIONS, c.cyan, 2)}
11773
+
11774
+ ${heading("Examples")}
11775
+ ${examples}
11776
+
11777
+ ${c.gray(`Run ${c.cyan("epd <command> --help")} for details on a command. Docs: ${c.underline("https://epd.peppi.dev")}`)}
11636
11778
  `;
11637
11779
  }
11780
+ function styleHelp(text) {
11781
+ return text.split(`
11782
+ `).map((line, i) => {
11783
+ if (i === 0)
11784
+ return `
11785
+ ${line.replace(/^(\x1b\[1m)?(epd[\w -]*?)(\x1b\[0m)?(?= \u2014)/, (_m, _a, name) => c.cyan(c.bold(name)))}`;
11786
+ if (/^[A-Z][A-Za-z0-9 &/()-]{1,40}:?$/.test(stripAnsi2(line)))
11787
+ return heading(stripAnsi2(line).replace(/:$/, ""));
11788
+ if (/\x1b\[/.test(line))
11789
+ return line;
11790
+ const opt = line.match(/^(\s+)(-{1,2}[A-Za-z0-9][^\s]*(?:,? -{1,2}[^\s]+)*(?: <[^>]+>| \[[^\]]+\])?)(\s{2,}|(?<=[>\]])\s+)(.*)$/);
11791
+ if (opt) {
11792
+ const flag = opt[2].replace(/(<[^>]+>|\[[^\]]+\])/g, (m) => c.gray(m));
11793
+ return `${opt[1]}${c.cyan(flag)}${opt[3]}${opt[4]}`;
11794
+ }
11795
+ const env = line.match(/^(\s+)([A-Z][A-Z0-9_]{2,})(\s{2,}.*)$/);
11796
+ if (env)
11797
+ return `${env[1]}${c.cyan(env[2])}${env[3]}`;
11798
+ const ex = line.match(/^(\s+)(epd\b.*?)((?:\s{2,}|\s+#).*)?$/);
11799
+ if (ex)
11800
+ return `${ex[1]}${c.gray("$")} ${ex[2]}${ex[3] ? c.gray(ex[3]) : ""}`;
11801
+ return line;
11802
+ }).join(`
11803
+ `);
11804
+ }
11638
11805
  async function main(argv) {
11639
11806
  if (argv.includes("--version") && !argv[0]?.startsWith("-")) {}
11640
11807
  const first = argv[0];
@@ -11699,11 +11866,11 @@ Run ${c.cyan("epd --help")} to see the available commands.
11699
11866
  } catch (e) {
11700
11867
  log.error(e instanceof Error ? e.message : String(e));
11701
11868
  console.log(`
11702
- ${command.help()}`);
11869
+ ${styleHelp(command.help())}`);
11703
11870
  return 1;
11704
11871
  }
11705
11872
  if (parsed.values.help) {
11706
- console.log(command.help());
11873
+ console.log(styleHelp(command.help()));
11707
11874
  return 0;
11708
11875
  }
11709
11876
  setVerbose(Boolean(parsed.values.verbose));
@@ -11788,3 +11955,6 @@ try {
11788
11955
  process.exitCode = 1;
11789
11956
  finish(false, 1, error instanceof Error ? error.message : String(error), error instanceof EpdError ? error.hint : undefined);
11790
11957
  }
11958
+ export {
11959
+ styleHelp
11960
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabioplunser/epd",
3
- "version": "0.5.17",
3
+ "version": "0.5.18",
4
4
  "description": "Easy Project Deployer \u2014 deploy any project to one or many servers with Docker or PM2, fronted by Traefik.",
5
5
  "type": "module",
6
6
  "author": "Fabio Pl\u00fcnser",