Return transform stream which resolve HTML files.
@param {object} opts - stream options
@returns {Stream}
492813
function publish(opts) {
  // stream options
  var defaults = {
    enableResolve: false,
    directory: './build',
    debug: false
  };
  var options = utils.shallowMerge(opts, defaults);

  return through(function(file, enc, callback) {
    if (file.isNull()) return callback(null, file);

    // emit error event when pass stream
    if (file.isStream()) {
      this.emit('error', new gutil.PluginError(PLUGIN, 'Streams are not supported!'));
      return callback();
    }

    // resolve the HTML files
    var blocks = utils.getSplitBlock(file.contents.toString());
    var result = utils.resolveSourceToDestiny(blocks, options);
    file.contents = new Buffer(result);

    // resolve the files linked by tag script and link
    if (options.enableResolve) {
      var fileSource = utils.getBlockFileSource(blocks);
      utils.resolveFileSource(fileSource, options);
    }

    callback(null, file);
  });
}
1322017
function html(opts) {
  opts = opts || {}
  var parent = opts.target =  createElement();
  parent.innerHTML = opts.content;
  Splitting(opts)
  return parent.outerHTML
}
435019
function () {
                var stream = new $.streamqueue({
                    objectMode: true
                });

                //Optionally injected additional javascript sourcecode
                injectIntoStream(stream, options.injectInto.js.pre);

                // App files without vendor files
                stream.queue(gulp.src(options.files.jsNoVendor));

                //Angular template files
                stream.queue(
                    gulp.src(options.files.partials)
                        .pipe($.htmlMinify())
                        .pipe($.angularTemplatecache(options.templateCacheOptions))
                );

                //Optionally injected additional javascript sourcecode
                injectIntoStream(stream, options.injectInto.js.post);

                return stream
                    .done()
                    .pipe($.angularFilesort())
                    .pipe($.concat(options.output.js.app))
                    .pipe($.generateOutPipe(options.paths.build, options.output.js.path, 'app.js', options.rev, $.jsMinify)());
            }
