Async Gulp任务不会启动

时间:2015-05-19 19:30:13

标签: javascript gulp

我正在尝试在任务中创建一个循环,但是该任务不想启动。这是我的实际代码:

var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var gfi = require("gulp-file-insert");
var fs = require('fs');

gulp.task('modules', function() {

    var i = 0;

    var functionCases = [
        "functions",
        "document.ready",
        "window.load",
        "document.scroll",
        "window.resize"
    ];

    function forloop(){
        if( i < functionCases.length ){

            var bermuda = function(){
                if ( i == 0 ) {
                    var source = "js/modules/modules.js";
                    console.log("não existe");
                } else{
                    var source = "generator/assets/js/modules.js";
                    console.log("existe");
                }
                return source;
            }

            gulp.src('js/modules/**/' + functionCases[i] + '.js')
                .pipe(concat('' + functionCases[i] + '.js'))
                .pipe(gulp.dest('generator/assets/js'))
                .on('end',function(){
                    var gfiInput = {};
                    gfiInput["/* "+ functionCases[i] + " */"] = "generator/assets/js/" + functionCases[i] + ".js";
                    gulp.src(bermuda())
                        .pipe(gfi(gfiInput))
                        .pipe(gulp.dest('generator/assets/js'))
                        .on("end", function(){
                            i++;
                        });
                });

            forloop();

        }else{
            console.log("all done");
        }
    }

    forloop();

});

知道可能会发生什么吗?

0 个答案:

没有答案