gulp-s3-upload
Advanced tools
Comparing version 0.8.0 to 0.8.5
30
index.js
@@ -18,3 +18,3 @@ var through = require('through2') | ||
*/ | ||
return function(options) { | ||
return function(options, s3_params) { | ||
@@ -29,3 +29,3 @@ var stream, keyname_transform; | ||
stream = through.obj(function(file, enc, callback) { | ||
var keyname, keyparts, filename, mimetype; | ||
var keyname, keyparts, filename, mimetype, mimeLookupName; | ||
@@ -41,6 +41,8 @@ if(file.isNull()) { | ||
if(options.name_transform) { | ||
// Plugin Transforms & Look-ups | ||
// File Name transform | ||
if(options.nameTransform) { | ||
// allow the transform function to take the complete path | ||
// in case the user wants to change the path of the file, too. | ||
keyname = options.name_transform(file.relative); | ||
keyname = options.nameTransform(file.relative); | ||
} else { | ||
@@ -53,4 +55,8 @@ // otherwise keep it exactly parallel | ||
keyname = keyname.replace(/\\/g, "/"); // jic windows | ||
mimetype = mime.lookup(keyname); | ||
// Mime Lookup | ||
mimeLookupName = options.mimeTypeLookup ? options.mimeTypeLookup(keyname) : keyname; | ||
mimetype = mime.lookup(mimeLookupName); | ||
_s3.getObject({ | ||
@@ -84,2 +90,6 @@ Bucket: options.bucket | ||
if(s3_params) { | ||
objectOptions = helper.mergeOptions(objectOptions, s3_params); | ||
} | ||
_s3.putObject(objectOptions, function(err, data) { | ||
@@ -113,3 +123,3 @@ if(err) { | ||
module.exports = function(config) { | ||
var aws_config = {}; | ||
var aws_config = config || {}; | ||
@@ -119,9 +129,5 @@ aws_config.accessKeyId = config.key; | ||
if(config.region) { | ||
aws_config.region = config.region; | ||
} | ||
if(!config) { | ||
if(!aws_config.accessKeyId || !aws_config.secretAccessKey) { | ||
throw new PluginError(PLUGIN_NAME, "Missing AWS Key & secret."); | ||
return false; | ||
} | ||
@@ -132,2 +138,2 @@ | ||
return gulpPrefixer(AWS); | ||
} | ||
}; |
{ | ||
"name": "gulp-s3-upload", | ||
"version": "0.8.0", | ||
"version": "0.8.5", | ||
"description": "A gulp task to upload/update assets to an S3 account.", | ||
@@ -26,7 +26,8 @@ "main": "index.js", | ||
"dependencies": { | ||
"through2": "^0.6.1", | ||
"aws-sdk": "^2.0.15", | ||
"gulp-util": "^3.0.0", | ||
"mime": "^1.2.11" | ||
"mime": "^1.2.11", | ||
"through2": "^0.6.1", | ||
"underscore": "^1.7.0" | ||
} | ||
} |
@@ -8,8 +8,4 @@ # gulp-s3-upload | ||
[NPM](https://www.npmjs.com/package/gulp-s3-upload) / [Changelog](changelog.md) | ||
**Note** | ||
I haven't written tests for this quite yet, since it utilizes an Amazon AWS account. | ||
This is also my first gulp plugin and my first npm published package, so any advice/help appreciated. | ||
Thanks, Caroline | ||
## Install | ||
@@ -19,3 +15,3 @@ npm install gulp-s3-upload | ||
## Usage | ||
Put in your AWS Developer key/secret. Region is optional. | ||
@@ -30,2 +26,6 @@ | ||
The other options not mentioned above available in the [AWS Config constructor](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property) are also available, though by default are undefined. | ||
Signature to pass through pipe: `s3(plugin_options [, putObjectParams])`; | ||
Create a task. | ||
@@ -42,5 +42,10 @@ | ||
**As of Version 0.8.5**, the s3 task can now take a second parameter that has all the options available in the [S3 putObject documentation](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property). | ||
#### Options | ||
Any settings that are overlapped between the required paramter in this new optional parameter will be overwritten if defined in the second optional parameter, with `Body` being the exception, since that is purely handled by the gulp stream, and `Bucket` since it is required in the first set of required options. | ||
The way this is handled in the future will be changed for version 1.0, condensing everything into one `options` parameter. See the [Feature Roadmap](roadmap.md) for details. | ||
### Options | ||
**bucket** *(required)* | ||
@@ -57,5 +62,6 @@ | ||
See [Access Control List (ACL) Overview](http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html) | ||
See [Access Control List (ACL) Overview](http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html) | ||
for more information. Defaults to 'public-read'. | ||
**gzip** | ||
@@ -67,2 +73,3 @@ | ||
**cache** | ||
@@ -74,2 +81,3 @@ | ||
**meta** | ||
@@ -81,4 +89,5 @@ | ||
**name_transform** | ||
**nameTransform** | ||
Type: `function` | ||
@@ -92,5 +101,5 @@ | ||
gulp.src("./dir/to/upload/**") | ||
.pipe(aws({ | ||
.pipe(s3({ | ||
bucket: 'example-bucket', | ||
name_transform: function(relative_filename) { | ||
nameTransform: function(relative_filename) { | ||
var new_name = change_file_name(relative_filename); | ||
@@ -103,5 +112,25 @@ return new_name; | ||
**mime_type_lookup** | ||
Type: `function` | ||
Use this to transform what the key that is used to match the MIME type when uploading to s3. | ||
Example: | ||
gulp.task("upload_transform", function() { | ||
gulp.src("./dir/to/upload/**") | ||
.pipe(s3({ | ||
bucket: 'example-bucket', | ||
mimeTypeLookup: function(originalFilepath) { | ||
return originalFilepath.replace('.gz', ''); //ignore gzip extension | ||
}, | ||
})); | ||
}); | ||
---------------------------------------------------- | ||
### License | ||
### License | ||
Copyright (c) 2014, [Caroline Amaba](mailto:caroline.amaba@gmail.com) | ||
@@ -108,0 +137,0 @@ |
"use strict"; | ||
var Path = require('path'); | ||
var Path = require('path'), | ||
_ = require('underscore'); | ||
@@ -16,3 +17,10 @@ module.exports = { | ||
return Path.join(dirs, filename); | ||
}, | ||
mergeOptions: function(defaultObjOpts, userObjOpts) { | ||
// Body is handled by stream, Bucket will be defined | ||
// in first parameter. | ||
userObjOpts = _.omit(userObjOpts, ['Body', 'Bucket']); | ||
return _.extend(defaultObjOpts, userObjOpts); | ||
} | ||
}; |
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
11629
7
123
131
5
+ Addedunderscore@^1.7.0
+ Addedunderscore@1.13.7(transitive)