Working code

This commit is contained in:
Josh Strange
2014-03-01 13:42:41 -05:00
parent 94a9546ddc
commit 8ef4301495
5 changed files with 70 additions and 52 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules
cache

View File

@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2013 Florian Cargoët Copyright (c) 2013 Josh Strange
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

View File

@@ -1,45 +1,44 @@
# FTP deployer plugin for [Hexo](http://zespia.tw/hexo/) # S3 deployer plugin for [Hexo](http://zespia.tw/hexo/)
This plugin can deploy your blog via FTP. This plugin can deploy your blog via S3.
## Usage ## Usage
### Install ### Install
``` ```
npm install hexo-deployer-ftp --save npm install hexo-deployer-s3 --save
``` ```
`lftp` is required. Install it with `apt-get install lftp` or `brew install lftp` depending on your OS.
### Enable ### Enable
Add `hexo-deployer-ftp` to `plugins` in `_config.yml`. Add `hexo-deployer-s3` to `plugins` in `_config.yml`.
``` yaml ``` yaml
plugins: plugins:
- hexo-deployer-ftp - hexo-deployer-s3
``` ```
### Configure ### Configure
Add `host`, `user` and `root` to `deploy` in `_config.yml`. Add `bucket`, `aws_key` and `aws_secret` to `deploy` in `_config.yml`.
``` ```
deploy: deploy:
type: ftp type: s3
host: <ftp host> bucket: <S3 bucket>
user: <ftp user> aws_key: <AWS id key>
root: <path/to/your/blog/on/the/server> aws_secret: <AWS secret key>
concurrency: <number of connections> //Optional
``` ```
### Disable ### Disable
Remove `hexo-deployer-ftp` from `plugins` in `_config.yml`. Remove `hexo-deployer-s3` from `plugins` in `_config.yml`.
``` yaml ``` yaml
plugins: plugins:
- hexo-deployer-ftp - hexo-deployer-s3
``` ```
### Update ### Update
@@ -55,7 +54,7 @@ npm update
Execute the following command. Don't forget to disable the plugin before uninstalling. Execute the following command. Don't forget to disable the plugin before uninstalling.
``` ```
npm uninstall hexo-deployer-ftp npm uninstall hexo-deployer-s3
``` ```
[Hexo]: http://zespia.tw/hexo [Hexo]: http://zespia.tw/hexo

View File

@@ -1,52 +1,60 @@
var spawn = require('child_process').spawn; var level = require('level')
, s3sync = require('s3-sync')
, readdirp = require('readdirp')
var public_dir = hexo.config.public_dir || './public'; var public_dir = hexo.config.public_dir || './public';
// run function which supports interactive commands
function run (command, args, callback) {
process.stdin.pause();
process.stdin.setRawMode(false);
var p = spawn(command, args, { hexo.extend.deployer.register('s3', function (args, callback) {
customFds: [0, 1, 2]
});
return p.on('exit', function() {
process.stdin.setRawMode(true);
process.stdin.resume();
return callback();
});
};
hexo.extend.deployer.register('ftp', function (args, callback) {
var config = hexo.config.deploy; var config = hexo.config.deploy;
if (!config.host || !config.user || !config.root){ if (!config.bucket || !config.aws_key || !config.aws_secret){
var help = [ var help = [
'You should configure deployment settings in _config.yml first!', 'You should configure deployment settings in _config.yml first!',
'', '',
'Example:', 'Example:',
' deploy:', ' deploy:',
' type: ftp', ' type: s3',
' host: <host>', ' bucket: <bucket>',
' user: <user>', ' aws_key: <aws_key>',
' root: <root>', ' aws_secret: <aws_secret>',
' [concurrency]: <concurrency>',
'', '',
'For more help, you can check the docs: ' + 'http://zespia.tw/hexo/docs/deployment.html' 'For more help, you can check the docs: ' + 'https://github.com/joshstrange/hexo-deployer-s3'
]; ];
console.log(help.join('\n')); console.log(help.join('\n'));
return callback(); return callback();
} }
var args = [
'-e',
'mirror -R --ignore-time --delete -v ' + public_dir + ' ' + config.root + '; bye',
'-u',
config.user,
config.host
];
run('lftp', args, function (code) { var files = readdirp({
root: public_dir
, directoryFilter: []
});
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
}).on('data', function(file) {
console.log(file.fullPath + ' -> ' + file.url)
}).on('end', function() {
console.log('Done!');
callback(); callback();
}); });
files.pipe(uploader);
}); });

View File

@@ -1,13 +1,18 @@
{ {
"name": "hexo-deployer-ftp", "name": "hexo-deployer-s3",
"version": "0.0.2", "version": "0.0.2",
"description": "FTP deployer plugin for Hexo", "description": "AWS S3 deployer plugin for Hexo",
"main": "index", "main": "index",
"keywords": ["hexo", "ftp"], "keywords": [
"author": "Florian Cargoët", "hexo",
"repository" : { "s3",
"aws",
"deployer"
],
"author": "Josh Strange",
"repository": {
"type": "git", "type": "git",
"url" : "http://github.com/floriancargoet/hexo-deployer-ftp.git" "url": "http://github.com/joshstrange/hexo-deployer-s3.git"
}, },
"license": { "license": {
"type": "MIT" "type": "MIT"
@@ -16,5 +21,9 @@
"hexo": ">= 1.0.0" "hexo": ">= 1.0.0"
}, },
"dependencies": { "dependencies": {
"readdirp": "^0.3.3",
"s3sync": "0.0.3",
"level": "^0.18.0",
"s3-sync": "^0.5.1"
} }
} }