Skip to content

Commit

Permalink
Switch emojis to log-symbols for terminal compatibility (#363)
Browse files Browse the repository at this point in the history
* Don't show emoji on windows.

* Use log-symbols

* Emoji with fallback for windows
  • Loading branch information
shawwn authored and devongovett committed Dec 25, 2017
1 parent ec89fab commit 0eb4487
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Logger = require('./Logger');
const PackagerRegistry = require('./packagers');
const localRequire = require('./utils/localRequire');
const config = require('./utils/config');
const emoji = require('./utils/emoji');

/**
* The Bundler is the main entry point. It resolves and loads assets,
Expand Down Expand Up @@ -122,7 +123,7 @@ class Bundler extends EventEmitter {
this.errored = false;

this.logger.clear();
this.logger.status('⏳', 'Building...');
this.logger.status(emoji.progress, 'Building...');

try {
// Start worker farm, watcher, etc. if needed
Expand All @@ -144,7 +145,7 @@ class Bundler extends EventEmitter {
buildTime < 1000
? `${buildTime}ms`
: `${(buildTime / 1000).toFixed(2)}s`;
this.logger.status('✨', `Built in ${time}.`, 'green');
this.logger.status(emoji.success, `Built in ${time}.`, 'green');

return bundle;
} catch (err) {
Expand Down Expand Up @@ -304,7 +305,7 @@ class Bundler extends EventEmitter {
}

if (!this.errored) {
this.logger.status('⏳', `Building ${asset.basename}...`);
this.logger.status(emoji.progress, `Building ${asset.basename}...`);
}

// Mark the asset processed so we don't load it twice
Expand Down Expand Up @@ -461,7 +462,7 @@ class Bundler extends EventEmitter {
}

this.logger.clear();
this.logger.status('⏳', `Building ${asset.basename}...`);
this.logger.status(emoji.progress, `Building ${asset.basename}...`);

// Add the asset to the rebuild queue, and reset the timeout.
this.buildQueue.add(asset);
Expand Down
3 changes: 2 additions & 1 deletion src/Logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const chalk = require('chalk');
const readline = require('readline');
const prettyError = require('./utils/prettyError');
const emoji = require('./utils/emoji');

class Logger {
constructor(options) {
Expand Down Expand Up @@ -51,7 +52,7 @@ class Logger {

let {message, stack} = prettyError(err, {color: this.color});

this.status('🚨', message, 'red');
this.status(emoji.error, message, 'red');
if (stack) {
this.write(stack);
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/emoji.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const supportsEmoji = process.platform !== 'win32' || process.env.VSCODE_PID;

// Fallback symbols for Windows from https://en.wikipedia.org/wiki/Code_page_437
exports.progress = supportsEmoji ? '⏳' : '∞';
exports.success = supportsEmoji ? '✨' : '√';
exports.error = supportsEmoji ? '🚨' : '×';

0 comments on commit 0eb4487

Please sign in to comment.