Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 975
Max Vorozhcov Avatar asked Dec 18 '22 10:12

Max Vorozhcov


2 Answers

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/'));
like image 162
Sven Schoenung Avatar answered Feb 13 '23 00:02

Sven Schoenung


Since I got a lot of struggle with this, here a working peace of code. It removes all files from the server that dont exist locally except the usage folder:

var connection = ftp.create({ ... });

connection.clean([
    '/*.*',
    '/!(usage)*',
    '/de/**',
    '/en/**',
    '/images/**',
    '/fonts/**',
    '/json/**',
    '/sounds/**'
], './dist', { base: '/' });

My files are locally on the ./dist folder and remote directly in the root directory (/) (of the used ftp user).

like image 20
Thomas Kekeisen Avatar answered Feb 12 '23 23:02

Thomas Kekeisen