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.
This commit is contained in:
61
README.md
61
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: <S3 bucket>
|
||||
aws_key: <AWS id key> //Optional, if the environment variable `AWS_KEY` is set
|
||||
aws_secret: <AWS secret key> //Optional, if the environment variable `AWS_SECRET` is set
|
||||
concurrency: <number of connections> //Optional
|
||||
region: <region> //Optional, see https://github.com/LearnBoost/knox#region
|
||||
aws_key: <AWS id key> // Optional, if the environment variable `AWS_KEY` is set
|
||||
aws_secret: <AWS secret key> // Optional, if the environment variable `AWS_SECRET` is set
|
||||
concurrency: <number of connections> // Optional
|
||||
region: <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
|
||||
|
||||
67
index.js
67
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: <bucket>',
|
||||
' [aws_key]: <aws_key> # Optional, if provided as environment variable',
|
||||
' [aws_secret]: <aws_secret> # Optional, if provided as environment variable',
|
||||
' [concurrency]: <concurrency>',
|
||||
' [region]: <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'));
|
||||
55
lib/deployer.js
Normal file
55
lib/deployer.js
Normal file
@@ -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: <bucket>\n';
|
||||
help += ' [aws_key]: <aws_key> # Optional, if provided as environment variable\n';
|
||||
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');
|
||||
|
||||
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)
|
||||
}));
|
||||
};
|
||||
17
package.json
17
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 <nicholas.terwoord+code@gmail.com>",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user