gulp-rsync = function (options) { if (typeof options !== 'object') { this.emit( 'error', new PluginError('gulp-rsync', 'options must be an object') ); } if (typeof options.destination !== 'string') { throw new PluginError( 'gulp-rsync', 'destination must be a string to a desired path' ); } var sources = []; var cwd = options.root ? path.resolve(options.root) : process.cwd(); return through.obj(function(file, enc, cb) { if (file.isStream()) { this.emit( 'error', new PluginError('gulp-rsync', 'Streams are not supported!') ); } if (path.relative(cwd, file.path).indexOf('..') === 0) { this.emit( 'error', new PluginError('gulp-rsync', 'Source contains paths outside of root') ); } sources.push(file); cb(null, file); }, function(cb) { sources = sources.filter(function(source) { return !source.isNull() || options.emptyDirectories || (source.path === cwd && options.recursive); }); if (sources.length === 0) { cb(); return; } var shell = options.shell; if (options.port) { shell = 'ssh -p ' + options.port; } var destination = options.destination; if (options.hostname) { destination = options.hostname + ':' + destination; if (options.username) { destination = options.username + '@' + destination; } } else { destination = path.relative(cwd, path.resolve(process.cwd(), destination)); } var config = { options: { 'a': options.archive, 'n': options.dryrun, 'R': options.relative !== false, 'c': options.incremental, 'd': options.emptyDirectories, 'e': shell, 'r': options.recursive && !options.archive, 't': options.times && !options.archive, 'u': options.update, 'v': !options.silent, 'z': options.compress, 'chmod': options.chmod, 'exclude': options.exclude, 'include': options.include, 'progress': options.progress, 'links': options.links }, source: sources.map(function(source) { return path.relative(cwd, source.path) || '.'; }), destination: destination, cwd: cwd }; if (options.options) { for (var key in options.options) { config.options[key] = options.options[key]; } } if (options.clean) { if (!options.recursive && !options.archive) { this.emit( 'error', new PluginError('gulp-rsync', 'clean requires recursive or archive option') ); } config.options['delete'] = true; } if (!options.silent) { var handler = function(data) { data.toString().split('\r').forEach(function(chunk) { chunk.split('\n').forEach(function(line, j, lines) { log('gulp-rsync:', line, (j < lines.length - 1 ? '\n' : '')); }); }); }; config.stdoutHandler = handler; config.stderrHandler = handler; gutil.log('gulp-rsync:', 'Starting rsync to ' + destination + '...'); } rsync(config).execute(function(error, command) { if (error) { this.emit('error', new PluginError('gulp-rsync', error.stack)); } if (options.command) { gutil.log(command); } if (!options.silent) { gutil.log('gulp-rsync:', 'Completed rsync.'); } cb(); }.bind(this)); }); }
n/a
function rsync(config) { if (!(this instanceof rsync)) { return new rsync(config); } assert(typeof config === 'object'); assert(!config.options || typeof config.options === 'object'); this._options = config.options || {}; var sources = config.source; if (!Array.isArray(sources)) { sources = [sources]; } assert(sources.length > 0 && every(sources, isString)); assert(sources.length === 1 || config.destination); this._sources = sources; assert(!config.destination || typeof config.destination === 'string'); this._destination = config.destination; assert(!config.cwd || typeof config.cwd === 'string'); this._cwd = config.cwd; assert(!config.stdoutHandler || typeof config.stdoutHandler === 'function'); this._stdout = config.stdoutHandler; assert(!config.stderrHandler || typeof config.stderrHandler === 'function'); this._stderr = config.stderrHandler; return this; }
n/a
function rsync(config) { if (!(this instanceof rsync)) { return new rsync(config); } assert(typeof config === 'object'); assert(!config.options || typeof config.options === 'object'); this._options = config.options || {}; var sources = config.source; if (!Array.isArray(sources)) { sources = [sources]; } assert(sources.length > 0 && every(sources, isString)); assert(sources.length === 1 || config.destination); this._sources = sources; assert(!config.destination || typeof config.destination === 'string'); this._destination = config.destination; assert(!config.cwd || typeof config.cwd === 'string'); this._cwd = config.cwd; assert(!config.stdoutHandler || typeof config.stdoutHandler === 'function'); this._stdout = config.stdoutHandler; assert(!config.stderrHandler || typeof config.stderrHandler === 'function'); this._stderr = config.stderrHandler; return this; }
n/a
command = function () { var args = []; var shortOptions = []; var longOptions = []; for (var key in this._options) { var value = this._options[key]; if (typeof value !== 'undefined' && value !== false) { if (key.length === 1 && value === true) { shortOptions.push(key); } else { var values = Array.isArray(value) ? value : [value]; for (var i = 0, l = values.length; i < l; i++) { longOptions.push({key: key, value: values[i]}); } } } } if (shortOptions.length > 0) { args.push('-' + shortOptions.join('')); } if (longOptions.length > 0) { args = args.concat(longOptions.map(function(option) { var single = option.key.length === 1; var output = (single ? '-' : '--') + option.key; if (typeof option.value !== 'boolean') { output += (single ? ' ' : '=') + escapeShellArg(option.value); } return output; })); } args = args.concat(this._sources.map(escapeShellArg)); if (this._destination) { args.push(escapeShellArg(this._destination)); } return 'rsync ' + args.join(' '); }
...
args.push(escapeShellArg(this._destination));
}
return 'rsync ' + args.join(' ');
},
execute: function(callback) {
var command = this.command();
var childProcess;
if (process.platform === 'win32') {
childProcess = spawn('cmd.exe', ['/s', '/c', '"' + command + '"'], {
cwd: this._cwd,
stdio: [process.stdin, 'pipe', 'pipe'],
env: process.env,
...
execute = function (callback) { var command = this.command(); var childProcess; if (process.platform === 'win32') { childProcess = spawn('cmd.exe', ['/s', '/c', '"' + command + '"'], { cwd: this._cwd, stdio: [process.stdin, 'pipe', 'pipe'], env: process.env, windowsVerbatimArguments: true }); } else { childProcess = spawn('/bin/sh', ['-c', command], { cwd: this._cwd, stdio: 'pipe', env: process.env }); } if (this._stdout) { childProcess.stdout.on('data', this._stdout); } if (this._stderr) { childProcess.stderr.on('data', this._stderr); } childProcess.on('close', function(code) { var error = null; if (code !== 0) { error = new Error('rsync exited with code ' + code); } if (typeof callback === 'function') { callback(error, command); } }); return childProcess; }
...
};
config.stdoutHandler = handler;
config.stderrHandler = handler;
gutil.log('gulp-rsync:', 'Starting rsync to ' + destination + '...');
}
rsync(config).execute(function(error, command) {
if (error) {
this.emit('error', new PluginError('gulp-rsync', error.stack));
}
if (options.command) {
gutil.log(command);
}
if (!options.silent) {
...