forked from hexojs/hexo-deployer-rsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var chalk = require('chalk')
var spawn = require('hexo-util/lib/spawn')
var pathFn = require('path')
var url = require('url')
module.exports = function (src, opts, fn) {
if (!opts.destination) {
return fn(new Error('The rsync output needs a destination.'))
}
if (!opts.hasOwnProperty('delete')) opts.delete = true
if (!opts.hasOwnProperty('verbose')) opts.verbose = true
if (!opts.hasOwnProperty('ignore_errors')) opts.ignore_errors = false
var uri = url.parse(opts.destination)
var params = [
'-az',
(process.platform === 'win32' ? pathFn.basename(src) : src) + '/',
(uri.username ? uri.username + '@' : '') + uri.hostname + ':' + uri.pathname
]
if (uri.port && uri.port > 0 && uri.port < 65536) {
params.splice(params.length - 2, 0, '-e')
params.splice(params.length - 2, 0, 'ssh -p ' + uri.port)
}
if (opts.verbose) params.unshift('-v')
if (opts.ignore_errors) params.unshift('--ignore-errors')
if (opts.delete) params.unshift('--delete')
if (opts.opts) params.unshift(opts.opts)
return spawn('rsync', params, {verbose: true}).then(output => {
fn(null, true)
})
}