借用闭包，处理gulp的task中index
482858
function _createCSSTask(gulp, name, config, depTasks, index, startFun, endFun) {
    gulp.task(name, depTasks, function(){
        var s = config.css[index];
       return runCSSTaskStream(gulp, s, config, startFun, endFun);
    });
}
922820
function loadGulpConfig(gulp, options){
	options = Object.assign({ data:{} }, options);
	options.dirs = isObject(options.dirs) ? options.dirs : {};
	options.configPath = isString(options.configPath) ? options.configPath : 'tasks';
	glob.sync(options.configPath, { realpath:true }).forEach(filterFiles.bind(this, gulp, options));
	loadGulpConfig.util.dir = rgdirs(options.dirs);
}
796347
function (pipe) {
        var tasks = [];

        _.forEach(plumber.sieve(pipe.content, 'statics'), function (file, key) {
            tasks.push(glob('**/*.*', {cwd: path.resolve(pipe.contentDir, key)})
                .then(function (files) {
                    pipe.content[key].files = files;
                }));
        });

        return Bluebird.all(tasks).return(pipe);
    }
331190
public void startPipeline(NodeTask nodeTask) {
        Long pipelineId = nodeTask.getPipeline().getId();
        releasePipeline(pipelineId);
        Map<StageType, GlobalTask> tasks = controllers.get(pipelineId);
        // 处理具体的任务命令
        List<StageType> stage = nodeTask.getStage();
        List<TaskEvent> event = nodeTask.getEvent();
        for (int i = 0; i < stage.size(); i++) {
            StageType stageType = stage.get(i);
            TaskEvent taskEvent = event.get(i);
            if (taskEvent.isCreate()) {
                startTask(nodeTask.getPipeline(), tasks, stageType);
            } else {
                stopTask(tasks, stageType);
            }
        }
    }
28404
function xinclude(file, encoding, callback) {
    if (!file) {
        throw new PluginError('gulp-xinclude', '文件为没有对应的文件');
    }

    if(file.isStream()) {
        throw new PluginError('gulp-xinclude', '只支持html文件中<!--xinclude command=xxx-->类型指令。');
    }

    processFile(file, encoding)
    this.push(file);
    callback();
}
299051
function(tasksConfig) {
  /* JS linting  */
  gulp.task('lint', extendDeps([], tasksConfig.lint), function() {
    return gulp.src(extendSrcs([
      paths.src.js,
      paths.src.es6
    ], tasksConfig.lint))
    .pipe($.jshint({
      lookup: true
    }))
    .pipe($.jshint.reporter('jshint-stylish'));
  });
  gulp.task('lint:blocker', extendDeps([], tasksConfig.lint), function() {
    return gulp.src(extendSrcs([
      paths.src.js,
      paths.src.es6
    ], tasksConfig.lint))
    .pipe($.jshint({
      lookup: true
    }))
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.jshint.reporter('fail'));
  });

  /* JS validation  */
  gulp.task('jsvalidate:blocker', ['babelify'], function () {
    return gulp.src(extendSrcs([
      paths.src.tmp + '**/*.js',
      paths.src.tmp + '**/*' + paths.src.esnextExt,
      '!' + paths.src.tmp + '**/*.test.js',
      '!' + paths.src.tmp + '**/*.test' + paths.src.esnextExt
    ], tasksConfig.lint))
    .pipe($.jsvalidate());
  });
  gulp.task('jsvalidate:blocker:clean', ['jsvalidate:blocker'], cleanTmp);

  /* JS unit tests runner  */
  gulp.task('karma', function() {
    return gulp.src([
      'tricky/freaky/trick/**/*.js'
    ])
    .pipe($.karma({
      configFile: 'karma.conf.js',
      action: 'run'
    }))
    .on('error', function(/*err*/) {
      // throw err;
    });
  });
  gulp.task('karma:dev', function() {
    return gulp.src([
      'tricky/freaky/trick/**/*.js'
    ])
    .pipe($.karma({
      configFile: 'karma.conf.js',
      action: 'watch'
    }))
    .on('error', function(/*err*/) {
      // throw err;
    });
  });
}
522798
function(tasks, callback) {

      if (!isArray(tasks)) return callback();

      var length = tasks.length;
      var results = [];

      function runTask(index) {
        tasks[index](function(err, result) {
          if (err) return callback(err);
          results[index] = result;
          if (index < length - 1) return runTask(index + 1);
          return callback(null, results);
        });
      }

      runTask(0);
    }
