From 58d0a1c3412a0ba3ebbfa1a1361151da367229c4 Mon Sep 17 00:00:00 2001 From: Nick Terwoord Date: Wed, 6 May 2015 19:15:36 -0400 Subject: [PATCH] Update to Hexo 3.0 Update to make code more similar to existing hexojs plugins. In theory should work with previous versions of hexojs, but forcing version to 3.0. --- README.md | 61 ++++++++++++-------------------------------- index.js | 67 +------------------------------------------------ lib/deployer.js | 55 ++++++++++++++++++++++++++++++++++++++++ package.json | 17 +++++++------ 4 files changed, 82 insertions(+), 118 deletions(-) create mode 100644 lib/deployer.js diff --git a/README.md b/README.md index c2b860f..09435e9 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,32 @@ -# S3 deployer plugin for [Hexo](http://zespia.tw/hexo/) +# hexo-deployer-s3 -This plugin can deploy your blog via S3. +Amazon S3 deployer plugin for [Hexo](http://hexo.io/) -## Usage +## Installation -### Install - -``` -npm install hexo-deployer-s3 --save +``` bash +$ npm install git://git@github.com/nt3rp/hexo-deployer-s3.git --save ``` -### Enable +## Options -Add `hexo-deployer-s3` to `plugins` in `_config.yml`. +You can configure this plugin in `_config.yml`. ``` yaml -plugins: -- hexo-deployer-s3 -``` - -### Configure - -Add `bucket`, `aws_key` and `aws_secret` to `deploy` in `_config.yml`. - -``` +# You can use this: deploy: type: s3 bucket: - aws_key: //Optional, if the environment variable `AWS_KEY` is set - aws_secret: //Optional, if the environment variable `AWS_SECRET` is set - concurrency: //Optional - region: //Optional, see https://github.com/LearnBoost/knox#region + aws_key: // Optional, if the environment variable `AWS_KEY` is set + aws_secret: // Optional, if the environment variable `AWS_SECRET` is set + concurrency: // Optional + region: // Optional, see https://github.com/LearnBoost/knox#region ``` -### Disable +## Contributors -Remove `hexo-deployer-s3` from `plugins` in `_config.yml`. +- Josh Strange ([joshstrange](https://github.com/joshstrange); original implementation) -``` yaml -plugins: -- hexo-deployer-s3 -``` +## License -### Update - -Execute the following command. - -``` -npm update -``` - -### Uninstall - -Execute the following command. Don't forget to disable the plugin before uninstalling. - -``` -npm uninstall hexo-deployer-s3 -``` - -[Hexo]: http://zespia.tw/hexo +MIT diff --git a/index.js b/index.js index 043d913..fffe4b7 100644 --- a/index.js +++ b/index.js @@ -1,66 +1 @@ -var level = require('level') - , s3sync = require('s3-sync') - , readdirp = require('readdirp') - - - -var public_dir = hexo.config.public_dir || './public'; - - -hexo.extend.deployer.register('s3', function (args, callback) { - var config = hexo.config.deploy; - - config.aws_key = config.aws_key || process.env.AWS_KEY; - config.aws_secret = config.aws_secret || process.env.AWS_SECRET; - - if (!config.bucket || !config.aws_key || !config.aws_secret){ - var help = [ - 'You should configure deployment settings in _config.yml first!', - '', - 'Example:', - ' deploy:', - ' type: s3', - ' bucket: ', - ' [aws_key]: # Optional, if provided as environment variable', - ' [aws_secret]: # Optional, if provided as environment variable', - ' [concurrency]: ', - ' [region]: # See https://github.com/LearnBoost/knox#region', - '', - 'For more help, you can check the docs: ' + 'https://github.com/joshstrange/hexo-deployer-s3' - ]; - - console.log(help.join('\n')); - return callback(); - } - - var files = readdirp({ - root: public_dir, - entryType: 'both' - }); - - if(!config.concurrency) - { - config.concurrency = 8; - } - - // Takes the same options arguments as `knox`, - // plus some additional options listed above - var uploader = s3sync({ - key: config.aws_key - , secret: config.aws_secret - , bucket: config.bucket - , concurrency: config.concurrency - , region: config.region - }).on('data', function(file) { - console.log(file.fullPath + ' -> ' + file.url) - }).on('end', function() { - console.log('Done!'); - callback(); - }).on('fail', function(err) { - console.log(err) - }); - - files.pipe(uploader); - - -}); +hexo.extend.deployer.register('s3', require('./lib/deployer')); \ No newline at end of file diff --git a/lib/deployer.js b/lib/deployer.js new file mode 100644 index 0000000..598d9b2 --- /dev/null +++ b/lib/deployer.js @@ -0,0 +1,55 @@ +var chalk = require('chalk'); +var s3sync = require('s3-sync'); +var readdirp = require('readdirp'); + +module.exports = function(args) { + 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) { + var help = ''; + + help += 'You should configure deployment settings in _config.yml first!\n\n'; + help += 'Example:\n'; + help += ' deploy:\n'; + help += ' type: s3\n'; + help += ' bucket: \n'; + help += ' [aws_key]: # Optional, if provided as environment variable\n'; + help += ' [aws_secret]: # Optional, if provided as environment variable\n'; + help += ' [concurrency]: \n'; + help += ' [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'); + + 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) + })); +}; \ No newline at end of file diff --git a/package.json b/package.json index cf6e18c..ccc93d7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hexo-deployer-s3", - "version": "0.0.2", - "description": "AWS S3 deployer plugin for Hexo", + "version": "0.1.0", + "description": "Amazon S3 deployer plugin for Hexo", "main": "index", "keywords": [ "hexo", @@ -9,21 +9,24 @@ "aws", "deployer" ], - "author": "Josh Strange", + "author": "Nicholas Terwoord ", + "contributors": [{ + "name": "Josh Strange" + "email": "josh@joshstrange.com" + }], "repository": { "type": "git", - "url": "http://github.com/joshstrange/hexo-deployer-s3.git" + "url": "http://github.com/nt3rp/hexo-deployer-s3.git" }, "license": { "type": "MIT" }, "engines": { - "hexo": ">= 1.0.0" + "hexo": ">= 3.0.0" }, "dependencies": { + "chalk": "^1.0.0", "readdirp": "^0.3.3", - "s3sync": "0.0.3", - "level": "^0.18.0", "s3-sync": "^0.5.1" } }