Heymdall
Heymdall

Reputation: 71

Overwrite file in gulp stream

I have following directory structure:

common
-services
--service1.js
--service2.js
-app
--gulpfile.js
--src
---services
----service1.js
----service3.js

I want to made gulp task that will take all files from common directory, take files from app directory and replace all files with same filenames in original stream. After that I will concat it and write to other directory. I tried this:

var gulp = require('gulp'),
    merge = require('gulp-merge'),
    concat = require('gulp-concat');
 gulp.task('templates', function () {
  return merge(
    gulp.src(['../common/**/*.js']),
    gulp.src(['src/**/*.js'])
  )
    .pipe(concat('app.js'))
    .pipe(gulp.dest('build/js'));
});

I expected to got content of common/services/service2.js, app/src/services/service1.js, app/src/services/service3.js in dest/app.js. But instead I've got content of all files. I tried to change cwd or base of gulp.src, but it has no effect. I know that I can write this stream to tmp directory, and after that get files from it, but it seems not really like gulp-style solution. So how can I overwrite files with same file names in streams?

Upvotes: 3

Views: 1490

Answers (1)

Heymdall
Heymdall

Reputation: 71

Ok, i can't find any existing solution for that, so I write my own gulp plugin: gulp-unique-files.

Upvotes: 4

Related Questions