Skip to content

Commit 685f3c8

Browse files
committed
Switch from colors to chalk
1 parent 72b6b07 commit 685f3c8

File tree

3 files changed

+162
-56
lines changed

3 files changed

+162
-56
lines changed

bin/http-server

+26-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
'use strict';
44

5-
var colors = require('colors/safe'),
5+
var chalk = require('chalk'),
66
os = require('os'),
77
httpServer = require('../lib/http-server'),
88
portfinder = require('portfinder'),
@@ -99,21 +99,21 @@ if (!argv.s && !argv.silent) {
9999
if (error) {
100100
logger.info(
101101
'[%s] %s "%s %s" Error (%s): "%s"',
102-
date, ip, colors.red(req.method), colors.red(req.url),
103-
colors.red(error.status.toString()), colors.red(error.message)
102+
date, ip, chalk.red(req.method), chalk.red(req.url),
103+
chalk.red(error.status.toString()), chalk.red(error.message)
104104
);
105105
}
106106
else {
107107
logger.info(
108108
'[%s] %s "%s %s" "%s"',
109-
date, ip, colors.cyan(req.method), colors.cyan(req.url),
109+
date, ip, chalk.cyan(req.method), chalk.cyan(req.url),
110110
req.headers['user-agent']
111111
);
112112
}
113113
}
114114
};
115115
}
116-
else if (colors) {
116+
else if (chalk) {
117117
logger = {
118118
info: function () {},
119119
request: function () {}
@@ -168,7 +168,7 @@ function listen(port) {
168168
new url.URL(proxy)
169169
}
170170
catch (err) {
171-
logger.info(colors.red('Error: Invalid proxy url'));
171+
logger.info(chalk.red('Error: Invalid proxy url'));
172172
process.exit(1);
173173
}
174174
}
@@ -183,14 +183,14 @@ function listen(port) {
183183
fs.lstatSync(options.https.cert);
184184
}
185185
catch (err) {
186-
logger.info(colors.red('Error: Could not find certificate ' + options.https.cert));
186+
logger.info(chalk.red('Error: Could not find certificate ' + options.https.cert));
187187
process.exit(1);
188188
}
189189
try {
190190
fs.lstatSync(options.https.key);
191191
}
192192
catch (err) {
193-
logger.info(colors.red('Error: Could not find private key ' + options.https.key));
193+
logger.info(chalk.red('Error: Could not find private key ' + options.https.key));
194194
process.exit(1);
195195
}
196196
}
@@ -200,34 +200,34 @@ function listen(port) {
200200
var protocol = tls ? 'https://' : 'http://';
201201

202202
logger.info([
203-
colors.yellow('Starting up http-server, serving '),
204-
colors.cyan(server.root),
205-
tls ? (colors.yellow(' through') + colors.cyan(' https')) : ''
203+
chalk.yellow('Starting up http-server, serving '),
204+
chalk.cyan(server.root),
205+
tls ? (chalk.yellow(' through') + chalk.cyan(' https')) : ''
206206
].join(''));
207207

208-
logger.info([colors.yellow('\nhttp-server version: '), colors.cyan(require('../package.json').version)].join(''));
208+
logger.info([chalk.yellow('\nhttp-server version: '), chalk.cyan(require('../package.json').version)].join(''));
209209

210210
logger.info([
211-
colors.yellow('\nhttp-server settings: '),
212-
([colors.yellow('CORS: '), argv.cors ? colors.cyan(argv.cors) : colors.red('disabled')].join('')),
213-
([colors.yellow('Cache: '), argv.c ? (argv.c === '-1' ? colors.red('disabled') : colors.cyan(argv.c + ' seconds')) : colors.cyan('3600 seconds')].join('')),
214-
([colors.yellow('Connection Timeout: '), argv.t === '0' ? colors.red('disabled') : (argv.t ? colors.cyan(argv.t + ' seconds') : colors.cyan('120 seconds'))].join('')),
215-
([colors.yellow('Directory Listings: '), argv.d ? colors.red('not visible') : colors.cyan('visible')].join('')),
216-
([colors.yellow('AutoIndex: '), argv.i ? colors.red('not visible') : colors.cyan('visible')].join('')),
217-
([colors.yellow('Serve GZIP Files: '), argv.g || argv.gzip ? colors.cyan('true') : colors.red('false')].join('')),
218-
([colors.yellow('Serve Brotli Files: '), argv.b || argv.brotli ? colors.cyan('true') : colors.red('false')].join('')),
219-
([colors.yellow('Default File Extension: '), argv.e ? colors.cyan(argv.e) : (argv.ext ? colors.cyan(argv.ext) : colors.red('none'))].join(''))
211+
chalk.yellow('\nhttp-server settings: '),
212+
([chalk.yellow('CORS: '), argv.cors ? chalk.cyan(argv.cors) : chalk.red('disabled')].join('')),
213+
([chalk.yellow('Cache: '), argv.c ? (argv.c === '-1' ? chalk.red('disabled') : chalk.cyan(argv.c + ' seconds')) : chalk.cyan('3600 seconds')].join('')),
214+
([chalk.yellow('Connection Timeout: '), argv.t === '0' ? chalk.red('disabled') : (argv.t ? chalk.cyan(argv.t + ' seconds') : chalk.cyan('120 seconds'))].join('')),
215+
([chalk.yellow('Directory Listings: '), argv.d ? chalk.red('not visible') : chalk.cyan('visible')].join('')),
216+
([chalk.yellow('AutoIndex: '), argv.i ? chalk.red('not visible') : chalk.cyan('visible')].join('')),
217+
([chalk.yellow('Serve GZIP Files: '), argv.g || argv.gzip ? chalk.cyan('true') : chalk.red('false')].join('')),
218+
([chalk.yellow('Serve Brotli Files: '), argv.b || argv.brotli ? chalk.cyan('true') : chalk.red('false')].join('')),
219+
([chalk.yellow('Default File Extension: '), argv.e ? chalk.cyan(argv.e) : (argv.ext ? chalk.cyan(argv.ext) : chalk.red('none'))].join(''))
220220
].join('\n'));
221221

222-
logger.info(colors.yellow('\nAvailable on:'));
222+
logger.info(chalk.yellow('\nAvailable on:'));
223223

224224
if (argv.a && host !== '0.0.0.0') {
225-
logger.info(` ${protocol}${host}:${colors.green(port.toString())}`);
225+
logger.info(` ${protocol}${host}:${chalk.green(port.toString())}`);
226226
} else {
227227
Object.keys(ifaces).forEach(function (dev) {
228228
ifaces[dev].forEach(function (details) {
229229
if (details.family === 'IPv4') {
230-
logger.info((' ' + protocol + details.address + ':' + colors.green(port.toString())));
230+
logger.info((' ' + protocol + details.address + ':' + chalk.green(port.toString())));
231231
}
232232
});
233233
});
@@ -268,11 +268,11 @@ if (process.platform === 'win32') {
268268
}
269269

270270
process.on('SIGINT', function () {
271-
logger.info(colors.red('http-server stopped.'));
271+
logger.info(chalk.red('http-server stopped.'));
272272
process.exit();
273273
});
274274

275275
process.on('SIGTERM', function () {
276-
logger.info(colors.red('http-server stopped.'));
276+
logger.info(chalk.red('http-server stopped.'));
277277
process.exit();
278278
});

package-lock.json

+135-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)