commit c85c1a6a62feb5e2020f6ff1458eda7cd993f9e5 Author: Florian Cargoët Date: Sun Nov 24 23:41:24 2013 +0100 initial commit diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..abae2e5 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +.git* +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4cfbb89 --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +# FTP deployer plugin for [Hexo] + +This plugin can deploy your blog via FTP. + +## Usage + +### Install + +``` +npm install hexo-deployer-ftp --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`. + +``` yaml +plugins: +- hexo-deployer-ftp +``` + +### Configure + +Add `host`, `user` and `root` to `deploy` in `_config.yml`. + +``` +deploy: + type: ftp + host: + user: + root: +``` + +### Disable + +Remove `hexo-deployer-ftp` from `plugins` in `_config.yml`. + +``` yaml +plugins: +- hexo-deployer-ftp +``` + +### 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-ftp +``` + +[Hexo]: http://zespia.tw/hexo \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..d159acc --- /dev/null +++ b/index.js @@ -0,0 +1,50 @@ +var spawn = require('child_process').spawn; + +// 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) { + var config = hexo.config.deploy; + + if (!config.host || !config.user || !config.root){ + var help = [ + 'You should configure deployment settings in _config.yml first!', + '', + 'Example:', + ' deploy:', + ' type: ftp', + ' host: ', + ' user: ', + ' root: ', + '', + 'For more help, you can check the docs: ' + 'http://zespia.tw/hexo/docs/deployment.html' + ]; + + console.log(help.join('\n')); + return callback(); + } + + var args = [ + '-e', + 'mirror -R --ignore-time --delete -v ./public ' + config.root + '; bye', + '-u', + config.user, + config.host + ]; + + run('lftp', args, function (code) { + callback(); + }); +}); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..42230f2 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "hexo-deployer-ftp", + "version": "0.0.1", + "description": "FTP deployer plugin for Hexo", + "main": "index", + "keywords": ["website", "blog", "cms", "framework", "hexo", "ftp"], + "author": "Florian Cargoët", + "repository" : "floriancargoet/hexo-deployer-ftp", + "license": { + "type": "MIT" + }, + "engines": { + "hexo": ">= 1.0.0" + }, + "dependencies": { + } +}