F
F
Fulminant2016-08-19 17:29:55
JavaScript
Fulminant, 2016-08-19 17:29:55

How to concatenate files with the same name using Gulp?

As an example, we have the following directory with JSON files:

test/
  dir1/
    test.json
    test2.json
  dir2/
    test.json
    test2.json

so, here, the essence of the question is how to get the output of the concatenated file test.jsonand, test2.json accordingly.
With plugins for gulp
gulp-foreach
and
gulp-merge-json
I came up with this one:
return gulp.src('test/**/*.json')
        .pipe(foreach((stream, file) => {
            return stream
                .pipe(merge(`${path.basename(file.path)}`));
        }))
        .pipe(gulp.dest(`куданибудь/`));

but the problem is that only the latest files are taken, in this case it would be all files from the dir2.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question