gulp add pipe to convert to Vinyl objects

216 views Asked by At

I have upgraded to gulp 4.0.2 version I need to update one of the tasks

const debug = require('gulp-debug');
const i18nextParser = require('i18next-parser');

function myTask() {
  return gulp
    .src(['./js/**/*.js', './js/**/*.jsx'])
    .pipe(
      i18nextParser({
        locales: ['en', 'de'],
        functions: ['translate'],
        output: '/opt/locales/'
      })
    )
    .pipe(debug())
    .pipe(gulp.dest('/opt/locales/'));
});

I want these files to be converted to Vinyl objects:

[17:04:32] gulp-debug: opt/locales/de/translation.json
[17:04:32] gulp-debug: opt/locales/de/translation_old.json
[17:04:32] gulp-debug: opt/locales/en/translation.json
[17:04:32] gulp-debug: opt/locales/en/translation_old.json

otherwise I have and error

Error: Received a non-Vinyl object in `dest()`

Is there a function that I can pipe to in order to make this task work properly?

i18next-parser version is 0.7.0. Upgrading to latest 3.6.0 version doesn't produce any output at all.

1

There are 1 answers

1
Most Wanted On BEST ANSWER

So I solved this by adding extra step using gulp-map

const map = require('gulp-map');
const Vinyl = require('vinyl');

  return gulp
    .src(['./js/*.js', './js/*.jsx'])
    .pipe(
      i18nextParser({
        locales: ['en', 'de'],
        functions: ['translate'],

        output: JSON_DIR
      })
    )
    .pipe(map(function(file) {
      // Explicitly convert to Vinyl object otherwise `gulp.dest()` will fail
      return new Vinyl(file);
    }))
    .pipe(gulp.dest(JSON_DIR));