gulp-rsync忽略符号链接

时间:2018-07-12 09:36:52

标签: gulp

我要同步包含符号链接的目录。此链接应作为符号链接进行传输。

gulp-rsync的文档说明了似乎涵盖了此内容的选项links

gulp.src(不支持符号链接)的第一个问题可以通过使用vinyl-fs来解决。除了符号链接(尽管已由gulpDebug()列出)以外,其他符号链接都可以正常工作。

使用过的gulpfile.js任务如下:

const gulp = require('gulp'),
      gulpDebug = require('gulp-debug'),
      merge = require('merge-stream'),
      rsync = require('gulp-rsync'),
      vfs = require('vinyl-fs');

gulp.task('rsyncFiles', function (done) {
    const rsyncSrcClient =
        vfs.src('src/**')
            .pipe(gulpDebug())
            .pipe(rsync({
                root: 'src/',
                hostname: remoteHostname,
                destination: remoteTargetDir + '/src/',
                links: true
            }));

    return merge(rsyncSrcClient);
});

从外壳手动使用rsync --link ...可以按需工作,符号链接将作为符号链接进行传输。

1 个答案:

答案 0 :(得分:0)

添加选项 emptyDirectories: true 解决了该问题。

gulpfile.js现在是:

gulp.task('rsyncFiles', function (done) {
    const rsyncSrcClient =
        vfs.src('src/**')
            .pipe(gulpDebug())
            .pipe(rsync({
                root: 'src/',
                hostname: remoteHostname,
                destination: remoteTargetDir + '/src/',
                links: true,
                emptyDirectories: true
            }));

    return merge(rsyncSrcClient);
});

原因是文件node_modules/gulp-rsync/index.js中的过滤机制。

index.js#L49上有以下源代码片段,对于符号链接始终为false

sources = sources.filter(function(source) {
    return !source.isNull() ||
           options.emptyDirectories ||
           (source.path === cwd && options.recursive);
});

添加选项emptyDirectories: true可以将此行为更改为符号链接的结果true。符号链接不再被过滤掉,rsync正在根据需要传输链接。

相关问题