692066
function loadTask(fileName, taskName) {
  const taskModule = require('./tools/gulp-tasks/' + fileName);
  const task = taskName ? taskModule[taskName] : taskModule;
  return task(gulp);
}
116687
function Devour(settings) {
	var devour = this,
		gulp = require('gulp'),
		glob = require('glob'),
		chalk = require('chalk'),
		submerge = require('submerge'),
		polymorphic = require('polymorphic'),
		Wanted = require('wanted'),
		chain = require('gulp-chain'),
		watcher = require('gulp-watch'),
		wanted = new Wanted(),
		definitions = {},
		run = process.argv.splice(2),
		config = submerge(settings, {
			debounce: 100,
			basePath: process.cwd(),
			gulpFiles: 'gulp',
			output: 'dist',
			verbose: !run.length
		}),
		active = [];

	/**
	 *  Initialize Devour
	 *  @name    init
	 *  @access  internal
	 *  @return  void
	 */
	function init() {
		Object.defineProperty(devour, 'gulp', {
			enumerable: true,
			value: gulp
		});

		preload();
	}

	/**
	 *  Load all available tasks and pipes
	 *  @name    preload
	 *  @access  internal
	 *  @return  void
	 */
	function preload() {
		var path = config.gulpFiles;

		if (/^[^\/]/.test(path)) {
			path = config.basePath + '/' + path;
		}

		glob.sync(path + '/*/*.js').map(function(file) {
			return file.replace(path, '').split('/').filter(function(split) {
				return !!split;
			});
		}).forEach(function(file) {
			register(
				file[0],
				file[file.length - 1].replace(/\.js$/, ''),
				require(path + '/' + file.join('/'))
			);
		});

		console.log(chalk.cyan('Devour initialized'));

		if (config.verbose) {
			['task', 'pipe'].forEach(function(what) {
				console.log(
					'  - available %ss: %s',
					what,
					what in definitions ? chalk.green(Object.keys(definitions[what]).join(', ')) : chalk.yellow('none')
				);
			});
			console.log('');
		}
	}

	/**
	 *  Register a task or pipe
	 *  @name    resgister
	 *  @access  internal
	 *  @param   string type [accepts any value, actual values: 'task' or 'pipe']
	 *  @param   string name
	 *  @param   function create
	 *  @return  void
	 */
	function register(type, name, create) {
		if (!(type in definitions)) {
			definitions[type] = {};
		}

		if (type === 'pipe') {
			create = chain(create, devour);
		}

		definitions[type][name] = create;
	}

	/**
	 *  Obtain a gulp plugin, initialized with given arguments
	 *  @name    plug
	 *  @access  internal
	 *  @param   string  name [automatically prefixed with 'gulp-']
	 *  @return  stream  initialized plugin
	 */
	function plug(name) {
		var part, scope;

		if (!('buffer' in plug.prototype)) {
			plug.prototype.buffer = {};
		}

		part  = name.split('.');
		scope = part.shift();

		if (!(scope in plug.prototype.buffer)) {
			plug.prototype.buffer[scope] = wanted.require('gulp-' + scope);
		}

		scope = plug.prototype.buffer[scope];

		part.forEach(function(p) {
			scope = scope[p];
		});

		//  this may be an a-typical gulp plugin (e.g. sourcemaps) which provides no stream, the implementer probably
		//  knows what to do with this
		if (typeof scope !== 'function') {
			return scope;
		}

		//  invoke the function in the scope with the arguments after the name
		//  this should create a stream
		return scope.apply(null, Array.prototype.slice.call(arguments, 1))
			//  always register an error listener for plugins
			.on('error', function(error) {
				console.error('Error from plugin %s: %s', chalk.red(name), error);
				this.emit('end');
			})
		;
	}

	/**
	 *  Start tasks provided from the command line
	 *  @name    startRequested
	 *  @access  internal
	 *  @return  bool  started
	 */
	function startRequested() {
		var start = [];

		if (run.length) {
			run.forEach(function(task) {
				var exists = task.replace(/:.*$/, '') in definitions.task;

				console.log(
					'Task %s %s',
					exists ? chalk.green(task) : chalk.red(task),
					exists ? 'running' : 'not found!'
				);

				if (exists) {
					start.push(task);
				}
			});

			if (start.length) {
				gulp.start.apply(gulp, start.concat([function(error) {
					if (error) {
						throw new Error(error);
					}

					console.log('Complete');
				}]));
			}
			else {
				console.log(chalk.red('No tasks are running, exiting!'));
				process.exit(1);
			}
		}

		return !!start.length;
	}

	/**
	 *  Create a plugin and initialize it
	 *  @name    plugin
	 *  @access  public
	 *  @param   mixed   arguments
	 *  @return  stream
	 */
	devour.plugin = plug;

	/**
	 *  Cleanup file basename and append .min to it
	 *  @name    min
	 *  @access  public
	 *  @param   object  file
	 *  @return  void
	 */
	devour.min = function(file) {
		file.basename = file.basename.replace(/\.(?:min|prep)/, '') + '.min';
	};

	/**
	 *  Require a module, trying to install it if not available
	 *  @name    require
	 *  @access  public
	 *  @param   string    module
	 *  @return  function  module
	 */
	devour.require = function(module) {
		return wanted.require(module);
	};

	/**
	 *  Create a source list and pipe it through the 'defaults' pipe
	 *  @name    source
	 *  @access  public
	 *  @param   mixed sources [one of: string, array]
	 *  @return  stream
	 */
	devour.source = function() {
		var source = gulp.src.apply(gulp, arguments);

		if ('defaults' in config) {
			config.defaults.forEach(function(name) {
				source = source.pipe(devour.plugin(name));
			});
		}

		return source;
	};

	/**
	 *  Invoke the predefined pipe and return its stream
	 *  @name    pipe
	 *  @access  public
	 *  @param   string  pipe
	 *  @return  stream
	 */
	devour.pipe = function() {
		var arg = Array.prototype.slice.call(arguments),
			name = arg.shift();

		if ('pipe' in definitions && name in definitions.pipe) {
			if (+config.verbose > 2) {
				console.log('  - Laying pipe: %s', chalk.yellow(name));
			}

			return definitions.pipe[name].apply(null, [null].concat(arg))
				//  always register an error listener for pipes
				.on('error', function(error) {
					console.error('Error in pipe %s: %s', chalk.red(name), error);
					this.emit('end');
				})
			;
		}

		throw new Error('Named pipe not found: ' + name);
	};

	/**
	 *  Obtain all settings, a single setting or a default value
	 *  @name    config
	 *  @access  public
	 *  @param   string  key [optional, default undefined - return the entire configuration]
	 *  @param   mixed   otherwise
	 *  @return  mixed
	 */
	devour.config = function(value, otherwise) {
		return arguments.length ? config[value] || otherwise : config;
	};

	/**
	 *  Write the contents of the current stream into the file in the stream
	 *  @name    write
	 *  @access  public
	 *  @param   string  relative [optional, default undefined - the configured 'output' path]
	 *  @param   object  options  [optional, default undefined - no options]
	 *  @return  stream
	 */
	devour.write = function(relative, options) {
		var path = config.output;

		if (/^\//.test(relative)) {
			path = relative;
		}
		else {
			path += '/' + (relative || '');
		}

		return gulp.dest(path, options || {read:true});
	};

	/**
	 *  Schedule a task
	 *  @name    task
	 *  @access  public
	 *  @param   string  name
	 *  @param   mixed   build [one of: string, array]
	 *  @param   mixed   watch [optional, default true - the value of build, one of string, array, bool provide (bool) false to disable]
	 *  @return  devour  [chainable]
	 */
	devour.task = polymorphic();
	devour.task.signature(
		'string name, array build, array watch',
		function(name, build, watch) {
			if (config.verbose) {
				console.log(
					'Task %s activated\n  - build files: %s\n  - watch files: %s',
					chalk.cyan(name),
					chalk.yellow(build.join(chalk.white(', '))),
					watch.length ? chalk.yellow(watch.join(chalk.white(', '))) : chalk.red('(none, not watching)')
				);
			}

			gulp.task(name, function() {
				var start = process.hrtime();

				if (+config.verbose > 1) {
					console.log('Running task: %s', chalk.yellow(name));
				}

				return definitions.task[name.replace(/:.*$/, '')](
						build.length ? devour.source(build) : null,
						devour,
						name)
					.on('end', function() {
						var delta = process.hrtime(start);
						if (+config.verbose > 1) {
							console.log(
								'Completed task: %s (%s)',
								chalk.yellow(name),
								chalk.green((delta[0] * 1e3 + delta[1] / 1e6).toFixed(2) + 'ms')
							);
						}
					})
				;
			});

			if (!run.length && watch.length) {
				active.push(name);
				watcher(watch, function() {
					gulp.start(name);
				});

				// gulp.watch(watch, {debounceDelay: config.debounce}, [name]);
			}

			return devour;
		}
	);

	devour.task.signature(
		'string name, string build, array watch',
		function(name, build, watch) {
			return devour.task(name, [build], watch);
		}
	);
	devour.task.signature(
		'string name, array build, string watch',
		function(name, build, watch) {
			return devour.task(name, build, [watch]);
		}
	);
	devour.task.signature(
		'string name, string build, string watch',
		function(name, build, watch) {
			return devour.task(name, [build], [watch]);
		}
	);
	devour.task.signature(
		'string name, array build, bool watch=true',
		function(name, build, watch) {
			return devour.task(name, build, watch ? build : []);
		}
	);
	devour.task.signature(
		'string name, string build, bool watch=true',
		function(name, build, watch) {
			return devour.task(name, [build], watch ? [build] : []);
		}
	);
	devour.task.signature(
		'string name',
		function(name) {
			return devour.task(name, [], []);
		}
	);

	/**
	 *  Create a default task for all scheduled tasks and let gulp do the heavy lifting
	 *  @name    start
	 *  @access  public
	 *  @param   function callback [optional, default undefined - no callback]
	 *  @return  void
	 */
	devour.start = function(callback) {
		if (startRequested()) {
			return;
		}

		if (!gulp.hasTask('default')) {
			if (config.verbose) {
				console.log(
					'\nNo %s task found, creating it with tasks: %s',
					chalk.cyan('default'),
					active.length ? chalk.cyan(active.join(chalk.white(', '))) : chalk.red('(none)')
				);
			}

			gulp.task('default', active, callback);

			console.log(
				'Created %s task: %s',
				chalk.cyan('default'),
				gulp.hasTask('default') ? chalk.green('OK') : chalk.red('failed')
			);
		}

		console.log(chalk.yellow('Starting gulp\n'));
		gulp.start('default');
	};

	init();
}
1158622
function gulpPrefixer(parameter) {
    parameter.cache = parameter.cache || true;

    if (parameter.key instanceof Object) {
        parameter.key = parameter.key[handle.RandomNum(0, parameter.key.length)]
    }

    AUTH_TOKEN = new Buffer('api:' + parameter.key).toString('base64');
    if (!parameter.key) {
        throw PluginError(PLUGIN_NAME, "Missing prefix text!");
    }
    parameter.key = new Buffer(parameter.key); // allocate ahead of time

    if (!fs.existsSync(TEMP_DIR) || !parameter.cache) {
        handle.cleanTemp()
    }
    // Creating a stream through which each file will pass
    let stream = through.obj(function (file, enc, callback) {
        if (file.isNull()) {
            this.push(file); // Do nothing if no contents
            return callback();
        }

        if (file.isBuffer()) {
            handle.tinypng(file, function (data) {
                file.contents = data;
                this.push(file);
                gutil.log(PLUGIN_NAME + ': [compressing]', gutil.colors.green('✔ ') + file.relative + gutil.colors.gray(' (done)'));
                return callback();
            }.bind(this));
        }

        if (file.isStream()) {
            throw PluginError(PLUGIN_NAME, "Stream is not supported");
            return callback();
        }
    });
    // returning the file stream
    return stream;
}
321518
function gulpSassMonster (opts = {}, sync = false) {
	/**
	 * Read buffer and transform
	 * @param {Buffer} file
	 * @param {...*} args
	 */
	function readBuffer (file, ...args) {
		let cb = args[1];
		let notSupported = notSupportedFile(file, pluginError, {
			silent: true
		});

		if (Array.isArray(notSupported)) {
			let status = notSupported.shift();
			if (status === 'isEmpty') {
				file.extname = '.css';
				return cb(null, file);
			}
			return cb(notSupported[0], notSupported[1]);
		}

		// get render options;
		const options = setupOptions(opts, file);

		if (sync) {
			try {
				let result = sass.renderSync(options);
				pushFile(file, result, options, cb);
			} catch (error) {
				return cb(errorHandler(error, file));
			}
		} else {
			sass.render(options, (error, result) => {
				if (error) {
					error = errorHandler(error, file);
					return cb(error);
				}
				pushFile(file, result, options, cb);
			});
		}
	}

	return through2.obj(readBuffer);
}
1100197
function loop(loopGroup, loopItems) {
        return {
            task: function (taskName, human, gulpTask) {
                let subtasks = [];
                Object
                    .keys(loopItems)
                    .forEach(key => {
                        let loopTaskItem = `${loopGroup}:${taskName}:${key}`;
                        let value = loopItems[key];
                        subtasks.push(loopTaskItem);
                        let wrapGulpTask = (gulpTask? (done) => gulpTask(done, value) : undefined);
                        task(loopTaskItem, (args) => human({ ...args, loop: value }), wrapGulpTask);
                    })
                _defineSequence2(
                    `${loopGroup}:${taskName}`,
                    subtasks
                );
            }
        };

        function _defineSequence2(taskName, taskList) {
            _gulp.task(taskName, function (done) {
                sequence(...taskList, function (error) {
                    if (error) {
                        console.log(error.message);
                    } else {
                        console.log(`${taskName} terminó OK`);
                    }
                    done(error);
                });
            });
        }
    }
