D
D
denis26012018-09-17 20:04:56
Node.js
denis2601, 2018-09-17 20:04:56

Find filename in gulp stream?

There is such a task

/* Paths */
  var src = {
      modules: 'src/modules',
      css: {
        skin: 'src/assets/styles/skins/',
        assets: 'src/assets/styles/'
      }
    },
    dist = {
      css: '../novi/projects/template/css/'
    };
  /* End Paths */

    var assets = skins.map(function (skin) {
      return gulp.src(src.css.assets + '[^_]*.scss')
        .pipe(plugins.addSrc.prepend('src/assets/styles/skins/' + skin + '.scss'))
        .pipe(plugins.concat(FileName + '.scss'))
        .pipe(plugins.sass())
        .pipe(gulp.dest(dist.css + skin + '/assets'));
    });

The essence of the question is this, you need to find out the name of the file being processed in the stream (FileName), in order to enter it into .pipe(plugins.concat(FileName + '.scss'))
without concat, the gulp-add-src (addSrc) plugin refuses to work

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anubis, 2018-09-18
@denis2601

1) npm i --save-dev gulp-tap
2) 3)const tap = require('gulp-tap');

gulp
    .src(...)
    .pipe(tap(file => {
        const path = file.path;
        const data = file.contents.toString();
    }));

Where path is the path to the file relative to the root folder of the project, data is the string content of the file

L
lemix85, 2018-09-17
@lemix85

Of course, I could be wrong, but in my opinion the concat plugin requires the name of the final saved file in which the processed files will be merged, and not the name of the current file to be merged. Those. answer - you can enter any name convenient for you there, have you tried it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question