Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utilities/cli): use chalk-template to render help message #713

Merged
merged 1 commit into from Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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