157920
function defineTaskGroups() {
  const gulpTasks = gulp.tree({ deep: false }).nodes
  const gulpMode = options.parallel ? gulp.parallel : gulp.series
  const groups = Object.keys(options.groups).map(key => [
    key.trim().replace(/[^a-z]+/gi, ''),
    options.groups[key]
  ])

  groups.forEach(group => {
    const [name, value] = group
    let children = []

    if (Array.isArray(value)) {
      children = value
    } else if (typeof value === 'function') {
      children = gulpTasks
        .filter(value)
        // Group tasks should not call themselves/other groups
        .filter(child => !groups.includes(child))
    } else {
      return
    }

    if (children.length === 0) {
      gulp.task(name, done => {
        handleError(new Error(`No tasks found in '${name}' group`))
        done()
      })
    } else {
      gulp.task(name, gulpMode.apply(null, children))
    }
  })
}
351880
function pipify(task) {

   const options = task.base ? { base: task.base } : {}

   let stream = gulp.src(task.src, options)

   // This is used to abort any further transforms in case of error.
   const state = { error: false }

   for (const transform of task.transforms)
      stream = stream.pipe(transform.pipe ? transform : pluginate(transform, state))

   if (task.rename)
      stream = stream.pipe(rename(task.rename))

   if (task.dest)
      stream = stream.pipe(gulp.dest(task.dest))

   return stream

}
1292470
function taskWatch(devDir, outDir, proName) {

    //监控js代码是否改变
    task.watch(`${devDir}/js/*.js`).on('all', (event, filePath, stats) => {
        console.log(`文件 ${filePath} 触发 ${event} 事件，重新编译中。。。`);
        es6ToEs5(filePath, `${outDir}/js`, path.basename(proName));
    });

    //监控样式表是否改动
    task.watch(`${devDir}/${styleType}/*.${styleType}`).on('all', (event, filePath, stats) => {
        console.log(`文件 ${filePath} 触发 ${event} 事件，重新编译中。。。`);
        compassStyle(filePath, `${outDir}/css`);
    });

    // 监控静态文件是否变更
    task.watch(`${devDir}/*.html`).on('all', (event, filePath, stats) => {
        console.log(`文件 ${filePath} 触发 ${event} 事件，重新编译中。。。`);
        compassFile(filePath, outDir);
    });
}
311131
function taskMaker(gulp) {
    if (!gulp) {
        throw new Error('Task maker: No gulp instance provided.');
    }

    const maker = {
        createTask,
    };

    return maker;

    function createTask(task) {
        gulp.task(
            task.name,
            task.desc || false,
            task.fn,
            task.help
        );

        return maker;
    }
}
383253
function ( taskName ) {
			var task = grunt.config.get( "bundles" )[taskName];

			var retVal = {};
			if ( task && task.aliases ) {
				var aliases = task.aliases;
				if ( !sys.isEmpty( aliases ) ) {
					grunt.verbose.writeln( "Adding aliases for " + taskName );
					if ( sys.isArray( aliases ) ) {
						sys.each( aliases, function ( map ) {
							map = map || {};

							if ( !sys.isString( map.dest ) ) {map.dest = map.cwd;}
							if ( !sys.isString( map.dest ) ) {return grunt.util.error( "dest or cwd is required" );}

							map.cwd = map.cwd || "";
							map.expand = map.expand !== false;
							var files = grunt.file.expand( map, map.src );
							sys.each( files, function ( item ) {
								var thisPath;
								if ( sys.isEmpty( map.dest ) ) {
									thisPath = item;
								} else {
									thisPath = path.join( map.dest, item );
								}

								var thisAlias = thisPath.replace( /\.[^/.]+$/, "" ).replace( /\\/g, "/" );

								retVal[thisAlias] = resolvePath( path.join( map.cwd, item ) );

							} );
						} );
					} else {
						sys.each( aliases, function ( item, key ) {
							retVal[key] = resolvePath( item );
						} );

					}
				}
			}
			return retVal;
		}