Skip to content

Commit 8d43ad6

Browse files
zbynekthornjad
authored andcommitted
Switch from colors to chalk
1 parent 29208b7 commit 8d43ad6

File tree

3 files changed

+2475
-1710
lines changed

3 files changed

+2475
-1710
lines changed

bin/http-server

+24-24
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'),
@@ -77,21 +77,21 @@ if (!argv.s && !argv.silent) {
7777
if (error) {
7878
logger.info(
7979
'[%s] %s "%s %s" Error (%s): "%s"',
80-
date, ip, colors.red(req.method), colors.red(req.url),
81-
colors.red(error.status.toString()), colors.red(error.message)
80+
date, ip, chalk.red(req.method), chalk.red(req.url),
81+
chalk.red(error.status.toString()), chalk.red(error.message)
8282
);
8383
}
8484
else {
8585
logger.info(
8686
'[%s] %s "%s %s" "%s"',
87-
date, ip, colors.cyan(req.method), colors.cyan(req.url),
87+
date, ip, chalk.cyan(req.method), chalk.cyan(req.url),
8888
req.headers['user-agent']
8989
);
9090
}
9191
}
9292
};
9393
}
94-
else if (colors) {
94+
else if (chalk) {
9595
logger = {
9696
info: function () {},
9797
request: function () {}
@@ -149,14 +149,14 @@ function listen(port) {
149149
fs.lstatSync(options.https.cert);
150150
}
151151
catch (err) {
152-
logger.info(colors.red('Error: Could not find certificate ' + options.https.cert));
152+
logger.info(chalk.red('Error: Could not find certificate ' + options.https.cert));
153153
process.exit(1);
154154
}
155155
try {
156156
fs.lstatSync(options.https.key);
157157
}
158158
catch (err) {
159-
logger.info(colors.red('Error: Could not find private key ' + options.https.key));
159+
logger.info(chalk.red('Error: Could not find private key ' + options.https.key));
160160
process.exit(1);
161161
}
162162
}
@@ -165,31 +165,31 @@ function listen(port) {
165165
server.listen(port, host, function () {
166166
var protocol = ssl ? 'https://' : 'http://';
167167

168-
logger.info([colors.yellow('Starting up http-server, serving '),
169-
colors.cyan(server.root),
170-
ssl ? (colors.yellow(' through') + colors.cyan(' https')) : ''
168+
logger.info([chalk.yellow('Starting up http-server, serving '),
169+
chalk.cyan(server.root),
170+
ssl ? (chalk.yellow(' through') + chalk.cyan(' https')) : ''
171171
].join(''));
172172

173-
logger.info([colors.yellow('\nhttp-server settings: '),
174-
([colors.yellow('CORS: '), argv.cors ? colors.cyan(argv.cors) : colors.red('disabled')].join('')),
175-
([colors.yellow('Cache: '), argv.c ? (argv.c === '-1' ? colors.red('disabled') : colors.cyan(argv.c + ' seconds')) : colors.cyan('3600 seconds')].join('')),
176-
([colors.yellow('Connection Timeout: '), argv.t === '0' ? colors.red('disabled') : (argv.t ? colors.cyan(argv.t + ' seconds') : colors.cyan('120 seconds'))].join('')),
177-
([colors.yellow('Directory Listings: '), argv.d ? colors.red('not visible') : colors.cyan('visible')].join('')),
178-
([colors.yellow('AutoIndex: '), argv.i ? colors.red('not visible') : colors.cyan('visible')].join('')),
179-
([colors.yellow('Serve GZIP Files: '), argv.g || argv.gzip ? colors.cyan('true') : colors.red('false')].join('')),
180-
([colors.yellow('Serve Brotli Files: '), argv.b || argv.brotli ? colors.cyan('true') : colors.red('false')].join('')),
181-
([colors.yellow('Default File Extension: '), argv.e ? colors.cyan(argv.e) : (argv.ext ? colors.cyan(argv.ext) : colors.red('none'))].join(''))
173+
logger.info([chalk.yellow('\nhttp-server settings: '),
174+
([chalk.yellow('CORS: '), argv.cors ? chalk.cyan(argv.cors) : chalk.red('disabled')].join('')),
175+
([chalk.yellow('Cache: '), argv.c ? (argv.c === '-1' ? chalk.red('disabled') : chalk.cyan(argv.c + ' seconds')) : chalk.cyan('3600 seconds')].join('')),
176+
([chalk.yellow('Connection Timeout: '), argv.t === '0' ? chalk.red('disabled') : (argv.t ? chalk.cyan(argv.t + ' seconds') : chalk.cyan('120 seconds'))].join('')),
177+
([chalk.yellow('Directory Listings: '), argv.d ? chalk.red('not visible') : chalk.cyan('visible')].join('')),
178+
([chalk.yellow('AutoIndex: '), argv.i ? chalk.red('not visible') : chalk.cyan('visible')].join('')),
179+
([chalk.yellow('Serve GZIP Files: '), argv.g || argv.gzip ? chalk.cyan('true') : chalk.red('false')].join('')),
180+
([chalk.yellow('Serve Brotli Files: '), argv.b || argv.brotli ? chalk.cyan('true') : chalk.red('false')].join('')),
181+
([chalk.yellow('Default File Extension: '), argv.e ? chalk.cyan(argv.e) : (argv.ext ? chalk.cyan(argv.ext) : chalk.red('none'))].join(''))
182182
].join('\n'));
183183

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

186186
if (argv.a && host !== '0.0.0.0') {
187-
logger.info(` ${protocol}${host}:${colors.green(port.toString())}`);
187+
logger.info(` ${protocol}${host}:${chalk.green(port.toString())}`);
188188
} else {
189189
Object.keys(ifaces).forEach(function (dev) {
190190
ifaces[dev].forEach(function (details) {
191191
if (details.family === 'IPv4') {
192-
logger.info((' ' + protocol + details.address + ':' + colors.green(port.toString())));
192+
logger.info((' ' + protocol + details.address + ':' + chalk.green(port.toString())));
193193
}
194194
});
195195
});
@@ -225,11 +225,11 @@ if (process.platform === 'win32') {
225225
}
226226

227227
process.on('SIGINT', function () {
228-
logger.info(colors.red('http-server stopped.'));
228+
logger.info(chalk.red('http-server stopped.'));
229229
process.exit();
230230
});
231231

232232
process.on('SIGTERM', function () {
233-
logger.info(colors.red('http-server stopped.'));
233+
logger.info(chalk.red('http-server stopped.'));
234234
process.exit();
235235
});

0 commit comments

Comments
 (0)