-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdeployer.js
62 lines (53 loc) · 2.19 KB
/
deployer.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
const color = require('picocolors');
const spawn = require('hexo-util/lib/spawn');
const pathFn = require('path');
module.exports = function(args) {
if (!args.host || !args.user || !args.root) {
let help = '';
help += 'You should configure deployment settings in _config.yml first!\n\n';
help += 'Example:\n';
help += ' deploy:\n';
help += ' type: rsync\n';
help += ' host: <host>\n';
help += ' user: <user>\n';
help += ' root: <root>\n';
help += ' port: [port] # Default is 22\n';
help += ' delete: [true|false] # Default is true\n';
help += ' args: <rsync args>\n';
help += ' rsh: <remote shell>\n';
help += ' key: <key>\n';
help += ' verbose: [true|false] # Default is true\n';
help += ' ignore_errors: [true|false] # Default is false\n\n';
help += 'For more help, you can check the docs: ' + color.underline('https://hexo.io/docs/deployment.html');
console.log(help);
return;
}
if (!Object.prototype.hasOwnProperty.call(args, 'delete')) args.delete = true;
if (!Object.prototype.hasOwnProperty.call(args, 'verbose')) args.verbose = true;
if (!Object.prototype.hasOwnProperty.call(args, 'ignore_errors')) args.ignore_errors = false;
const params = [
'-az',
process.platform === 'win32' ? pathFn.basename(this.public_dir) + '/' : this.public_dir,
args.user + '@' + args.host + ':' + args.root
];
if (args.port && args.port > 0 && args.port < 65536) {
params.splice(params.length - 2, 0, '-e');
if (args.rsh) {
if (args.key) {
params.splice(params.length - 2, 0, `'${args.rsh}' -i ${args.key} -p ${args.port}`);
} else {
params.splice(params.length - 2, 0, `'${args.rsh}' -p ${args.port}`);
}
} else if (args.key) {
params.splice(params.length - 2, 0, 'ssh -i ' + args.key + ' -p ' + args.port);
} else {
params.splice(params.length - 2, 0, 'ssh -p ' + args.port);
}
}
if (args.verbose) params.unshift('-v');
if (args.ignore_errors) params.unshift('--ignore-errors');
if (args.delete) params.unshift('--delete');
if (args.args) params.unshift(args.args);
return spawn('rsync', params, {verbose: true});
};