node.jsftpgulpvinylvinyl-ftp

Gulp vinyl ftp - how to use clean function?


The vinyl-ftp package has a function clean() but I'm not sure how to use it right. I need to:

  1. get all files from my build folder
  2. put them into the target folder on my ftp server
  3. clean files if they're not available locally

I have the following gulp task:

gulp.task('deploy', () => {
  let conn = ftp.create({host:host,user:user,password: password});
  return gulp.src('build/**', {base: './build/', buffer: false })
      .pipe(conn.newer('/path/on/my/server/')) // only upload newer files
      .pipe(conn.dest('/path/on/my/server/'))
      .pipe(conn.clean('build/**', './build/'));
});

1) and 2) is OK, but the clean() function does nothing


Solution

  • The vinyl-ftp docs have this to say:

    conn.clean( globs, local[, options] )

    Globs remote files, tests if they are locally available at <local>/<remote.relative> and removes them if not.

    Note that globs expects a path for the remote files on your FTP server. Since your remote files are located in /path/on/my/server/ you have to specify that path as your glob:

      .pipe(conn.clean('/path/on/my/server/**', './build/'));