Use the file transferring and syncing capabilities of rsync within your Gulp task. gulp-rsync calls rsync and offers you a subset of options for an easy setup.
Prerequisites
rsync needs to be installed on your machine and must be sitting in your PATH.
Note that rsync does not synchronize your build/-directory if you give it a trailing /.
rsync OPTIONS
rsync-gulp implements the following options of rsync. See the official documentation for more information.
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
-c, --checksum skip based on checksum, not mod-time & size
-d, --dirs transfer directories without recursing
-e, --rsh=COMMAND specify the remote shell to use
-n, --dry-run perform a trial run with no changes made
-r, --recursive recurse into directories
-t, --times preserve modification times
-u, --update skip files that are newer on the receiver
-v, --verbose increase verbosity
-z, --compress compress file data during the transfer
--chmod affect file and/or directory permissions
--delete delete extraneous files from destination dirs
--exclude=PATTERN exclude files matching PATTERN
--include=PATTERN don't exclude files matching PATTERN
--port=PORT specify double-colon alternate port number
--progress show progress during transfer
Windows users
When you are syncing from Windows to Unix you might encounter permission errors or issues resulting from these. A reason can be that rsync tries to preserve NTFS file attributes in UNIX. This behaviour can be remedied by:
chmod: "ugo=rwX"
So, if you are running rsync on Windows put this option in place.
API
rsync(options)
options
destination
Type: string, Required
The destination path. Use hostname when using a remote path.
root
Type: string, Default: process.cwd()
Specifying a root path changes the path names that are transferred to the
destination. The paths piped into rsync must be within the root path (or the
plugin will yell at you).
The hostname of the destination. rsync will connect to this hostname using SSH
along with configuration in ~/.ssh/config or SSH keys stored in a keychain.
When this is omitted, rsync will transfer the content to a local path.
username
Type: string
Used to specify a user for the remote host.
shell
Type: string, Compares to: rsync -e
Typically, rsync is configured to use ssh by default, but you may prefer to
use rsh on a local network.
port
Type: integer
Used to specify an SSH port for the remote host. Note: This will override the
shell option and force the use ssh in rsync -e ssh --port=PORT.
archive
Type: boolean, Default: false, Compares to: rsync -a
If set to true, rsync will turn on the archive mode which equals -rlptgoD:
-r, --recursive recurse into directories
-l, --links copy symlinks as symlinks
-p, --perms preserve permissions
-t, --times preserve modification times
-g, --group preserve group
-o, --owner preserve owner (super-user only)
-D same as --devices --specials
--devices preserve device files (super-user only)
--specials preserve special files
dryrun
Type: boolean, Default: false, Compares to: rsync -n
If set to true, rsync will do everything it does without actually syncing.
incremental
Type: boolean, Default: false, Compares to: rsync -c
If set to true, rsync will make incremental updates only. rsync will use the checksum of every file to determine whether a file needs to be updated. This will add a delay to the transfer, but will minimize the amount of files
transferred each time.
progress
Type: boolean, Default: false, Compares to: rsync --progress
If set to true, the transfer progress for each file will be displayed in the
console.
Type: boolean, Default: true, Compares to: rsync -R
By default, gulp-rsync will transfer all paths relative to the root specified.
If you want to transfer assets from multiple paths to a single destination, you
can set relative to false.
This will transfer all assets (*.js, *.css, and images) into a single directory.
emptyDirectories
Type: boolean, Default: false, Compares to: rsync -d
If set to true, rsync will create empty directories.
times
Type: boolean, Default: false, Compares to: rsync -t
Preserves times of the transferred files.
compress
Type: boolean, Default: false, Compares to: rsync -z
Compresses file data during transfer.
recursive
Type: boolean, Default: false
If set to true, rsync will transfer all files and subdirectories recursively.
This is not necessary when using glob(s) with gulp.src(). However, it can be
combined with non-globbed paths to transfer all files:
The difference is that the actual rsync command used in the first example is
much shorter.
clean
Type: boolean, Default: false, Compares to: rsync --delete
This must be used with archive or recursive set to true. If set to true, this instructs rsync to delete all files and directories that are not in the source paths. Be careful with this option as it could lead to data loss.
chmod
Type: string, Compares to: rsync --chmod=STRING
Enables files or directories matching the pattern(s) provided to be excluded
from the transfer. This is probably most useful when recursive is set to
true since it is typically better to make these exclusions in gulp.src().
chown
Type: string, Compares to: rsync --chown=STRING
Forces all remote files to be owned by the USER:GROUP provided in the string. If GROUP is empty, the trailing colon may be omitted, but if USER is empty, a leading colon must be supplied. If you're running macOS please check your rsync version with rsync --version. The default system version, older than 3.1.0, doesn't support this option. You can fix this by installing a recent version from Brew (brew install homebrew/dupes/rsync) or MacPorts (sudo port install rsync).
exclude
Type: string|Array<string>, Compares to: rsync --exclude=PATTERN
Enables files or directories matching the pattern(s) provided to be excluded
from the transfer. This is probably most useful when recursive is set to
true since it is typically better to make these exclusions in gulp.src().
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
请发表评论