1340039
function gulp(opts) {
  opts = opts || {};

  var failOnError = opts['failOnError'] || false;
  var interimFiles = [];
  var failedValidations = [];

  return Through(
    function (file) {
      interimFiles.push(file.path);
      this.queue(file);
    },
    function () {
      var baseFile = opts.packageFile;

      interimFiles.forEach(function (file) {
        opts.packageFile = file;

        var results = validate(opts);

        if (hasErrors(results)) {
          failedValidations.push(file);
          log(results);
        }
      });

      opts.packageFile = baseFile;

      if (failOnError &&  failedValidations.length) {
        this.emit('error', new PluginError('dep-validate', 'Unable to validate dependencies'));
      } else {
        this.emit('end');
      }
    }
  );
}
596183
function Options(opts) {

  //### Private properties

  var custfilt = [],
      varset   = {__FILE: '', $__FILE: '""'}

  //### Public Properties

  this.header1    = _defaults.header1
  this.headers    = _defaults.headers
  this.indent     = _defaults.indent
  this.eolType    = _defaults.eolType
  this.emptyLines = _defaults.emptyLines
  this.comments   = _defaults.comments
  this.filter     = _defaults.filter

  this.emitError  = procError     // error "handler"

  //### Public Methods

  this.invalid = function (msg, v) {
    this.emitError('Invalid ' + msg + ' ' + (v != null ? '"' + v + '"' : v))
  }

  this.getVars = function () {
    return varset
  }

  this.setFile = function (file) {
    varset.$__FILE = JSON.stringify(varset.__FILE = file)
  }

  this.def = function (s) {
    var m = s.match(RE_VARPAIR)

    if (m) {
      var k = m[1],
          v = m[2].trim()

      if (!RE_VARNAME.test(k))
        this.invalid('symbol name', k)
      else
        varset[k] = !v ? 1 :
          _fixValue(evalExpr(v, varset, this.emitError))
    }
    else
      this.invalid('symbol name or declaration', s) // only when starts with '='
  }

  this.undef = function (s) {
    var def = s.match(RE_VARNAME)

    if (def)
      delete varset[def[1]]
    else
      this.invalid('symbol name', s)
  }

  this.passFilter = function (str) {
    var i, f, filts

    for (i = 0; i < custfilt.length; ++i) {
      /* istanbul ignore else */
      if (custfilt[i].test(str)) return true
    }
    filts = this.filter
    if (filts === 'all')
      filts = Object.keys(_filters)
    for (i = 0; i < filts.length; ++i) {
      f = _filters[filts[i]]
      if (f.test(str)) return true
    }
    return false
  }

  this.merge = function (opt) {
    if (opt)
      merge.call(this, opt)
    return this
  }

  return this.merge(opts)

  //### Private methods

  // prepare a value for inclussion in the set of variables
  function _fixValue(v) {
    switch (typeof v) {
      case 'number':      // typeof NaN is 'number'
      case 'boolean':
      case 'undefined':
        break
      default:
        // date value returns 'new Date(NaN)' for null dates, ok
        v = v instanceof RegExp ? '' + v :
            v instanceof Date ? '(new Date(' + (+v) + '))' : // eslint-disable-line no-extra-parens
            v == null ? v : JSON.stringify(v)
        break
    }
    return v
  }

  // returns an array as-is or created from a delimited string
  function _split(v) {
    return Array.isArray(v) ? v : v.split(',')
  }

  // Enable filters for comments, 'all' enable all filters
  function _setFilter(filt) {
    filt = filt.trim()
    if (filt === 'all')
      this.filter = filt
    else if (filt in _filters) {
      if (this.filter !== 'all' && this.filter.indexOf(filt) < 0)
        this.filter.push(filt)
    }
    else this.invalid('filter', filt)
  }

  // Creates a custom filter
  function _createFilter(res) {
    for (var i = 0; i < res.length; ++i) {
      var f = res[i]

      if (f instanceof RegExp)
        custfilt.push(f)
      else {
        //console.log('--- creating regex with `' + str + '`')
        try {
          f = new RegExp(f)
          custfilt.push(f)
        }
        catch (e) {
          f = null
        }
        if (!f) this.invalid('custom filter', res[i])
      }
    }
  }

  function _formatHeader(str) {
    return !str ? '' :
      ('' + str)
      .replace(/\r\n?/g, '\n')
      .replace(/\^{1,2}/g, function (c) { return c[1] || '\n' })
  }

  function _setVars(set) {
    for (var k in set) {
      if (RE_VARNAME.test(k))
        varset[k] = _fixValue(set[k])
      else
        this.invalid('symbol name', k)
    }
  }

  /* eslint-disable guard-for-in, complexity */
  function merge(opt) {
    var k, v

    for (k in opt) {
      v = opt[k]

      switch (k) {
        case 'varset':
          _setVars.call(this, v)
          break
        case 'define':
        case 'set':
          _split(v).forEach(this.def, this)
          break
        case 'undef':
        case 'unset':
          _split(v).forEach(this.undef, this)
          break
        case 'filter':
          _split(v).forEach(_setFilter, this)
          break
        case 'customFilter':
          _createFilter(Array.isArray(v) ? v : [v])
          break
        case 'header1':
        case 'headers':
          this[k] = _formatHeader(v)
          break
        case 'emptyLines':
          this[k] = v | 0
          break
        case 'eolType':
          if (/^(?:win|mac|unix)$/.test(v))
            this[k] = v
          else
            this.invalid(k, v)
          break
        case 'comments':
          if (/^(?:all|none|filter)$/.test(v))
            this[k] = v
          else
            this.invalid(k + ' value', v)
          break
        case 'indent':
          if (/^\d+[ts]?/.test(v))
            this[k] = v
          else if (!v)
            this[k] = ''
          else
            this.invalid(k, v)
          break
        default:
          break
      }
      //else
      //  console.log('Ignoring option ' + k)
    }
  }
}
1236060
function addService(opts) {
	let values = Object.assign({}, opts);

	return Promise.resolve()
		.then(() => {
			return inquirer.prompt([
				{
					type: "input",
					name: "serviceFolder",
					message: "Service directory",
					default: "./services",
					validate(input) {
						if (!fs.existsSync(path.resolve(input)))
							return `The '${input}' directory is not exists! Full path: ${path.resolve(input)}`;

						return true;
					}
				},
				{
					type: "input",
					name: "serviceName",
					message: "Service name",
					default: "test"
				}
			]).then(answers => {
				Object.assign(values, answers);

				const newServicePath = path.join(values.serviceFolder, values.serviceName + ".service.js");
				values.newServicePath = newServicePath;

				if (fs.existsSync(newServicePath)) {
					return inquirer.prompt([{
						type: "confirm",
						name: "sure",
						message: "The file is exists! Overwrite?",
						default: false
					}]).then(({ sure }) => {
						if (!sure)
							fail("Aborted");
					});
				}
			});
		})
		.then(() => {
			const templatePath = path.join(__dirname, "service.template");
			const template = fs.readFileSync(templatePath, "utf8");

			return new Promise((resolve, reject) => {
				render(template, values, function (err, res) {
					if (err)
						return reject(err);

					const { newServicePath } = values;
					console.log(`Create new service file to '${newServicePath}'...`);
					fs.writeFileSync(path.resolve(newServicePath), res, "utf8");

					resolve();
				});
			});
		})

		// Error handler
		.catch(err => fail(err));
}
1218753
function gulpPlovr(opts) {
  opts = opts || { };
  
  if (!opts.java_path) opts.java_path = JAVA_PATH;
  if (!opts.plovr_path) opts.plovr_path = PLOVR_PATH;
  if (!opts.plovr_args) opts.plovr_args = {};
  if (opts.debug) gutil.log(PLUGIN_NAME + ':', 'debug mode is enabled!');
  
  // Creating a stream through which each file will pass
  return through.obj(function(file, enc, cb) {
    if (file.isNull()) {
      // return empty file
      cb(null, file);
    }
    
    //var baseDir = path.dirname(module.parent.filename);
    var filePath = path.dirname(file.path);
    var configPath = file.path;
    
    if (file.isBuffer()) {
      var args = [];
      args.push('-jar');
      args.push(opts.plovr_path);
      
      Object.keys(opts.plovr_args).forEach(function(key) {
        var value;
        value = opts.plovr_args[key];
        args.push("--" + key);
        return args.push(value);
      });
      
      args.push('build');
      args.push(configPath);
      
      var compiler = spawn(opts.java_path, args);
      var stdout = '';
      var stderr = '';
      compiler.stdout.setEncoding('utf8');
      compiler.stderr.setEncoding('utf8');
      compiler.stdout.on('data', function(data) {
        if (opts.debug) gutil.log(PLUGIN_NAME + ':', data);
        return stdout += data;
      });
      
      compiler.stderr.on('data', function(data) {
        return stderr += data;
      });
      
      compiler.on('exit', function(code) {
        if (code !== 0) {
          this.emit('error', new gutil.PluginError(PLUGIN_NAME, stderr));
        }
        
        cb();
      });
      
      compiler.on('close', function(code) {
        if (opts.debug) gutil.log(stdout + stderr);
      });
    }
    
    if (file.isStream()) {
      this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
      cb();
    }
  });
}
1156191
function gulpReplaceRef(opts) {

    opts = opts || {};

    var stream;

    // Creating a stream through which each file will pass
    stream = through.obj(function (srcFile, enc, callback) {
        var self = this;
        if (srcFile.isNull()) {
            self.push(srcFile); // Do nothing if no contents
            return callback();
        }

        if (srcFile.isBuffer()) {

            var strToReplace = srcFile.path.match( opts.srcMatch )[0], stream, targetMatch = opts.targetMatch;

            vfs.src(opts.target).pipe(es.map(function(phpFile, cb){
                //console.log(phpFile.path);
                var content = phpFile.contents.toString();
                if(targetMatch(srcFile.path).test(content)){
                    fs.writeFile(phpFile.path, content.replace(targetMatch(srcFile.path), strToReplace));
                    console.log('php file updated: ' + phpFile.path);
                }

                cb(null, phpFile);
            }));


            self.push(srcFile);
            return callback();
        }

        if (srcFile.isStream()) {
            this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!'));
            return callback();
        }
    });

    // returning the file stream
    return stream;
}
1131207
function getOptions(rules, opts) {
	var dir;
	var obj = {
		source: opts.source,
		transform: opts.transform || function (val) {
			return val;
		}
	};

	obj.path = opts.path || [];
	obj.path = Array.isArray(obj.path) ? obj.path : [obj.path];

	if (rules.length && rules[0].position && rules[0].position.source) {
		dir = path.dirname(rules[0].position.source);
	}

	if (dir && obj.path.indexOf(dir) === -1) {
		obj.path.unshift(dir);
	}

	if (!obj.path.length) {
		obj.path.push(process.cwd());
	}

	return obj;
}
124298
function JSONStreamer(options) {
	// allow use without new
	if (!(this instanceof JSONStreamer)) {
		return new JSONStreamer(options);
	}
	// init Transform
	Transform.call(this, options);

	this.push('[');
	this.count = 0;
}
83439
function (opts) {
        opts = opts || {};
        if (this._singleCanvas && !this._compositeManually) {
            return this._layers[CANVAS_ZLEVEL].dom;
        }

        var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
        imageLayer.initContext();
        imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);

        if (opts.pixelRatio <= this.dpr) {
            this.refresh();

            var width = imageLayer.dom.width;
            var height = imageLayer.dom.height;
            var ctx = imageLayer.ctx;
            this.eachLayer(function (layer) {
                if (layer.__builtin__) {
                    ctx.drawImage(layer.dom, 0, 0, width, height);
                }
                else if (layer.renderToCanvas) {
                    imageLayer.ctx.save();
                    layer.renderToCanvas(imageLayer.ctx);
                    imageLayer.ctx.restore();
                }
            });
        }
        else {
            // PENDING, echarts-gl and incremental rendering.
            var scope = {};
            var displayList = this.storage.getDisplayList(true);
            for (var i = 0; i < displayList.length; i++) {
                var el = displayList[i];
                this._doPaintEl(el, imageLayer, true, scope);
            }
        }

        return imageLayer.dom;
    }
