Search code examples
javascriptnode.jsgulpcopytask

Gulp is not overwriting JS files


I have a problem when I try to overwrite a file with gulp. To make you understand my problem here's an example of what I am trying to do: My project file path:

- Project
 |- clients
   |- clientBase
     |- JS
       |- jsexample.js
       |- jsexample2.js
     |- CSS
     |- HTML
   |- client1
     |- JS
       |- jsexample2.js
 |-dist
  1. Copy the base source to dist.
  2. Copy the custom client source and overwrite what's in the dist folder.

What am I doing

const args = require('yargs').argv;
const src = {
  base: './Project/clients/clientBase',
  client: `./Project/clients/${args.client}`,
};
const dist = './Project/dist';
const runSequence = require('run-sequence');

gulp.task('copy:base', function(){
  return gulp
    .src(`${src.base}/**/*`)
    .pipe(gulp.dest(dist))
});

gulp.task('copy:client', function(){
  return gulp
    .src(`${src.client}/**/*`)
    .pipe(gulp.dest(dist))
});

gulp.task('copy', function(){
  if (args.client) {
    runSequence('copy:base', 'copy:client');
  } else {
    runSequence('copy:base');
  }
});

The actual problem

The problem is that the dist files are not being overwritten by the copy:client task.

What I've checked already

I've checked the file path and the content inside the files. The argument client is being passed to, so this task is being executed.


Solution

  • After some more research, I noticed that in my task sequence chain in the default task, there was another task copying again the base code, without any logging.