feat: warn out when failing to get url on cli

Also cleaned up js uglify process as it was failing the test source.body when in fact there was a body, it was just empty.
This commit is contained in:
Remy Sharp 2015-08-29 15:02:34 +01:00
parent 8af810faa7
commit c66d95deda
4 changed files with 12 additions and 9 deletions

View File

@ -53,6 +53,10 @@ function main() {
pkg: defaults(pkg, { version: '0.0.0' }),
}).notify();
inliner.on('warning', function progress(event) {
console.warn('warning: ' + event);
});
if (argv.verbose) {
inliner.on('progress', function progress(event) {
console.error(event);

View File

@ -7,6 +7,7 @@ var mime = require('mime');
var cache = {};
module.exports = function get(url, options) {
var inliner = this;
if (url.indexOf('data:') === 0) {
debug('asset already inline', url);
return Promise.resolve({
@ -61,6 +62,7 @@ module.exports = function get(url, options) {
debug('response: %s %s', res.statusCode, url);
if (res.statusCode !== 200) {
body = '';
inliner.emit('warning', res.statusCode + ' on ' + url);
}
resolve({

View File

@ -146,10 +146,6 @@ function main() {
var cheerioLoadOptions = {};
var enc = inliner.options.encoding;
if (res.statusCode !== 200) {
inliner.emit('progress', res.statusCode + ' on ' + url);
}
// try to determine the encoding from the headers and the body
if (!enc) {
enc = charset(res.headers, res.body);

View File

@ -6,16 +6,17 @@ var UglifyJS = require('uglify-js');
function uglify(source) {
this.emit('progress', 'compressing javascript');
if (source.body === '') {
return '';
}
if (source.body) {
if (source.body !== undefined) {
source = source.body;
}
// in case of local buffer
source = source.toString();
if (source.trim() === '') {
return '';
}
debug('uglifying %sbytes', source.length);
return UglifyJS.minify(source, {