gulp-awspublish
Advanced tools
Comparing version 0.0.4 to 0.0.5
0.0.5 / 2014-02-05 | ||
================== | ||
* update sync | ||
0.0.4 / 2014-02-04 | ||
@@ -13,3 +18,2 @@ ================== | ||
* add cache feature | ||
* Update README.md | ||
@@ -16,0 +20,0 @@ 0.0.1 / 2014-02-03 |
@@ -1,2 +0,2 @@ | ||
var Readable = require('stream').Readable, | ||
var Stream = require('stream'), | ||
fs = require('fs'), | ||
@@ -249,43 +249,57 @@ through = require('through2'), | ||
* Sync file in stream with file in the s3 bucket | ||
* @param {Stream} stream stream of files to keep in sync with the bucket | ||
* | ||
* @return {Stream} a readable stream with both input files and delete files | ||
* @return {Stream} a transform stream that stream both new and delete files | ||
* @api public | ||
*/ | ||
Publisher.prototype.sync = function(stream) { | ||
Publisher.prototype.sync = function() { | ||
var client = this.client, | ||
rs = new Readable({ objectMode : true }); | ||
stream = new Stream.Transform({ objectMode : true }), | ||
newFiles = [], | ||
existings; | ||
rs._read = function() {}; | ||
// compare newfiles and existings | ||
// and delete old files from bucket | ||
function cleanup(cb) { | ||
client.list({}, function(err, data) { | ||
if (err) return rs.emit('error', err); | ||
// get old files | ||
var oldS3paths = existings.filter(function (file) { | ||
return newFiles.indexOf(file) === -1; | ||
}); | ||
// get file in the s3 bucket | ||
var s3Docs = data.Contents.map(function(item) { return item.Key; }); | ||
// add file to stream and mark file we dont want to delete | ||
stream.on('data', function(file) { | ||
file = initFile(file); | ||
delete s3Docs[s3Docs.indexOf(file.s3.path)]; | ||
rs.push(file); | ||
// push old files in the stream | ||
oldS3paths.forEach(function (s3path) { | ||
var file = new gutil.File({}); | ||
file.s3 = {path: s3path, state: 'delete', headers: {} }; | ||
stream.push(file); | ||
}); | ||
// add files to delete to stream and trigger a request to delete them | ||
stream.on('end', function() { | ||
s3Docs.forEach(function (s3path) { | ||
var file = new gutil.File({}); | ||
file.s3 = {path: s3path, state: 'delete', headers: {} }; | ||
rs.push(file); | ||
}); | ||
// delete old files from bucket | ||
client.deleteMultiple(oldS3paths, cb); | ||
} | ||
client.deleteMultiple(s3Docs, function(err) { | ||
if (err) return rs.emit('error', err); | ||
rs.push(null); | ||
}); | ||
// push file to stream and add files to s3 path to list of new files | ||
stream._transform = function(file, encoding, cb) { | ||
newFiles.push(file.s3.path); | ||
this.push(file); | ||
cb(); | ||
}; | ||
// figure out what are the old files | ||
// cleanup and add deleted file to stream | ||
stream._flush = function(cb) { | ||
// get actual | ||
client.list({}, function(err, data) { | ||
if (err) return cb(err); | ||
// get file in the s3 bucket | ||
existings = data.Contents.map(function(item) { return item.Key; }); | ||
// clean up files | ||
cleanup(cb); | ||
}); | ||
}); | ||
}; | ||
return rs; | ||
return stream; | ||
}; | ||
@@ -292,0 +306,0 @@ |
{ | ||
"name": "gulp-awspublish", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "gulp plugin to publish files to amazon s3", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -38,4 +38,4 @@ # gulp-awspublish | ||
// print progress with reporter | ||
publisher | ||
.sync(es.merge(js, jsgz))) | ||
es.merge(js, jsgz) | ||
.pipe(publisher.sync()) | ||
.pipe(publisher.cache()) | ||
@@ -96,3 +96,3 @@ .pipe(publisher.reporter()); | ||
### publisher.cache() | ||
#### publisher.cache() | ||
@@ -105,6 +105,6 @@ create a through stream that create or update a cache file with the list | ||
#### Publisher.sync(stream) | ||
#### Publisher.sync() | ||
Take a stream of files and sync the content of the s3 bucket with these files. | ||
It return a readable stream with both input files and deleted files | ||
create a transform stream that delete old files from the bucket | ||
and stream both new and delete files. | ||
deleted file will have s3.state set to delete | ||
@@ -114,3 +114,3 @@ | ||
The knox client is exposed to let you do other s3 operations | ||
Expose the knox clientto let you do other s3 operations | ||
@@ -117,0 +117,0 @@ ### awspublish.reporter() |
@@ -227,4 +227,4 @@ /* global describe, before, it */ | ||
publisher | ||
.sync(stream) | ||
stream | ||
.pipe(publisher.sync()) | ||
.pipe(es.writeArray(function(err, arr) { | ||
@@ -231,0 +231,0 @@ expect(err).to.not.exist; |
Sorry, the diff of this file is not supported yet
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
21651
472
14