53
README.md
53
README.md
@@ -1,29 +1,19 @@
|
|||||||
# 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
|
``` bash
|
||||||
|
$ npm install git://git@github.com/nt3rp/hexo-deployer-s3.git --save
|
||||||
```
|
|
||||||
npm install hexo-deployer-s3 --save
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Enable
|
## Options
|
||||||
|
|
||||||
Add `hexo-deployer-s3` to `plugins` in `_config.yml`.
|
You can configure this plugin in `_config.yml`.
|
||||||
|
|
||||||
``` yaml
|
``` yaml
|
||||||
plugins:
|
# You can use this:
|
||||||
- hexo-deployer-s3
|
|
||||||
```
|
|
||||||
|
|
||||||
### Configure
|
|
||||||
|
|
||||||
Add `bucket`, `aws_key` and `aws_secret` to `deploy` in `_config.yml`.
|
|
||||||
|
|
||||||
```
|
|
||||||
deploy:
|
deploy:
|
||||||
type: s3
|
type: s3
|
||||||
bucket: <S3 bucket>
|
bucket: <S3 bucket>
|
||||||
@@ -33,29 +23,10 @@ deploy:
|
|||||||
region: <region> // Optional, see https://github.com/LearnBoost/knox#region
|
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
|
## License
|
||||||
plugins:
|
|
||||||
- hexo-deployer-s3
|
|
||||||
```
|
|
||||||
|
|
||||||
### Update
|
MIT
|
||||||
|
|
||||||
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
|
|
||||||
|
|||||||
67
index.js
67
index.js
@@ -1,66 +1 @@
|
|||||||
var level = require('level')
|
hexo.extend.deployer.register('s3', require('./lib/deployer'));
|
||||||
, 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);
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
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",
|
"name": "hexo-deployer-s3",
|
||||||
"version": "0.0.2",
|
"version": "0.1.0",
|
||||||
"description": "AWS S3 deployer plugin for Hexo",
|
"description": "Amazon S3 deployer plugin for Hexo",
|
||||||
"main": "index",
|
"main": "index",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"hexo",
|
"hexo",
|
||||||
@@ -9,21 +9,24 @@
|
|||||||
"aws",
|
"aws",
|
||||||
"deployer"
|
"deployer"
|
||||||
],
|
],
|
||||||
"author": "Josh Strange",
|
"author": "Nicholas Terwoord <nicholas.terwoord+code@gmail.com>",
|
||||||
|
"contributors": [{
|
||||||
|
"name": "Josh Strange"
|
||||||
|
"email": "josh@joshstrange.com"
|
||||||
|
}],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://github.com/joshstrange/hexo-deployer-s3.git"
|
"url": "http://github.com/nt3rp/hexo-deployer-s3.git"
|
||||||
},
|
},
|
||||||
"license": {
|
"license": {
|
||||||
"type": "MIT"
|
"type": "MIT"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"hexo": ">= 1.0.0"
|
"hexo": ">= 3.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"chalk": "^1.0.0",
|
||||||
"readdirp": "^0.3.3",
|
"readdirp": "^0.3.3",
|
||||||
"s3sync": "0.0.3",
|
|
||||||
"level": "^0.18.0",
|
|
||||||
"s3-sync": "^0.5.1"
|
"s3-sync": "^0.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user