Comparing version 1.0.1 to 1.1.0
@@ -6,11 +6,12 @@ #!/usr/bin/env node | ||
var argv = require('yargs') | ||
.usage("\nUsage: bestzip destination.zip source/") | ||
.usage("\nUsage: bestzip destination.zip sources/") | ||
.demand(2) | ||
.argv._; | ||
var dest = argv[0]; | ||
var source = argv[1]; | ||
var dest = argv.shift(); | ||
var sources = argv; | ||
console.log('Writing %s to %s...', source, dest); | ||
zip(dest, source, function(err) { | ||
console.log('Writing %s to %s...', sources.join(', '), dest); | ||
var archive = zip(dest, sources, function(err) { | ||
if (err) { | ||
@@ -17,0 +18,0 @@ console.error(err); |
// creates a zip file using either the native `zip` command if avaliable, | ||
// or a node.js zip implimentation otherwise. | ||
// | ||
// currently only supports zipping a single source file/dir | ||
// currently only supports zipping a single sources file/dir | ||
@@ -11,2 +11,3 @@ var cp = require('child_process'); | ||
var archiver = require('archiver'); | ||
var async = require('async'); | ||
@@ -36,13 +37,8 @@ var NATIVE = 'native'; | ||
function nativeZip(dest, source, done) { | ||
cp.spawn('zip', ['--quiet', '--recurse-paths', dest, source], done); | ||
var args = ['--quiet', '--recurse-paths', dest].concat(source); | ||
cp.spawn('zip', args, done); | ||
} | ||
// based on http://stackoverflow.com/questions/15641243/need-to-zip-an-entire-directory-using-node-js/18775083#18775083 | ||
function nodeZip(dest, source, done) { | ||
var zipDest = source;// this "dest" is the filename inside of the zip | ||
var basename = pathUtil.basename(source); | ||
if (basename == '*') { | ||
source = source.substr(0, source.length-1); | ||
zipDest = '/'; | ||
} | ||
function nodeZip(dest, sources, done) { | ||
@@ -56,15 +52,32 @@ var output = fs.createWriteStream(dest); | ||
archive.pipe(output); | ||
fs.stat(source, function(err, stats) { | ||
if (stats.isDirectory()) { | ||
archive.bulk([ | ||
{expand: true, cwd: source, src: ['**'], dest: zipDest} | ||
]); | ||
} else if (stats.isFile()) { | ||
archive.file(source, {name: basename, stats: stats}); | ||
async.forEach(sources, function(source, next) { | ||
var zipDest = source;// this "dest" is the filename inside of the zip | ||
var basename = pathUtil.basename(source); | ||
if (basename == '*') { | ||
source = source.substr(0, source.length-1); | ||
zipDest = '/'; | ||
} | ||
fs.stat(source, function(err, stats) { | ||
if (stats.isDirectory()) { | ||
archive.bulk([ | ||
{expand: true, cwd: source, src: ['**'], dest: zipDest} | ||
]); | ||
} else if (stats.isFile()) { | ||
archive.file(source, {name: basename, stats: stats}); | ||
} | ||
next(); | ||
}); | ||
}, function(err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
archive.finalize(); | ||
}); | ||
}) | ||
} | ||
function zip(dest, source, done) { | ||
function zip(dest, sources, done) { | ||
if (!Array.isArray(sources)) { | ||
sources = [sources] | ||
} | ||
which(function(err, which) { | ||
@@ -75,5 +88,5 @@ if (err) { | ||
if (which == NATIVE) { | ||
nodeZip(dest, source, done); | ||
nodeZip(dest, sources, done); | ||
} else { | ||
nodeZip(dest, source, done); | ||
nodeZip(dest, sources, done); | ||
} | ||
@@ -80,0 +93,0 @@ }); |
{ | ||
"name": "bestzip", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Uses OS zip command if avaliable (for better performance and speed) or node.js version if there is no system command avaliable. Can be called via node or command line.", | ||
@@ -16,2 +16,3 @@ "main": "lib/bestzip.js", | ||
"archiver": "^0.12.0", | ||
"async": "^0.9.0", | ||
"concat-stream": "^1.4.6", | ||
@@ -18,0 +19,0 @@ "yargs": "^1.3.2" |
@@ -40,3 +40,3 @@ # bestzip | ||
zip('./destination.zip', 'source/', function(err) { | ||
zip('./destination.zip', ['source/', 'other_soure_file.js'], function(err) { | ||
if (err) { | ||
@@ -53,4 +53,3 @@ console.error(err.stack); | ||
* add support for more than one source | ||
* jshint | ||
* Fix bug when source contains `../` | ||
* Test if using a vbscript or whatever on Windows results in significantly better performance. | ||
@@ -57,0 +56,0 @@ |
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
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
6273
97
4
76
+ Addedasync@^0.9.0