Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-contrib-compress

Package Overview
Dependencies
Maintainers
3
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-contrib-compress - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

.gitattributes

23

Gruntfile.js

@@ -41,3 +41,3 @@ /*

compress: {
mainZip: {
zip: {
options: {

@@ -47,6 +47,6 @@ archive: 'tmp/compress_test_files.zip'

files: [
{expand: true, cwd: 'test/fixtures', src: ['*']}
{expand: true, cwd: 'test/fixtures/', src: ['**/*']}
]
},
mainTar: {
tar: {
options: {

@@ -56,6 +56,6 @@ archive: 'tmp/compress_test_files.tar'

files: [
{expand: true, cwd: 'test/fixtures', src: ['*']}
{expand: true, cwd: 'test/fixtures', src: ['**/*']}
]
},
mainTarGz: {
tgz: {
options: {

@@ -65,10 +65,13 @@ archive: 'tmp/compress_test_files.tgz'

files: [
{expand: true, cwd: 'test/fixtures', src: ['*']}
{expand: true, cwd: 'test/fixtures', src: ['**/*']}
]
},
mainGz: {
gzip: {
expand: true,
cwd: 'test/fixtures/',
src: ['**/*.{css,html,js}'],
dest: 'tmp/gzip/',
options: {
archive: 'tmp/compress_test_file.js.gz'
},
src: ['test/fixtures/test.js']
mode: 'gzip'
}
}

@@ -75,0 +78,0 @@ },

{
"name": "grunt-contrib-compress",
"description": "Compress files and folders.",
"version": "0.4.1",
"version": "0.4.2",
"homepage": "https://github.com/gruntjs/grunt-contrib-compress",

@@ -32,8 +32,6 @@ "author": {

"archiver": "~0.3.0",
"rimraf": "~2.0.2",
"grunt-lib-contrib": "~0.5.1",
"prettysize": "~0.0.2"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-jshint": "~0.2.0",
"grunt-contrib-nodeunit": "~0.1.2",

@@ -40,0 +38,0 @@ "grunt-contrib-clean": "~0.4.0",

@@ -82,2 +82,3 @@ # grunt-contrib-compress [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-compress.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-compress)

* 2013-03-12   v0.4.2   Refactor task like other contrib tasks. Fix gzip of multiple files. Remove unused dependencies.
* 2013-02-21   v0.4.1   Pretty print compressed sizes. Logging each addition to a compressed file now only happens in verbose mode.

@@ -97,2 +98,2 @@ * 2013-02-14   v0.4.0   First official release for Grunt 0.4.0.

*This file was generated on Fri Feb 22 2013 09:14:59.*
*This file was generated on Wed Mar 13 2013 12:00:33.*

@@ -5,3 +5,3 @@ /*

*
* Copyright (c) 2012 Chris Talkington, contributors
* Copyright (c) 2013 Chris Talkington, contributors
* Licensed under the MIT license.

@@ -13,171 +13,24 @@ */

module.exports = function(grunt) {
var fs = require('fs');
var path = require('path');
var rimraf = require('rimraf');
var prettySize = require('prettysize');
var compress = require('./lib/compress')(grunt);
grunt.registerMultiTask('compress', 'Compress files.', function() {
var archiver = require('archiver');
var zlib = require('zlib');
var kindOf = grunt.util.kindOf;
var helpers = require('grunt-lib-contrib').init(grunt);
var done = this.async();
var options = this.options({
compress.options = this.options({
archive: null,
mode: null,
level: 1
level: 1,
});
var pretty = function(size) {
if (!options.pretty) {
return size + ' bytes';
}
return prettySize(size);
};
compress.options.mode = compress.options.mode || compress.autoDetectMode(compress.options.archive);
grunt.verbose.writeflags(compress.options, 'Options');
var archiverOptions = options;
var supportedModes = ['zip', 'tar', 'tgz', 'gzip'];
var shouldGzipTar = false;
grunt.verbose.writeflags(options, 'Options');
if (kindOf(options.archive) !== 'string' || options.archive.length === 0) {
grunt.fail.warn('Unable to compress; no valid archive file was specified.');
if (grunt.util._.include(['zip', 'tar', 'tgz', 'gzip'], compress.options.mode) === false) {
grunt.fail.warn('Mode ' + String(compress.options.mode).cyan + ' not supported.');
}
var archiveFile = options.archive;
var archiveDir = path.dirname(archiveFile);
var mode = options.mode || autoDetectMode(archiveFile);
if (mode === 'tgz') {
shouldGzipTar = true;
mode = 'tar';
if (compress.options.mode === 'gzip') {
compress.gzip(this.files, this.async());
} else {
compress.tar(this.files, this.async());
}
if (grunt.util._.include(supportedModes, mode) === false) {
grunt.fail.warn('Mode ' + mode.cyan + ' not supported.');
}
if (this.filesSrc.length === 0) {
grunt.fail.warn('Unable to compress; no valid source files were found.');
}
if (grunt.file.exists(archiveDir) === false) {
grunt.file.mkdir(archiveDir);
}
var archiveStream = fs.createWriteStream(archiveFile);
var internalFileName;
var srcFile;
var filePairSrc;
var isExpandedPair;
var archive;
if (mode === 'gzip') {
// this needs to be evaluated as it doesn't fit new flow
var srcFiles = this.filesSrc;
srcFiles = srcFiles.filter(function(src) {
return grunt.file.isFile(src);
});
if (srcFiles.length > 1) {
grunt.fail.warn('Cannot specify multiple input files for gzip compression.');
}
var srcStream = fs.createReadStream(srcFiles[0]);
srcStream.pipe(zlib.createGzip()).pipe(archiveStream);
archiveStream.on('close', function() {
grunt.log.writeln('File ' + archiveFile.cyan + ' created (' + pretty(getSize(archiveFile)) + ').');
done();
});
} else if (mode === 'tar' || mode === 'zip') {
archive = archiver.create(mode, archiverOptions);
if (shouldGzipTar) {
archive.pipe(zlib.createGzip()).pipe(archiveStream);
} else {
archive.pipe(archiveStream);
}
archive.on('error', function(err) {
grunt.log.error(err);
grunt.fail.warn('archiver failed');
});
grunt.util.async.forEachSeries(this.files, function(filePair, nextPair) {
isExpandedPair = filePair.orig.expand || false;
filePairSrc = filePair.src;
filePairSrc = filePairSrc.filter(function(src) {
return grunt.file.isFile(src);
});
grunt.util.async.forEachSeries(filePairSrc, function(srcFile, nextFile) {
internalFileName = (isExpandedPair) ? filePair.dest : unixifyPath(path.join(filePair.dest || '', srcFile));
archive.addFile(fs.createReadStream(srcFile), { name: internalFileName }, function(err) {
grunt.verbose.writeln('Archiving ' + srcFile.cyan + ' -> ' + archiveFile.cyan + '/'.cyan + internalFileName.cyan);
nextFile(err);
});
}, nextPair);
}, function(err) {
if (err) {
grunt.fail.warn(err);
}
archive.finalize(function(err, written) {
if (shouldGzipTar) {
grunt.log.writeln('Created ' + archiveFile.cyan + ' (' + pretty(getSize(archiveFile)) + ')');
} else {
grunt.log.writeln('Created ' + archiveFile.cyan + ' (' + pretty(written) + ')');
}
done(err);
});
});
}
});
var getSize = function(filename) {
try {
return fs.statSync(filename).size;
} catch (e) {
return 0;
}
};
var autoDetectMode = function(dest) {
if (grunt.util._.endsWith(dest, '.tar.gz')) {
return 'tgz';
}
var ext = path.extname(dest).replace('.', '');
if (ext === 'gz') {
return 'gzip';
} else {
return ext;
}
};
var unixifyPath = function(filepath) {
if (process.platform === 'win32') {
return filepath.replace(/\\/g, '/');
} else {
return filepath;
}
};
};

@@ -0,42 +1,47 @@

'use strict';
var grunt = require('grunt');
var fs = require('fs');
var path = require('path');
var compress = require('../tasks/lib/compress')(grunt);
var getSize = function(filename) {
'use strict';
try {
return fs.statSync(filename).size;
} catch (e) {
return 0;
}
};
exports.compress = {
main: function(test) {
'use strict';
zip: function(test) {
test.expect(1);
test.expect(4);
var actual = compress.getSize('tmp/compress_test_files.zip', false);
var expected = compress.getSize('test/expected/compress_test_files.zip', false);
test.equal(actual, expected, 'should compress files into zip');
// Zip
var actual = getSize('tmp/compress_test_files.zip');
var expected = getSize('test/expected/compress_test_files.zip');
test.equal(expected, actual, 'should compress files into zip');
test.done();
},
tar: function(test) {
test.expect(1);
// Tar
actual = getSize('tmp/compress_test_files.tar');
expected = getSize('test/expected/compress_test_files.tar');
test.equal(expected, actual, 'should add files into tar');
var actual = compress.getSize('tmp/compress_test_files.tar', false);
var expected = compress.getSize('test/expected/compress_test_files.tar', false);
test.equal(actual, expected, 'should compress files into tar');
// Tar (gzip)
actual = getSize('tmp/compress_test_files.tgz') >= 195;
expected = true;
test.equal(expected, actual, 'should add files into tar. compressing the tar with gzip.');
test.done();
},
tgz: function(test) {
test.expect(1);
// gzip
actual = getSize('tmp/compress_test_file.js.gz');
expected = getSize('test/expected/compress_test_file.js.gz');
test.equal(expected, actual, 'should gzip file');
var actual = compress.getSize('tmp/compress_test_files.tgz', false) >= 300;
test.equal(actual, true, 'should add files into tar. compressing the tar with gzip.');
test.done();
},
gzip: function(test) {
test.expect(3);
[
'test.js.gz',
path.join('folder_one', 'one.css.gz'),
path.join('folder_two', 'two.js.gz'),
].forEach(function(file) {
var actual = compress.getSize(path.join('tmp', 'gzip', file), false);
var expected = compress.getSize(path.join('test', 'expected', 'gzip', file), false);
test.equal(actual, expected, 'should have been the same file size as the expected file.');
});
test.done();
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc