javascriptbuildcoffeescriptgulpgulp-plugin

Gulp-coffee remove nonexistent files


I'm using gulp-coffee to compile my coffee files to js, nothing fancy.

I'm having a hard time figuring how to remove js files (in the dest js directory) that DO NOT exist anymore in the source coffee folder.

I'm quite sure this does not concern directly gulp-coffee, but I'm kind of clueless and I'm not that proficient in gulp.

My Files structure

/app/
  /coffee (source)
  /js     (dest)

My gulp task

gulp.task('coffee', function() {
    return gulp.src('app/coffee/**/*.coffee')
    .pipe($.changed('./app/js/', {extension: '.js'}))
    .pipe($.coffee())
        .on('error', logCoffeeError)
    .pipe(gulp.dest('app/js/'));
});

Solution

  • If anybody is interested on the solution of this problem I ended up using this package that does exactly what I was looking for: https://github.com/StevenTheEVILZ/gulp-syncronize

    USAGE:

    gulp.task('unused', function() {
        return syncronize({
            src:    'app/coffee/',  //Source folder
            target: 'app/js/',      //Output folder
            extensions: {
                'js': 'coffee', // Corresponds .js files to the .coffee files; 
            }
        });
    });