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 += ' progress: [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'; help += ' create_before_update: [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, 'progress')) args.progress = true; if (!Object.prototype.hasOwnProperty.call(args, 'ignore_errors')) args.ignore_errors = false; if (!Object.prototype.hasOwnProperty.call(args, 'create_before_update')) args.create_before_update = false;
if (args.verbose) params.unshift('-v'); if (args.ignore_errors) params.unshift('--ignore-errors'); if (args.delete) params.unshift('--delete'); if (args.progress) params.unshift('--progress'); if (args.args) params.unshift(args.args);
if (args.create_before_update) { // Create non-existing files before updating existing files. // New files may be large documents, images and media, and we want to upload them first before updating links to them in the existing pages. // Otherwise, the links may be updated first and temporarily point to new files that have not been uploaded yet. params.unshift('--ignore-existing'); returnspawn('rsync', params, {verbose: true}).then(() => { params.shift(); returnspawn('rsync', params, {verbose: true}); }); } returnspawn('rsync', params, {verbose: true}); };