Skip to content

Commit

Permalink
Working code
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstrange committed Mar 1, 2014
1 parent 94a9546 commit 8ef4301
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
cache
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
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
this software and associated documentation files (the "Software"), to deal in
Expand Down
29 changes: 14 additions & 15 deletions README.md
@@ -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

### 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

Add `hexo-deployer-ftp` to `plugins` in `_config.yml`.
Add `hexo-deployer-s3` to `plugins` in `_config.yml`.

``` yaml
plugins:
- hexo-deployer-ftp
- hexo-deployer-s3
```

### Configure

Add `host`, `user` and `root` to `deploy` in `_config.yml`.
Add `bucket`, `aws_key` and `aws_secret` to `deploy` in `_config.yml`.

```
deploy:
type: ftp
host: <ftp host>
user: <ftp user>
root: <path/to/your/blog/on/the/server>
type: s3
bucket: <S3 bucket>
aws_key: <AWS id key>
aws_secret: <AWS secret key>
concurrency: <number of connections> //Optional
```

### Disable

Remove `hexo-deployer-ftp` from `plugins` in `_config.yml`.
Remove `hexo-deployer-s3` from `plugins` in `_config.yml`.

``` yaml
plugins:
- hexo-deployer-ftp
- hexo-deployer-s3
```

### Update
Expand All @@ -55,7 +54,7 @@ npm update
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
68 changes: 38 additions & 30 deletions index.js
@@ -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';

// run function which supports interactive commands
function run (command, args, callback) {
process.stdin.pause();
process.stdin.setRawMode(false);

var p = spawn(command, args, {
customFds: [0, 1, 2]
});
return p.on('exit', function() {
process.stdin.setRawMode(true);
process.stdin.resume();
return callback();
});
};
var public_dir = hexo.config.public_dir || './public';


hexo.extend.deployer.register('ftp', function (args, callback) {
hexo.extend.deployer.register('s3', function (args, callback) {
var config = hexo.config.deploy;

if (!config.host || !config.user || !config.root){
if (!config.bucket || !config.aws_key || !config.aws_secret){
var help = [
'You should configure deployment settings in _config.yml first!',
'',
'Example:',
' deploy:',
' type: ftp',
' host: <host>',
' user: <user>',
' root: <root>',
' type: s3',
' bucket: <bucket>',
' aws_key: <aws_key>',
' 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'));
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();
});

files.pipe(uploader);


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

0 comments on commit 8ef4301

Please sign in to comment.