@fabioplunser/epd 0.5.16 → 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 +309 -117
  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
  });
@@ -5809,6 +5925,7 @@ async function buildImage(cfg, version, env) {
5809
5925
  }
5810
5926
  cfg.containerEngine = await containerEngine(cfg.containerEngine);
5811
5927
  const ref = imageRef(cfg, version);
5928
+ await loginLocalRegistry(cfg, env);
5812
5929
  log.step(`Building ${ref}`, "build");
5813
5930
  if (await hasBuildx(cfg.containerEngine))
5814
5931
  await buildWithBuildx(cfg, ref, version, env);
@@ -5902,6 +6019,27 @@ async function loginRegistry(host, cfg, env) {
5902
6019
  const server = cfg.registry.server ?? "";
5903
6020
  await host.exec(`printf '%s' ${shq(password)} | docker login ${server ? shq(server) + " " : ""}--username ${shq(cfg.registry.username)} --password-stdin >/dev/null`, { label: `${host.name}: docker login` });
5904
6021
  }
6022
+ function registryServer(cfg) {
6023
+ if (cfg.registry?.server)
6024
+ return cfg.registry.server;
6025
+ const first = cfg.image.split("/")[0] ?? "";
6026
+ return cfg.image.includes("/") && (/[.:]/.test(first) || first === "localhost") ? first : "docker.io";
6027
+ }
6028
+ async function loginLocalRegistry(cfg, env) {
6029
+ if (!cfg.registry)
6030
+ return;
6031
+ checkRegistryPassword(cfg, env);
6032
+ const engine = await containerEngine(cfg.containerEngine);
6033
+ const server = registryServer(cfg);
6034
+ const res = await run([engine, "login", server, "--username", cfg.registry.username, "--password-stdin"], {
6035
+ input: env[cfg.registry.passwordEnv],
6036
+ allowFailure: true,
6037
+ label: `${engine} login ${server}`
6038
+ });
6039
+ if (res.code !== 0) {
6040
+ log.warn(`${engine} login ${server} failed; pushing with existing credentials. ${(res.stderr || res.stdout).trim()}`);
6041
+ }
6042
+ }
5905
6043
  async function ensureImage(host, cfg, version) {
5906
6044
  const ref = imageRef(cfg, version);
5907
6045
  if (await host.test(`docker image inspect ${shq(ref)} >/dev/null 2>&1`)) {
@@ -6764,58 +6902,50 @@ async function deploy(loaded, opts = {}) {
6764
6902
  const version = (await resolveVersion(cfg, opts.version)).id;
6765
6903
  log.step(`Deploying ${c.bold(cfg.name)} ${c.cyan(version)}${cfg.destination ? ` \u2192 ${cfg.destination}` : ""} to ${targetHosts.length} host(s)`, "plan");
6766
6904
  if (opts.dryRun) {
6767
- log.step(`[dry-run] Simulating deployment plan for ${c.bold(cfg.name)} ${c.cyan(version)}`);
6768
- log.plain(`
6769
- ${c.bold("Deployment Plan")}`);
6770
- log.plain(` App: ${cfg.name}`);
6771
- log.plain(` Mode: ${cfg.mode}`);
6772
- log.plain(` Version: ${version}`);
6773
- log.plain(` Target hosts: ${targetHosts.join(", ")}`);
6774
- log.plain(` Services: ${services.map((s) => s.name).join(", ")}`);
6775
- if (cfg.mode === "docker") {
6776
- log.plain(` Image: ${cfg.image}:${version}${cfg.registry ? ` (push to ${cfg.registry.server ?? "docker.io"})` : " (ship over SSH)"}`);
6777
- } else {
6778
- log.plain(` Process: ${cfg.process.start}`);
6779
- }
6780
- log.plain(`
6781
- ${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");
6782
6916
  for (const h of targetHosts) {
6783
- log.plain(` ${c.cyan(h)}:`);
6917
+ log.plain(` ${hostColor(h)(c.bold(h))}`);
6784
6918
  for (const svc of services) {
6785
- log.plain(` \u2022 Service: ${c.bold(svc.name)} (${svc.replicas} replica(s) on port ${svc.port})`);
6786
- if (usesHostPorts(cfg)) {
6787
- log.plain(` Host ports: blue=${hostPort(cfg, svc, "blue", 0)}, green=${hostPort(cfg, svc, "green", 0)}`);
6788
- }
6789
- log.plain(` Health check: ${svc.health.path ?? "tcp connect"} (status ${svc.health.status}, timeout ${svc.health.timeout}s)`);
6790
- for (const r of svc.routes) {
6791
- log.plain(` Route: ${r.ssl ? "https" : "http"}://${r.hosts.join(", ")}${r.path ?? ""} -> :${r.port}`);
6792
- }
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));
6793
6926
  }
6794
6927
  }
