Skip to content

Commit

Permalink
feat: warn out when failing to get url on cli
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
remy committed Aug 29, 2015
1 parent 8af810f commit c66d95d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 4 additions & 0 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 0 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions lib/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit c66d95d

Please sign in to comment.