diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..02d2255 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +cache \ No newline at end of file diff --git a/LICENSE b/LICENSE index 03424f3..c77e11a 100644 --- a/LICENSE +++ b/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 diff --git a/README.md b/README.md index 2f9bdf2..445e967 100644 --- a/README.md +++ b/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: - user: - root: + type: s3 + bucket: + aws_key: + aws_secret: + concurrency: //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 @@ -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 \ No newline at end of file diff --git a/index.js b/index.js index 20d2c0b..170dcd6 100644 --- a/index.js +++ b/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(); - }); -}; - -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: ', - ' user: ', - ' root: ', + ' type: s3', + ' bucket: ', + ' aws_key: ', + ' aws_secret: ', + ' [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); + + }); diff --git a/package.json b/package.json index 84d7fd9..cf6e18c 100644 --- a/package.json +++ b/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" @@ -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" } }