From eafc25eefa4b23b97d4cb5da50dcbd9884f99946 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Sat, 30 Jul 2016 18:10:16 -0700 Subject: [PATCH 1/2] shorten path for better UX --- bin/now-deploy | 3 ++- lib/utils/to-human-path.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 lib/utils/to-human-path.js diff --git a/bin/now-deploy b/bin/now-deploy index 019a22a..86aa9f4 100755 --- a/bin/now-deploy +++ b/bin/now-deploy @@ -10,6 +10,7 @@ import bytes from 'bytes'; import chalk from 'chalk'; import minimist from 'minimist'; import Now from '../lib'; +import toHumanPath from '../lib/utils/to-human-path'; import ms from 'ms'; import { handleError, error } from '../lib/error'; @@ -138,7 +139,7 @@ async function sync (token) { const start = Date.now(); if (!quiet) { - console.log(`> Deploying "${path}"`); + console.log(`> Deploying ${chalk.bold(toHumanPath(path))}`); } const now = new Now(apiUrl, token, { debug }); diff --git a/lib/utils/to-human-path.js b/lib/utils/to-human-path.js new file mode 100644 index 0000000..a8533c9 --- /dev/null +++ b/lib/utils/to-human-path.js @@ -0,0 +1,14 @@ +import { resolve } from 'path'; + +// cleaned-up `$HOME` (i.e.: no trailing slash) +const HOME = resolve(process.env.HOME); + +/** + * Attempts to show the given path in + * a human-friendly form. For example, + * `/Users/rauchg/test.js` becomes `~/test.js` + */ + +export default function toHumanPath (path) { + return path.replace(HOME, '~'); +} From 5791b496538d726807490a738e4c397f8080e62c Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Sat, 30 Jul 2016 18:57:01 -0700 Subject: [PATCH 2/2] error: prevent ansi escapes for colors in stdout --- lib/error.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/error.js b/lib/error.js index acaab62..52d5777 100644 --- a/lib/error.js +++ b/lib/error.js @@ -1,4 +1,5 @@ import ms from 'ms'; +import chalk from 'chalk'; export function handleError (err) { if (403 === err.status) { @@ -21,5 +22,5 @@ export function handleError (err) { } export function error (err) { - console.error(`> \u001b[31mError!\u001b[39m ${err}`); + console.error(`> ${chalk.red('Error!')} ${err}`); }