Skip to content

Commit

Permalink
fix(utilities/cli): use chalk-template to render help message (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
gamemaker1 committed Jul 13, 2022
1 parent 995247d commit 3fbca73
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -38,6 +38,7 @@
"arg": "5.0.2",
"boxen": "7.0.0",
"chalk": "5.0.1",
"chalk-template": "0.4.0",
"clipboardy": "3.0.0",
"compression": "1.7.4",
"is-port-reachable": "4.0.0",
Expand Down
18 changes: 12 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions source/main.ts
Expand Up @@ -28,15 +28,16 @@ const printUpdateNotification = async (debugMode?: boolean) => {
const [error, update] = await resolve(checkForUpdate(manifest));

if (error) {
const suffix = debugMode ? ':' : ' (use `--debug` to see full error)';
const suffix = debugMode ? ':' : ' (use `--debug` to see full error).';
logger.warn(`Checking for updates failed${suffix}`);

if (debugMode) logger.error(error.message);
}
if (!update) return;

logger.log(
chalk` {bgRed.white UPDATE } The latest version of \`serve\` is ${update.latest}`,
chalk.bgRed.white(' UPDATE '),
`The latest version of \`serve\` is ${update.latest}.`,
);
};

Expand Down Expand Up @@ -115,7 +116,7 @@ for (const endpoint of args['--listen']) {
// If we are not in a TTY or Node is running in production mode, print
// a single line of text with the server address.
if (!process.stdout.isTTY || process.env.NODE_ENV === 'production') {
const suffix = local ? ` at ${local}` : '';
const suffix = local ? ` at ${local}.` : '.';
logger.info(`Accepting connections${suffix}`);

continue;
Expand Down Expand Up @@ -144,7 +145,9 @@ for (const endpoint of args['--listen']) {
await clipboard.write(local);
message += `\n\n${chalk.grey('Copied local address to clipboard!')}`;
} catch (error: unknown) {
logger.error(`Cannot copy to clipboard: ${(error as Error).message}`);
logger.error(
`Cannot copy server address to clipboard: ${(error as Error).message}.`,
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/utilities/cli.ts
@@ -1,7 +1,7 @@
// source/utilities/cli.ts
// CLI-related utility functions.

import chalk from 'chalk';
import chalk from 'chalk-template';
import parseArgv from 'arg';
import { parseEndpoint } from './http.js';
import type { Arguments } from '../types.js';
Expand Down

0 comments on commit 3fbca73

Please sign in to comment.