sitevision-cli 0.3.1-beta.1 → 0.3.1-beta.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.
Files changed (2) hide show
  1. package/dist/cli.js +30 -2
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -53,9 +53,37 @@ const cli = meow(`
53
53
  },
54
54
  });
55
55
  const [commandName, ...args] = cli.input;
56
+ const CYAN = '\x1b[36m';
57
+ const BOLD = '\x1b[1m';
58
+ const DIM = '\x1b[2m';
59
+ const RESET = '\x1b[0m';
60
+ // Visible column width of a string: astral code points (emoji) take 2 columns,
61
+ // everything else 1. ANSI escapes are never passed in here.
62
+ function displayWidth(text) {
63
+ let width = 0;
64
+ for (const char of text) {
65
+ width += (char.codePointAt(0) ?? 0) > 0xffff ? 2 : 1;
66
+ }
67
+ return width;
68
+ }
69
+ // Print a boxed masthead. Borders are sized from the content's display width so
70
+ // they stay aligned regardless of how long the version string is.
71
+ function printMasthead(version) {
72
+ const left = '📦 Sitevision CLI';
73
+ const right = `v${version}`;
74
+ const padding = 2; // spaces inside each vertical border
75
+ const gap = 7; // spaces between the title and the version
76
+ const inner = padding + displayWidth(left) + gap + displayWidth(right) + padding;
77
+ const border = '─'.repeat(inner);
78
+ const spaces = (n) => ' '.repeat(n);
79
+ console.log(`${CYAN}╭${border}╮${RESET}`);
80
+ console.log(`${CYAN}│${RESET}${spaces(padding)}${BOLD}${CYAN}${left}${RESET}` +
81
+ `${spaces(gap)}${DIM}${right}${RESET}${spaces(padding)}${CYAN}│${RESET}`);
82
+ console.log(`${CYAN}╰${border}╯${RESET}`);
83
+ }
56
84
  async function main() {
57
- // Show the CLI version on startup, and check npm for a newer release.
58
- console.log(`\x1b[36msvc v${pkg.version}\x1b[0m`);
85
+ // Show the masthead on startup, and check npm for a newer release.
86
+ printMasthead(pkg.version);
59
87
  const latestVersion = await checkForUpdate(pkg.name, pkg.version);
60
88
  if (latestVersion) {
61
89
  console.log(`\x1b[33m ↑ update available: ${pkg.version} → ${latestVersion} (run: npm i -g ${pkg.name})\x1b[0m`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sitevision-cli",
3
- "version": "0.3.1-beta.1",
3
+ "version": "0.3.1-beta.2",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "svc": "dist/cli.js"