6795
6928
  if (cfg.accessories.length) {
6796
- log.plain(`
6797
- ${c.bold("Accessories")}`);
6798
- for (const acc of cfg.accessories) {
6799
- log.plain(` \u2022 ${c.bold(acc.name)}: ${acc.image} on ${acc.host}`);
6800
- }
6929
+ section("Accessories");
6930
+ log.plain(kv(cfg.accessories.map((acc) => [acc.name, `${acc.image} ${c.gray(`on ${acc.host}`)}`])));
6801
6931
  }
6802
6932
  if (cfg.proxy.enabled) {
6803
- log.plain(`
6804
- ${c.bold("Proxy & Routing")}`);
6805
- log.plain(` Traefik proxy enabled across: ${proxyHosts(cfg).join(", ")}`);
6806
- 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
+ ]));
6807
6939
  } else {
6808
- log.plain(`
6809
- ${c.bold("External Proxy")}`);
6810
- log.plain(` External proxy synchronization enabled (Caddy / Nginx / Traefik)`);
6940
+ section("External proxy");
6941
+ log.plain(" External proxy synchronization enabled (Caddy / Nginx / Traefik)");
6811
6942
  }
6812
6943
  if (cfg.dns?.enabled && cfg.dns.autoSync || cfg.cloudflare?.enabled && cfg.cloudflare.autoSync) {
6813
- log.plain(`
6814
- ${c.bold("DNS Synchronization")}`);
6815
- log.plain(` Auto-sync configured for ${cfg.dns?.provider || "cloudflare"}`);
6944
+ section("DNS");
6945
+ log.plain(kv([["Auto-sync", cfg.dns?.provider || "cloudflare"]]));
6816
6946
  }
6817
- log.plain(`
6818
- ${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.")}`);
6819
6949
  return;
6820
6950
  }
6821
6951
  log.step(`Connecting to ${hosts.map((h) => h.target).join(", ")}`, "connect");
@@ -6857,7 +6987,7 @@ ${c.green("\u2713")} [dry-run] Plan validated successfully. No changes were made
6857
6987
  if (!opts.skipHooks && cfg.hooks.postDeploy)
6858
6988
  await hook(cfg, "post_deploy", cfg.hooks.postDeploy, version);
6859
6989
  log.ok(`Deployed ${cfg.name} ${version} in ${dur(Date.now() - started)}`);
6860
- printUrls(cfg);
6990
+ printUrls(cfg, `${c.green(glyph.ok)} ${c.bold(cfg.name)} ${c.cyan(version)} is live ${c.gray(`(${dur(Date.now() - started)})`)}`);
6861
6991
  }
6862
6992
  async function deployLocked(cfg, hosts, services, version, opts, fx, prep) {
6863
6993
  const snapshot = await snapshotLive(cfg, fx, true);
@@ -7318,7 +7448,7 @@ async function hook(cfg, name, script, version) {
7318
7448
  label: `hook ${name}`
7319
7449
  });
7320
7450
  }
7321
- function printUrls(cfg) {
7451
+ function printUrls(cfg, title) {
7322
7452
  const urls = new Set;
7323
7453
  for (const svc of cfg.services) {
7324
7454
  for (const route of svc.routes) {
@@ -7332,12 +7462,19 @@ function printUrls(cfg) {
7332
7462
  urls.add(`${route.ssl ? "https" : "http"}://${h}${route.path ?? ""}`);
7333
7463
  }
7334
7464
  }
7335
- for (const u of urls)
7336
- 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 }));
7337
7473
  }
7338
7474
  var errMsg = (e) => e instanceof Error ? e.message : String(e);
7339
7475
  var init_deploy = __esm(() => {
7340
7476
  init_log();
7477
+ init_ui();
7341
7478
  init_misc();
7342
7479
  init_proc();
7343
7480
  init_bootstrap();
@@ -7615,19 +7752,13 @@ Options
7615
7752
  });
