gulp-awspublish
awspublish plugin for gulp
Usage
First, install gulp-awspublish
as a development dependency:
npm install --save-dev gulp-awspublish
Then, add it to your gulpfile.js
:
var es = require('event-stream'),
awspublish = require('gulp-awspublish'),
publisher = awspublish({ key: '...', secret: '...', bucket: '...'}),
headers = { 'Cache-Control': 'max-age=315360000, no-transform, public' };
var js = gulp.src('./public/*.js')
.pipe(publisher.publish(headers));
var jsgz = gulp.src('./public/*.js')
.pipe(awspublish.gzip())
.pipe(publisher.publish(headers));
es.merge(js, jsgz)
.pipe(publisher.sync())
.pipe(publisher.cache())
.pipe(publisher.reporter());
Testing
add an aws-credentials.json json file to the project directory
with your bucket credentials, then run mocha.
{
"key": "...",
"secret": "...",
"bucket": "..."
}
API
awspublish.gzip()
create a through stream, that gzip file and add Content-Encoding header
awspublish.create(options)
Create a Publisher
Options are passed to knox to create a s3 client
create a through stream, that push files to s3.
publish take a header
object that add or override existing s3 headers.
Files that go through the stream get extra properties
s3.path: s3 path
s3.etag: file etag
s3.state: publication state (create, update, cache or skip)
s3.headers: s3 headers for this file
Defaults headers are:
- x-amz-acl: public-read
- Content-Type
- Content-Length
publisher.cache()
create a through stream that create or update a cache file using file s3 path
and file etag. Consecutive runs of publish will use this file to avoid reuploading identical files
Cache file is save in the current working dir and is named.awspublish-bucket
The cache file is flushed to disk every 10 files just to be safe :)
Publisher.sync()
create a transform stream that delete old files from the bucket
Both new and delete files are written to the stream
deleted file will have s3.state set to delete
Publisher.client
the knox client to let you do other s3 operations
awspublish.reporter([options])
create a reporter that logs s3.path and s3.state (delete, create, update, cache, skip)
Available options:
- states: list of state to log (default to all)
License
MIT License