V
V
vohaha2016-03-31 18:05:15
JavaScript
vohaha, 2016-03-31 18:05:15

How to complete a task in gulp 4?

First there was an error: ce78296fda.jpg
Then I added a callback and now here it is: f08117f13f.jpg
Task:

'use strict';

var $ = require('gulp-load-plugins')();
var gulp = require('gulp');
// var path = require('path');
var merge = require('merge-stream');

module.exports = function(options) {

    return function(cb) {

        return $.folders('./app/images', function (folder) {

            var folderCheck = new RegExp(options.spriteFolderPrefix, 'g'),
                imgStream,
                cssStream,
                spriteStream;

            if (folder.match(folderCheck)) {

                var spriteData = gulp.src('app/images/ico-first/*.png')
                    .pipe($.spritesmith({
                        imgName: options.imgPrefix + folder + '.png',
                        cssName: options.stylesPrefix + folder + '.scss'
                    }));
                imgStream = spriteData.img
                    .pipe(gulp.dest(options.imgDest));
                cssStream = spriteData.css
                    .pipe(gulp.dest(options.stylesDest));

                spriteStream = merge(imgStream, cssStream);

                return spriteStream;
            }
            
        }, cb())(); // в консоле ошибку выдает на эту строку, начиная с последних скобок
    };

};

I call like this:
function lazyRequireTask(taskName, path, options) {
    options = options || {};
    options.taskName = taskName;
    gulp.task(taskName, function(callback) {
        var task = require(path).call(this, options);

        return task(callback); // в консоле ошибку выдает на эту строку, начиная с "task"
    });
}

lazyRequireTask('img:sprite', './tasks/img-sprite', {
    src: 'src'
    spriteFolderPrefix: 'ico-',
    imgPrefix: 'sprite-',
    stylesPrefix: 'sprite-',
    imgDest: 'images',
    stylesDest: 'styles'
});

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2016-04-01
@abberati

Promise, return or callback.
I won’t explain in detail, I didn’t fully move to 4k myself.
Here is a wonderful screencast on 4ke, everything is there. That's all right, even the answer to this question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question