Merge pull request #4 from harangue/master
Updated to work with new s3 node module
This commit is contained in:
@@ -1,24 +1,22 @@
|
|||||||
|
var s3 = require('s3');
|
||||||
var chalk = require('chalk');
|
var chalk = require('chalk');
|
||||||
var s3sync = require('s3-sync');
|
|
||||||
var readdirp = require('readdirp');
|
|
||||||
|
|
||||||
module.exports = function(args) {
|
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 publicDir = this.config.public_dir;
|
||||||
var log = this.log;
|
var log = this.log;
|
||||||
|
|
||||||
if (!args.hasOwnProperty('concurrency')) {
|
if (!args.bucket || !config.s3Options.accessKeyId || !config.s3Options.secretAccessKey) {
|
||||||
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) {
|
|
||||||
var help = '';
|
var help = '';
|
||||||
|
|
||||||
help += 'You should configure deployment settings in _config.yml first!\n\n';
|
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 += ' [aws_secret]: <aws_secret> # Optional, if provided as environment variable\n';
|
||||||
help += ' [concurrency]: <concurrency>\n';
|
help += ' [concurrency]: <concurrency>\n';
|
||||||
help += ' [region]: <region> # See https://github.com/LearnBoost/knox#region\n\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);
|
console.log(help);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// s3sync takes the same options arguments as `knox`,
|
var params = {
|
||||||
// plus some additional options listed above
|
localDir: publicDir,
|
||||||
return readdirp({root: publicDir, entryType: 'both'})
|
deleteRemoved: true,
|
||||||
.pipe(s3sync({
|
s3Params: {
|
||||||
key: args.aws_key,
|
Bucket: args.bucket
|
||||||
secret: args.aws_secret,
|
}
|
||||||
bucket: args.bucket,
|
}
|
||||||
concurrency: args.concurrency,
|
|
||||||
region: args.region
|
var uploader = client.uploadDir(params);
|
||||||
}).on('data', function(file) {
|
log.info('Uploading...');
|
||||||
log.info(file.fullPath + ' -> ' + file.url)
|
|
||||||
}).on('end', function() {
|
return uploader
|
||||||
log.info('Done!');
|
.on('progress', function() {
|
||||||
}).on('fail', function(err) {
|
// log.info(uploader.progressAmount + ' / ' + uploader.progressTotal);
|
||||||
log.error(err)
|
}).on('end', function() {
|
||||||
}));
|
log.info('Done!');
|
||||||
|
}).on('error', function(err) {
|
||||||
|
log.error(err)
|
||||||
|
});
|
||||||
};
|
};
|
||||||
22
package.json
22
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hexo-deployer-s3",
|
"name": "hexo-deployer-s3",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"description": "Amazon S3 deployer plugin for Hexo",
|
"description": "Amazon S3 deployer plugin for Hexo",
|
||||||
"main": "index",
|
"main": "index",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -10,10 +10,16 @@
|
|||||||
"deployer"
|
"deployer"
|
||||||
],
|
],
|
||||||
"author": "Nicholas Terwoord <nicholas.terwoord+code@gmail.com>",
|
"author": "Nicholas Terwoord <nicholas.terwoord+code@gmail.com>",
|
||||||
"contributors": [{
|
"contributors": [
|
||||||
"name": "Josh Strange",
|
{
|
||||||
"email": "josh@joshstrange.com"
|
"name": "Josh Strange",
|
||||||
}],
|
"email": "josh@joshstrange.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jack Guy",
|
||||||
|
"email": "jack@thatguyjackguy.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://github.com/nt3rp/hexo-deployer-s3.git"
|
"url": "http://github.com/nt3rp/hexo-deployer-s3.git"
|
||||||
@@ -25,9 +31,7 @@
|
|||||||
"hexo": "3.x"
|
"hexo": "3.x"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^1.0.0",
|
"chalk": "^1.1.1",
|
||||||
"level": "^0.18.0",
|
"s3": "^4.4.0"
|
||||||
"readdirp": "^0.3.3",
|
|
||||||
"s3-sync": "^0.5.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user