grunt-contrib-compress
Advanced tools
Comparing version 0.2.1 to 0.2.2
89
grunt.js
@@ -45,2 +45,3 @@ /* | ||
}, | ||
files: { | ||
@@ -52,81 +53,28 @@ compress_test: 'test/fixtures/folder_one' | ||
compress: { | ||
zip: { | ||
options: { | ||
mode: 'zip' | ||
}, | ||
main: { | ||
files: { | ||
'tmp/compress_test_files.zip': ['test/fixtures/*'], | ||
'tmp/compress_test_v<%= test_vars.version %>.zip': ['test/fixtures/**'], | ||
'tmp/compress_test_files_template.zip': ['<%= files.compress_test %>/**'] | ||
} | ||
}, | ||
'tmp/compress_test_files_template.zip': ['<%= files.compress_test %>/**'], | ||
zip_flatten: { | ||
options: { | ||
mode: 'zip', | ||
flatten: true | ||
}, | ||
files: { | ||
'tmp/compress_test_flatten.zip': ['test/fixtures/**'] | ||
} | ||
}, | ||
zip_rootdir: { | ||
options: { | ||
mode: 'zip', | ||
rootDir: 'abc123' | ||
}, | ||
files: { | ||
'tmp/compress_test_rootdir.zip': ['test/fixtures/**'] | ||
} | ||
}, | ||
tar: { | ||
options: { | ||
mode: 'tar' | ||
}, | ||
files: { | ||
'tmp/compress_test_files.tar': ['test/fixtures/*'], | ||
'tmp/compress_test_v<%= test_vars.version %>.tar': ['test/fixtures/**'], | ||
'tmp/compress_test_files_template.tar': ['<%= files.compress_test %>/**'] | ||
} | ||
}, | ||
'tmp/compress_test_files_template.tar': ['<%= files.compress_test %>/**'], | ||
tar_flatten: { | ||
options: { | ||
mode: 'tar', | ||
flatten: true | ||
}, | ||
files: { | ||
'tmp/compress_test_flatten.tar': ['test/fixtures/**'] | ||
} | ||
}, | ||
tar_rootdir: { | ||
options: { | ||
mode: 'tar', | ||
rootDir: 'abc123' | ||
}, | ||
files: { | ||
'tmp/compress_test_rootdir.tar': ['test/fixtures/**'] | ||
} | ||
}, | ||
tgz: { | ||
options: { | ||
mode: 'tgz' | ||
}, | ||
files: { | ||
'tmp/compress_test_files.tgz': ['test/fixtures/*'], | ||
'tmp/compress_test_v<%= test_vars.version %>.tgz': ['test/fixtures/**'], | ||
'tmp/compress_test_files_template.tgz': ['<%= files.compress_test %>/**'] | ||
'tmp/compress_test_files_template.tgz': ['<%= files.compress_test %>/**'], | ||
'tmp/compress_test_file.gz': ['test/fixtures/test.js'], | ||
'tmp/compress_test_file2.gz': ['test/fixtures/folder_one/one.js'] | ||
} | ||
}, | ||
tgz_flatten: { | ||
flatten: { | ||
options: { | ||
mode: 'tgz', | ||
flatten: true | ||
}, | ||
files: { | ||
'tmp/compress_test_flatten.zip': ['test/fixtures/**'], | ||
'tmp/compress_test_flatten.tar': ['test/fixtures/**'], | ||
'tmp/compress_test_flatten.tgz': ['test/fixtures/**'] | ||
@@ -136,20 +84,11 @@ } | ||
tgz_rootdir: { | ||
rootdir: { | ||
options: { | ||
mode: 'tgz', | ||
rootDir: 'abc123' | ||
}, | ||
files: { | ||
'tmp/compress_test_rootdir.zip': ['test/fixtures/**'], | ||
'tmp/compress_test_rootdir.tar': ['test/fixtures/**'], | ||
'tmp/compress_test_rootdir.tgz': ['test/fixtures/**'] | ||
} | ||
}, | ||
gzip: { | ||
options: { | ||
mode: 'gzip' | ||
}, | ||
files: { | ||
'tmp/compress_test_file.gz': ['test/fixtures/test.js'], | ||
'tmp/compress_test_file2.gz': ['test/fixtures/folder_one/one.js'] | ||
} | ||
} | ||
@@ -156,0 +95,0 @@ }, |
{ | ||
"name": "grunt-contrib-compress", | ||
"description": "Compress files and folders.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/gruntjs/grunt-contrib-compress", | ||
@@ -25,3 +25,3 @@ "author": { | ||
"engines": { | ||
"node": "*" | ||
"node": ">= 0.6.3" | ||
}, | ||
@@ -34,3 +34,3 @@ "scripts": { | ||
"fstream": "~0.1.18", | ||
"zipstream": "~0.2.1", | ||
"zipstream-ctalkington": "~0.3.0", | ||
"rimraf": "~2.0.2", | ||
@@ -37,0 +37,0 @@ "grunt-contrib-lib": "~0.2.0" |
@@ -5,3 +5,3 @@ # grunt-contrib-compress | ||
## Getting Started | ||
Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-contrib-clean` | ||
Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-contrib-compress` | ||
@@ -39,2 +39,4 @@ Then add this line to your project's `grunt.js` gruntfile: | ||
As of v0.2.2, this is now automatically detected per dest:src pair but can be overridden per target if desired. | ||
##### basePath ```string``` | ||
@@ -44,2 +46,4 @@ | ||
This has been automatically detected per dest:src pair for some time now but can be overridden per target if desired. | ||
##### flatten ```boolean``` | ||
@@ -64,44 +68,16 @@ | ||
zip: { | ||
options: { | ||
mode: "zip", | ||
basePath: "path/to", | ||
level: 1 | ||
}, | ||
files: { | ||
"path/to/result.zip": "path/to/source/*", // includes files in dir | ||
"path/to/another.gz": "path/to/source/**", // includes files in dir and subdirs | ||
"path/to/final.zip": ["path/to/sources/*.js", "path/to/more/*.js"], // include JS files in two diff dirs | ||
"path/to/another.tar": "path/to/source/**", // includes files in dir and subdirs | ||
"path/to/final.tgz": ["path/to/sources/*.js", "path/to/more/*.js"], // include JS files in two diff dirs | ||
"path/to/single.gz": "path/to/source/single.js", // gzip a single file | ||
"path/to/project-<%= pkg.version %>.zip": "path/to/source/**" // variables in destination | ||
} | ||
} | ||
} | ||
``` | ||
tar: { | ||
options: { | ||
mode: "tar", | ||
basePath: "path/to" | ||
}, | ||
files: { | ||
"path/to/result.tar": "path/to/file.ext" | ||
} | ||
}, | ||
## Release History | ||
tgz: { | ||
options: { | ||
mode: "tgz", | ||
basePath: "path/to" | ||
}, | ||
files: { | ||
"path/to/result.tgz": "path/to/file.ext" | ||
} | ||
}, | ||
gzip: { | ||
options: { | ||
mode: "gzip" | ||
}, | ||
files: { | ||
"path/to/result.gz": "path/to/file.ext" | ||
} | ||
} | ||
} | ||
``` | ||
* 2012/09/18 - v0.2.2 - test refactoring. no valid source check. automatic mode detection. | ||
* 2012/09/10 - v0.2.0 - refactored from grunt-contrib into individual repo. |
@@ -40,7 +40,5 @@ /* | ||
var supported = ['zip', 'tar', 'tgz', 'gzip']; | ||
var mode = options.mode; | ||
if (options.mode === 'tgz') { | ||
mode = 'tar'; | ||
} | ||
var supportedModes = ['zip', 'tar', 'tgz', 'gzip']; | ||
var targetMode = options.mode; | ||
delete options.mode; | ||
@@ -64,10 +62,5 @@ var done = this.async(); | ||
if (_.include(supported, options.mode) === false) { | ||
grunt.log.error('Mode ' + options.mode + ' not supported.'); | ||
done(); | ||
return; | ||
} | ||
var srcFiles; | ||
var destDir; | ||
var mode; | ||
@@ -78,2 +71,12 @@ async.forEachSeries(this.files, function(file, next) { | ||
if (srcFiles.length === 0) { | ||
grunt.fail.warn('Unable to compress; no valid source files were found.'); | ||
} | ||
mode = targetMode || autoDetectMode(file.dest); | ||
if (_.include(supportedModes, mode) === false) { | ||
grunt.fail.warn('Mode ' + mode.cyan + ' not supported.'); | ||
} | ||
if (options.mode === 'gzip' && srcFiles.length > 1) { | ||
@@ -89,3 +92,3 @@ grunt.fail.warn('Cannot specify multiple input files for gzip compression.'); | ||
methods[mode](srcFiles, file.dest, options, function(written) { | ||
grunt.log.writeln('File ' + file.dest + ' created (' + written + ' bytes written).'); | ||
grunt.log.writeln('File ' + file.dest.cyan + ' created (' + written + ' bytes written).'); | ||
next(); | ||
@@ -123,2 +126,16 @@ }); | ||
var autoDetectMode = function(dest) { | ||
if (_.endsWith(dest, '.tar.gz')) { | ||
return 'tgz'; | ||
} | ||
var ext = path.extname(dest).replace('.', ''); | ||
if (ext === 'gz') { | ||
return 'gzip'; | ||
} else { | ||
return ext; | ||
} | ||
}; | ||
var tempCopy = function(srcFiles, tempDir, options) { | ||
@@ -166,5 +183,4 @@ var newFiles = []; | ||
var methods = { | ||
zip: function(srcFiles, dest, options, callback) { | ||
var zip = require('zipstream').createZip(options); | ||
var zip = require('zipstream-ctalkington').createZip(options); | ||
@@ -199,3 +215,2 @@ var destDir = path.dirname(dest); | ||
// TODO: node-zipstream v0.2.1 has issues that prevents this from working atm! | ||
zip.on('error', function(e) { | ||
@@ -207,3 +222,3 @@ grunt.log.error(e); | ||
tar: function(srcFiles, dest, options, callback) { | ||
tar: function(srcFiles, dest, options, callback, gzip) { | ||
var fstream = require('fstream'); | ||
@@ -226,2 +241,6 @@ var tar = require('tar'); | ||
if (gzip === true) { | ||
tarDir = tarDir.replace('.tar', ''); | ||
} | ||
var tarProcess; | ||
@@ -238,3 +257,3 @@ | ||
if (options.mode === 'tgz') { | ||
if (gzip === true) { | ||
tarProcess = reader.pipe(packer).pipe(gzipper).pipe(writer); | ||
@@ -256,2 +275,6 @@ } else { | ||
tgz: function(srcFiles, dest, options, callback) { | ||
methods.tar(srcFiles, dest, options, callback, true); | ||
}, | ||
gzip: function(file, dest, options, callback) { | ||
@@ -271,3 +294,2 @@ var zlib = require('zlib'); | ||
}; | ||
}; |
var grunt = require('grunt'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
@@ -9,3 +8,3 @@ | ||
try { | ||
return fs.statSync(path.join('tmp', filename)).size; | ||
return fs.statSync(filename).size; | ||
} catch (e) { | ||
@@ -16,107 +15,93 @@ return 0; | ||
exports['compress'] = { | ||
zip: function(test) { | ||
exports.compress = { | ||
main: function(test) { | ||
'use strict'; | ||
var expect, result; | ||
test.expect(11); | ||
test.expect(5); | ||
// 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'); | ||
expect = 310; | ||
result = getSize('compress_test_files.zip'); | ||
test.equal(expect, result, 'should compress files into zip'); | ||
actual = getSize('tmp/compress_test_v0.1.0.zip'); | ||
expected = getSize('test/expected/compress_test_v0.1.0.zip'); | ||
test.equal(expected, actual, 'should compress folders and their files into zip (with template support)'); | ||
expect = 962; | ||
result = getSize('compress_test_v0.1.0.zip'); | ||
test.equal(expect, result, 'should compress folders and their files into zip (with template support)'); | ||
actual = getSize('tmp/compress_test_files_template.zip'); | ||
expected = getSize('test/expected/compress_test_files_template.zip'); | ||
test.equal(expected, actual, 'should compress files and folders into zip (grunt template in source)'); | ||
expect = 302; | ||
result = getSize('compress_test_files_template.zip'); | ||
test.equal(expect, result, 'should compress files and folders into zip (grunt template in source)'); | ||
// 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'); | ||
expect = 874; | ||
result = getSize('compress_test_flatten.zip'); | ||
test.equal(expect, result, 'should create a flat internal structure'); | ||
actual = getSize('tmp/compress_test_v0.1.0.tar'); | ||
expected = getSize('test/expected/compress_test_v0.1.0.tar'); | ||
test.equal(expected, actual, 'should add folders and their files into tar (with template support)'); | ||
expect = 1046; | ||
result = getSize('compress_test_rootdir.zip'); | ||
test.equal(expect, result, 'should compress folders and their files into zip (with a root dir)'); | ||
actual = getSize('tmp/compress_test_files_template.tar'); | ||
expected = getSize('test/expected/compress_test_files_template.tar'); | ||
test.equal(expected, actual, 'should add files and folders into tar (grunt template in source)'); | ||
test.done(); | ||
}, | ||
// Tar (gzip) | ||
actual = getSize('tmp/compress_test_files.tgz') >= 200; | ||
expected = true; | ||
test.equal(expected, actual, 'should compress files into tar'); | ||
tar: function(test) { | ||
'use strict'; | ||
actual = getSize('tmp/compress_test_v0.1.0.tgz') >= 350; | ||
expected = true; | ||
test.equal(expected, actual, 'should compress folders and their files into tgz (with template support)'); | ||
var expect, result; | ||
actual = getSize('tmp/compress_test_files_template.tgz') >= 200; | ||
expected = true; | ||
test.equal(expected, actual, 'should compress files and folders into tgz (grunt template in source)'); | ||
test.expect(5); | ||
// gzip | ||
actual = getSize('tmp/compress_test_file.gz'); | ||
expected = getSize('test/expected/compress_test_file.gz'); | ||
test.equal(expected, actual, 'should gzip file'); | ||
expect = 3072; | ||
result = getSize('compress_test_files.tar'); | ||
test.equal(expect, result, 'should add files into tar'); | ||
actual = getSize('tmp/compress_test_file2.gz'); | ||
expected = getSize('test/expected/compress_test_file2.gz'); | ||
test.equal(expected, actual, 'should gzip another file (multiple dest:source pairs)'); | ||
expect = 8192; | ||
result = getSize('compress_test_v0.1.0.tar'); | ||
test.equal(expect, result, 'should add folders and their files into tar (with template support)'); | ||
expect = 3072; | ||
result = getSize('compress_test_files_template.tar'); | ||
test.equal(expect, result, 'should add files and folders into tar (grunt template in source)'); | ||
expect = 7168; | ||
result = getSize('compress_test_flatten.tar'); | ||
test.equal(expect, result, 'should create a flat internal structure'); | ||
expect = 8192; | ||
result = getSize('compress_test_rootdir.tar'); | ||
test.equal(expect, result, 'should compress folders and their files into tar (with a custom root dir)'); | ||
test.done(); | ||
}, | ||
tgz: function(test) { | ||
flatten: function(test) { | ||
'use strict'; | ||
var expect, result; | ||
test.expect(3); | ||
test.expect(5); | ||
var actual = getSize('tmp/compress_test_flatten.zip'); | ||
var expected = getSize('test/expected/compress_test_flatten.zip'); | ||
test.equal(expected, actual, 'should create a flat internal structure'); | ||
expect = true; | ||
result = getSize('compress_test_files.tgz') >= 200; | ||
test.equal(expect, result, 'should compress files into tar'); | ||
actual = getSize('tmp/compress_test_flatten.tar'); | ||
expected = getSize('test/expected/compress_test_flatten.tar'); | ||
test.equal(expected, actual, 'should create a flat internal structure'); | ||
expect = true; | ||
result = getSize('compress_test_v0.1.0.tgz') >= 350; | ||
test.equal(expect, result, 'should compress folders and their files into tgz (with template support)'); | ||
actual = getSize('tmp/compress_test_flatten.tgz') >= 320; | ||
expected = true; | ||
test.equal(expected, actual, 'should create a flat internal structure'); | ||
expect = true; | ||
result = getSize('compress_test_files_template.tgz') >= 200; | ||
test.equal(expect, result, 'should compress files and folders into tgz (grunt template in source)'); | ||
expect = true; | ||
result = getSize('compress_test_flatten.tgz') >= 320; | ||
test.equal(expect, result, 'should create a flat internal structure'); | ||
expect = true; | ||
result = getSize('compress_test_rootdir.tgz') >= 200; | ||
test.equal(expect, result, 'should compress folders and their files into tgz (with a custom root dir)'); | ||
test.done(); | ||
}, | ||
gzip: function(test) { | ||
rootdir: function(test) { | ||
'use strict'; | ||
var expect, result; | ||
test.expect(3); | ||
test.expect(2); | ||
var actual = getSize('tmp/compress_test_rootdir.zip'); | ||
var expected = getSize('test/expected/compress_test_rootdir.zip'); | ||
test.equal(expected, actual, 'should compress folders and their files into zip (with a root dir)'); | ||
expect = 52; | ||
result = getSize('compress_test_file.gz'); | ||
test.equal(expect, result, 'should gzip file'); | ||
actual = getSize('tmp/compress_test_rootdir.tar'); | ||
expected = getSize('test/expected/compress_test_rootdir.tar'); | ||
test.equal(expected, actual, 'should compress folders and their files into tar (with a custom root dir)'); | ||
expect = 67; | ||
result = getSize('compress_test_file2.gz'); | ||
test.equal(expect, result, 'should gzip another file (multiple dest:source pairs)'); | ||
actual = getSize('tmp/compress_test_rootdir.tgz') >= 200; | ||
expected = true; | ||
test.equal(expected, actual, 'should compress folders and their files into tgz (with a custom root dir)'); | ||
@@ -123,0 +108,0 @@ test.done(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 6 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53615
26
392
79
6
+ Addedzipstream-ctalkington@~0.3.0
- Removedzipstream@~0.2.1
- Removedzipstream@0.2.1(transitive)