90709
function writeStreamToFs(opts, stream) {
    var baseDir = path.join(opts.cwd, opts.directory);
    var walker = walk.walk(baseDir);

    walker.on('errors', function (root, stats, next) {
        stream.emit('error', new PluginError(PLUGIN_NAME, stats.error));
        next();
    });
    walker.on('directory', function (root, stats, next) {
        next();
    });

    walker.on('file', function (root, stats, next) {
        var filePath = path.resolve(root, stats.name);

        fs.readFile(filePath, function (error, data) {
            if (error) {
                stream.emit('error', new PluginError(PLUGIN_NAME, error));
            } else {
                stream.write(new Vinyl({
                    path: path.relative(baseDir, filePath),
                    contents: data
                }));
            }

            next();
        });
    });

    walker.on('end', function () {
        stream.emit('end');
        stream.emit('finish');
    });
}
922018
function Stream( options ) {
	var args = arguments,
		opts = {},
		err;
	if ( args.length ) {
		opts = options;
	}
	if ( !( this instanceof Stream ) ) {
		return new Stream( opts );
	}
	err = validate( opts );
	if ( err ) {
		throw err;
	}
	Transform.call( this, opts );
	this._readableState.objectMode = true;
	this._data = '';

	return this;
}
293510
function nodeInjectmd (opts) {
  const inBuf = bl()

  assert.equal(typeof opts, 'object', 'opts should be an object')
  assert.equal(typeof opts.in, 'string', 'opts.in should be a string')
  assert.equal(typeof opts.tag, 'string', 'opts.tag should be a string')

  const inFile = opts.in
  const tag = opts.tag
  const startTag = new RegExp('<!--\\s*START ' + tag + '\\s*-->')
  const endTag = new RegExp('<!--\\s*END ' + tag + '\\s*-->')

  assert.equal(typeof opts, 'object', 'opts must be an object')

  const rs = new stream.PassThrough()

  rs.pipe(inBuf)

  rs.on('end', function () {
    var tagMode = false
    const mdPath = path.join(process.cwd(), inFile)
    const irs = fs.createReadStream(mdPath)
    const its = split(parse)
    const tmpBuf = bl()

    irs.pipe(its).pipe(tmpBuf)

    tmpBuf.on('finish', function () {
      const ws = fs.createWriteStream(inFile, { flags: 'w' })
      const rs = tmpBuf.duplicate()
      rs.pipe(ws)
    })

    function parse (line) {
      if (startTag.test(line.trim())) {
        tagMode = true
        const res = line + EOL + String(inBuf) + EOL
        return res
      } else if (endTag.test(line.trim())) {
        tagMode = false
        return line + EOL
      } else if (!tagMode) {
        return line + EOL
      }
    }
  })

  return rs
}
111685
function gulpCopy(destination, opts) {
    const throughOptions = { objectMode: true };

    // Make sure a destination was verified
    if (typeof destination !== 'string') {
        throw new PluginError('gulp-copy', 'No valid destination specified');
    }

    // Default options
    if (opts === undefined) {
        opts = opts || {};
    } else if (typeof opts !== 'object' || opts === null) {
        throw new PluginError('gulp-copy', 'No valid options specified');
    }

    return through(throughOptions, transform);

    /**
     * Transform method, copies the file to its new destination
     * @param {object} file
     * @param {string} encoding
     * @param {function} cb
     */
    function transform(file, encoding, cb) {
        let rel = null;
        let fileDestination = null;

        if (file.isStream()) {
            cb(new PluginError('gulp-copy', 'Streaming not supported'));
        }

        if (file.isNull()) {
            cb(null, file);
        } else {
            rel = path.relative(file.cwd, file.path).replace(/\\/g, separator);

            // Strip path prefixes
            if (opts.prefix) {
                let p = opts.prefix;
                while (p-- > 0) {
                    rel = rel.substring(rel.indexOf(separator) + 1);
                }
            }

            fileDestination = path.join(destination, rel);

            // Make sure destination exists
            if (!doesPathExist(fileDestination)) {
                createDestination(fileDestination.substr(0, fileDestination.lastIndexOf(separator)));
            }

            // Copy the file
            copyFile(file.path, fileDestination, function copyFileCallback(error) {
                if (error) {
                    throw new PluginError('gulp-copy', `Could not copy file <${file.path}>: ${error.message}`);
                }

                // Update path for file so this path is used later on
                file.path = fileDestination;
                cb(null, file);
            });
        }
    }
}
469220
function lint (files) {
  const stream = gulp.src(files)
  .pipe($.plumber())
  .pipe($.eslint())
  .pipe($.eslint.format())
  if (process.env.NODE_ENV === 'production') {
    stream.pipe($.eslint.failOnError())
  }
  stream.on('error', onError)
  return stream
}
598680
function (opts) {
    this.options = opts || {};
    this.pattern = null;
    this.middleware = {};
    this.includes = {};
    this.excludes = {};
    this.files = [];
    this.fns = [];

    options(this);
    iterators(this);
    symlinks(this);
    readers(this);
  }