7616
7753
 
7617
7754
  // src/commands/status.ts
7618
- function table(rows, head) {
7619
- const all = [head, ...rows];
7620
- const widths = head.map((_, i) => Math.max(...all.map((r) => stripAnsi2(r[i] ?? "").length)));
7621
- const line = (r) => r.map((cell, i) => cell + " ".repeat(Math.max(0, widths[i] - stripAnsi2(cell).length))).join(" ").trimEnd();
7622
- return [c.gray(line(head)), ...rows.map(line)].join(`
7623
- `);
7624
- }
7625
- function stripAnsi2(s) {
7626
- return s.replace(/\x1b\[[0-9;]*m/g, "");
7755
+ function table2(rows, head) {
7756
+ return table(head, rows);
7627
7757
  }
7628
7758
  var status;
7629
7759
  var init_status = __esm(() => {
7630
7760
  init_log();
7761
+ init_ui();
7631
7762
  init_misc();
7632
7763
  init_state();
7633
7764
  init_ssh();
@@ -7668,20 +7799,24 @@ Options
7668
7799
  console.log(JSON.stringify({ app: cfg.name, mode: cfg.mode, hosts: report }, null, 2));
7669
7800
  return;
7670
7801
  }
7671
- 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)`)}`);
7672
7804
  for (const r of report) {
7673
7805
  log.plain("");
7674
7806
  if (!r.ok) {
7675
- 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)}`);
7676
7809
  continue;
7677
7810
  }
7678
7811
  const version = r.state?.version ? c.cyan(r.state.version) : c.gray("nothing deployed");
7679
7812
  const proxyBit = r.proxy ? r.proxy.running ? c.green("proxy up") : c.red(`proxy ${r.proxy.status}`) : c.gray("no proxy");
7680
- 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("");
7681
7816
  if (cfg.mode === "docker") {
7682
7817
  const live = new Set(Object.values(r.state?.services ?? {}).map((s) => s.slot));
7683
7818
  const rows = r.containers.filter((ct) => ct.service).sort((a, b) => a.name.localeCompare(b.name)).map((ct) => [
7684
- ct.running ? c.green("\u25CF") : c.red("\u25CB"),
7819
+ dot(ct.running),
7685
7820
  ct.service,
7686
7821
  live.has(ct.slot) ? c.bold(ct.slot) : c.gray(ct.slot),
7687
7822
  ct.version,
@@ -7689,33 +7824,32 @@ Options
7689
7824
  ]);
7690
7825
  const accessories = r.containers.filter((ct) => !ct.service && ct.name.includes("-acc-"));
7691
7826
  for (const a of accessories)
7692
- rows.push([a.running ? c.green("\u25CF") : c.red("\u25CB"), c.gray("accessory"), a.name.split("-acc-")[1] ?? "", "", a.status]);
7693
- 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"));
7694
7829
  } else {
7695
7830
  const rows = r.processes.map((p) => [
7696
- p.status === "online" ? c.green("\u25CF") : c.red("\u25CB"),
7831
+ dot(p.status === "online"),
7697
7832
  p.name.replace(`epd-${cfg.name}-`, ""),
7698
7833
  p.status,
7699
7834
  `${p.restarts} restarts`,
7700
7835
  `${Math.round(p.memory / 1024 / 1024)}MB`
7701
7836
  ]);
7702
- 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"));
7703
7838
  }
7704
7839
  }
7705
7840
  const urls = new Set;
7706
7841
  for (const svc of cfg.services)
7707
7842
  for (const route of svc.routes)
7708
7843
  for (const h of route.hosts)
7709
- 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}`)}`);
7710
7845
  for (const acc of cfg.accessories)
7711
7846
  for (const route of acc.routes)
7712
7847
  for (const h of route.hosts)
7713
- 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}`)}`);
7714
7849
  if (urls.size) {
7715
- log.plain(`
7716
- ${c.bold("Routes")}`);
7850
+ section("Routes");
7717
7851
  for (const u of urls)
7718
- log.plain(` ${u}`);
7852
+ log.plain(` ${c.cyan(glyph.arrow)} ${u}`);
7719
7853
  }
7720
7854
  }
7721
7855
  };
@@ -9462,7 +9596,7 @@ function isNewer(current, latest) {
9462
9596
  return lPatch > cPatch;
9463
9597
  }
9464
9598
  function getCachePath() {
9465
- return join11(homedir5(), ".epd", "update-check.json");
9599
+ return join11(process.env.HOME || homedir5(), ".epd", "update-check.json");
9466
9600
  }
9467
9601
  function readCache() {
9468
9602
  try {
@@ -9606,7 +9740,7 @@ var init_update = __esm(() => {
9606
9740
  });
9607
9741
 
9608
9742
  // package.json
9609
- var version = "0.5.16";
9743
+ var version = "0.5.18";
9610
9744
  var init_package = () => {};
9611
9745
 
9612
9746
  // src/version.ts
@@ -11546,6 +11680,7 @@ var init_commands = __esm(() => {
11546
11680
  init_log();
11547
11681
  init_interrupt();
11548
11682
  init_misc();
11683
+ init_ui();
11549
11684
  init_prompt();
11550
11685
  init_load();
11551
11686
  init_commands();
@@ -11574,45 +11709,99 @@ var CATEGORIES = [
11574
11709
  commands: ["doctor", "completion", "update"]
11575
11710
  }
11576
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
+ }
11577
11747
  function renderUsage() {
11748
+ const nameWidth = Math.max(...commands.filter((cmd) => !cmd.hidden).map((cmd) => cmd.name.length)) + 3;
11578
11749
  const renderedCategories = CATEGORIES.map((cat) => {
11579
- 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
+ ]);
11580
11755
  return ` ${c.bold(cat.title)}
