Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make iltorb an optional dependency. #191

Merged
merged 1 commit into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
"dependencies": {
"archiver": "^1.0.0",
"chalk": "^1.1.1",
"iltorb": "^1.0.13",
"lodash": "^4.7.0",
"pretty-bytes": "^3.0.1",
"stream-buffers": "^2.1.0"
},
"optionalDependencies": {
"iltorb": "^1.0.13"
},
"devDependencies": {
"grunt": "^1.0.0",
"grunt-contrib-clean": "^1.0.0",
Expand Down
14 changes: 13 additions & 1 deletion tasks/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
module.exports = function(grunt) {
var _ = require('lodash');
var compress = require('./lib/compress')(grunt);
var iltorb;

try {
iltorb = require('iltorb');
} catch (er) {
iltorb = null;
}

grunt.registerMultiTask('compress', 'Compress files.', function() {
compress.options = this.options({
Expand All @@ -25,8 +32,13 @@ module.exports = function(grunt) {

compress.options.mode = compress.options.mode || compress.autoDetectMode(compress.options.archive);

if (compress.options.mode.match('brotli') && !iltorb) {
grunt.fail.fatal('iltorb dependency wasn\'t found; in order to use brotli, ' +
'make sure you have a supported C++ compiler available and run `npm install` again.');
}

if (_.includes(['zip', 'tar', 'tgz', 'gzip', 'deflate', 'deflateRaw', 'brotli'], compress.options.mode) === false) {
grunt.fail.warn('Mode ' + String(compress.options.mode).cyan + ' not supported.');
grunt.fail.warn('Mode ' + String(compress.options.mode) + ' not supported.');
}

if (/gzip|brotli/.test(compress.options.mode) || compress.options.mode.slice(0, 7) === 'deflate') {
Expand Down
17 changes: 15 additions & 2 deletions tasks/lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ var zlib = require('zlib');
var archiver = require('archiver');
var streamBuffers = require('stream-buffers');
var _ = require('lodash');
var iltorb = require('iltorb');

var iltorb;

try {
iltorb = require('iltorb');
} catch (er) {
iltorb = null;
}

module.exports = function(grunt) {

Expand Down Expand Up @@ -104,7 +111,13 @@ module.exports = function(grunt) {
initDestStream();
}

var compressor = extension === 'br' ? algorithm.call(iltorb, exports.options.brotli) : algorithm.call(zlib, exports.options);
var compressor;

if (iltorb && extension === 'br') {
compressor = algorithm.call(iltorb, exports.options.brotli);
} else {
compressor = algorithm.call(zlib, exports.options);
}

compressor.on('error', function(err) {
grunt.log.error(err);
Expand Down