Merge pull request #4 from harangue/master

Updated to work with new s3 node module
This commit is contained in:
Nicholas Terwoord
2016-06-22 21:08:30 -04:00
committed by GitHub
2 changed files with 46 additions and 41 deletions

View File

@@ -1,24 +1,22 @@
var s3 = require('s3');
var chalk = require('chalk');
var s3sync = require('s3-sync');
var readdirp = require('readdirp');
module.exports = function(args) {
var config = {
maxAsyncS3: args.concurrency,
s3Options: {
accessKeyId: args.aws_key || process.env.AWS_KEY,
secretAccessKey: args.aws_secret || process.env.AWS_SECRET,
region: args.region
}
};
var client = s3.createClient(config);
var publicDir = this.config.public_dir;
var log = this.log;
if (!args.hasOwnProperty('concurrency')) {
args.concurrency = 8;
}
if (!args.hasOwnProperty('aws_key')) {
args.aws_key = process.env.AWS_KEY
}
if (!args.hasOwnProperty('aws_secret')) {
args.aws_secret = process.env.AWS_SECRET;
}
if (!args.bucket || !args.aws_key || !args.aws_secret) {
if (!args.bucket || !config.s3Options.accessKeyId || !config.s3Options.secretAccessKey) {
var help = '';
help += 'You should configure deployment settings in _config.yml first!\n\n';
@@ -30,26 +28,29 @@ module.exports = function(args) {
help += ' [aws_secret]: <aws_secret> # Optional, if provided as environment variable\n';
help += ' [concurrency]: <concurrency>\n';
help += ' [region]: <region> # See https://github.com/LearnBoost/knox#region\n\n',
help += 'For more help, you can check the docs: ' + chalk.underline('https://github.com/nt3rp/hexo-deployer-s3');
help += 'For more help, you can check the docs: ' + chalk.underline('https://github.com/nt3rp/hexo-deployer-s3');
console.log(help);
return;
}
// s3sync takes the same options arguments as `knox`,
// plus some additional options listed above
return readdirp({root: publicDir, entryType: 'both'})
.pipe(s3sync({
key: args.aws_key,
secret: args.aws_secret,
bucket: args.bucket,
concurrency: args.concurrency,
region: args.region
}).on('data', function(file) {
log.info(file.fullPath + ' -> ' + file.url)
}).on('end', function() {
log.info('Done!');
}).on('fail', function(err) {
log.error(err)
}));
var params = {
localDir: publicDir,
deleteRemoved: true,
s3Params: {
Bucket: args.bucket
}
}
var uploader = client.uploadDir(params);
log.info('Uploading...');
return uploader
.on('progress', function() {
// log.info(uploader.progressAmount + ' / ' + uploader.progressTotal);
}).on('end', function() {
log.info('Done!');
}).on('error', function(err) {
log.error(err)
});
};

View File

@@ -1,6 +1,6 @@
{
"name": "hexo-deployer-s3",
"version": "0.1.0",
"version": "0.2.0",
"description": "Amazon S3 deployer plugin for Hexo",
"main": "index",
"keywords": [
@@ -10,10 +10,16 @@
"deployer"
],
"author": "Nicholas Terwoord <nicholas.terwoord+code@gmail.com>",
"contributors": [{
"name": "Josh Strange",
"email": "josh@joshstrange.com"
}],
"contributors": [
{
"name": "Josh Strange",
"email": "josh@joshstrange.com"
},
{
"name": "Jack Guy",
"email": "jack@thatguyjackguy.com"
}
],
"repository": {
"type": "git",
"url": "http://github.com/nt3rp/hexo-deployer-s3.git"
@@ -25,9 +31,7 @@
"hexo": "3.x"
},
"dependencies": {
"chalk": "^1.0.0",
"level": "^0.18.0",
"readdirp": "^0.3.3",
"s3-sync": "^0.5.1"
"chalk": "^1.1.1",
"s3": "^4.4.0"
}
}