cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

loose-envify.js (791B)


      1'use strict';
      2
      3var stream = require('stream');
      4var util = require('util');
      5var replace = require('./replace');
      6
      7var jsonExtRe = /\.json$/;
      8
      9module.exports = function(rootEnv) {
     10  rootEnv = rootEnv || process.env;
     11  return function (file, trOpts) {
     12    if (jsonExtRe.test(file)) {
     13      return stream.PassThrough();
     14    }
     15    var envs = trOpts ? [rootEnv, trOpts] : [rootEnv];
     16    return new LooseEnvify(envs);
     17  };
     18};
     19
     20function LooseEnvify(envs) {
     21  stream.Transform.call(this);
     22  this._data = '';
     23  this._envs = envs;
     24}
     25util.inherits(LooseEnvify, stream.Transform);
     26
     27LooseEnvify.prototype._transform = function(buf, enc, cb) {
     28  this._data += buf;
     29  cb();
     30};
     31
     32LooseEnvify.prototype._flush = function(cb) {
     33  var replaced = replace(this._data, this._envs);
     34  this.push(replaced);
     35  cb();
     36};