11581
- ${lines.join(`
11582
- `)}`;
11756
+ ${columns(rows, c.cyan, 4, nameWidth)}`;
11583
11757
  }).join(`
11584
11758
 
11585
11759
  `);
11586
- 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.")}
11587
11764
 
11588
- ${c.bold("Usage")}
11589
- epd <command> [options]
11765
+ ${heading("Usage")}
11766
+ ${c.gray("$")} epd ${c.cyan("<command>")} ${c.gray("[options]")}
11590
11767
 
11591
- ${c.bold("Commands")}
11768
+ ${heading("Commands")}
11592
11769
  ${renderedCategories}
11593
11770
 
11594
- ${c.bold("Global options")}
11595
- -c, --config <file> Path to epd.yml
11596
- -d, --destination <d> Overlay epd.<d>.yml (staging, production, \u2026)
11597
- -v, --verbose Show every command epd runs
11598
- --log-format <f> pretty (default) or json: one JSON event per line on
11599
- stdout, ending with a "result" event (EPD_LOG_FORMAT)
11600
- -h, --help Show help for a command
11601
- --version Print the epd version
11602
-
11603
- ${c.bold("Examples")}
11604
- epd init Create an epd.yml for this project
11605
- epd doctor Run pre-flight health & config diagnostics
11606
- epd setup Prepare the servers, then deploy
11607
- epd deploy Build and deploy the current commit
11608
- epd deploy --dry-run Simulate deployment plan without making changes
11609
- epd deploy -d staging Deploy with the staging overlay
11610
- epd rollback Go back to the previous version
11611
- epd logs -f Follow logs from every server
11612
- epd docker-command Print the docker run command epd would use
11613
- 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")}`)}
11614
11778
  `;
11615
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
+ }
11616
11805
  async function main(argv) {
11617
11806
  if (argv.includes("--version") && !argv[0]?.startsWith("-")) {}
11618
11807
  const first = argv[0];
@@ -11677,11 +11866,11 @@ Run ${c.cyan("epd --help")} to see the available commands.
11677
11866
  } catch (e) {
11678
11867
  log.error(e instanceof Error ? e.message : String(e));
11679
11868
  console.log(`
11680
- ${command.help()}`);
11869
+ ${styleHelp(command.help())}`);
11681
11870
  return 1;
11682
11871
  }
11683
11872
  if (parsed.values.help) {
11684
- console.log(command.help());
11873
+ console.log(styleHelp(command.help()));
11685
11874
  return 0;
11686
11875
  }
11687
11876
  setVerbose(Boolean(parsed.values.verbose));
@@ -11766,3 +11955,6 @@ try {
11766
11955
  process.exitCode = 1;
11767
11956
  finish(false, 1, error instanceof Error ? error.message : String(error), error instanceof EpdError ? error.hint : undefined);
11768
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.16",
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",