1

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/'));
});
Leonardo
  • 4,046
  • 5
  • 44
  • 85
  • Why don't you just manually delete all the .js files, then relaunch gulp? It will recompile properly and recreate the relevant files. – Jeremy Thille Jun 13 '16 at 15:50
  • I'm in the middle of creating and deleting multiple files while developing, deleting them manually would break the automation process (for example js injection into index html file) – Leonardo Jun 13 '16 at 15:59
  • Well, if your coffee files get compiled to JS, there's no danger deleting all JS files and just let Gulp rebuild them. Or am I missing something? – Jeremy Thille Jun 13 '16 at 16:01
  • For that matter, you should concatenate and minify everything in one file, and get one script.min.js file. No need for more. – Jeremy Thille Jun 13 '16 at 16:04
  • No, there isn't anything wrong, it's just not automatic and I would do this manually tens of times per day and if I forget to do so I could have injected old files that I do not want – Leonardo Jun 13 '16 at 16:04
  • Your assumption about my dev environment is wrong, I need all the js files because I am in DEV. The min and concat is another build step not relevant here. – Leonardo Jun 13 '16 at 16:08

1 Answers1

1

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; 
        }
    });
});
Leonardo
  • 4,046
  • 5
  • 44
  • 85