WireDependencies.prototype.collectDependencies = function (srcDir, destDir) {
  var self = this;

  var result = {
    js: [],
    css: []
  };

  var dependencies = {
    js: self.findFiles(srcDir, '.js'),
    css: self.findFiles(srcDir, '.css')
  };

  if (self.options.bower) {
    var bowerPackages = wiredep(self.options.wiredep);

    if (!self.options.ignoreBowerStylesheets) {
      dependencies.css = bowerPackages.css.concat(dependencies.css);
    }

    dependencies.js = bowerPackages.js.concat(dependencies.js);
  }

  _.forOwn(dependencies, function (value, type) {
    _.forEach(value, function (filepath) {
      var filename = path.basename(filepath);
      var target = self.options.paths[type] + '/' + filename;
      fs.copySync(filepath, destDir + '/' + target);

      result[type].push(target);
    });
  });

  return result;
};
Exemplo n.º 2
0
function assertAllUnitDepsOk(app) {
    var valid = Object.create(null);

    _.forOwn(app._units, function (unit) {
        assertUnitDepsOk(unit, []);
    });

    function assertUnitDepsOk(unit, unitDepsPath) {
        if (valid[unit.name]) {
            return;
        }

        _.forEach(unit.deps, function (depName) {
            var depUnit = app._units[depName];

            if (!depUnit) {
                throw new errors.NoSuchUnitError(f('No such dependency %j for unit %j', depName, unit.name));
            }

            if (_.contains(unitDepsPath, depName)) {
                throw new errors.DepsConflictError(
                    f('Recursive dependencies found: "%s" < "%s"', unitDepsPath.join('" < "'), depName));
            }

            assertUnitDepsOk(depUnit, unitDepsPath.concat(depName));
        });

        valid[unit.name] = true;
    }
}
Exemplo n.º 3
0
function compileObj (obj) {
    var item = null;
    var result = {};

    if (!_.isObject(obj)) {
      return compile.buildByVal(obj);
    } else {
      _.forOwn(obj, function (val, key) {
          if (~key.indexOf(':') || ~key.indexOf('|')) {
              if (/\|Nullable$/.test(key) && Math.round(Math.random())) {
                result[key.replace(/\|Nullable$/, '')] = null;
              } else {
                key = key.replace(/\|Nullable$/, '');

                item = compile.buildByKey(key, val);
                result[item[0]] = item[1];
              }
          } else {
              key = key.replace(/\|Nullable$/, '');

              if (_.isObject(val)) {
                  result[key] = compile(val);
              } else {
                  result[key] = compile.buildByVal(val);
              }
          }
      });
    }

    return result;
}
Exemplo n.º 4
0
 var getAttachments = function(obj) {
   var items = [];
   _.forOwn(obj, function(value, key) {
     items.push({
       name: value.name,
       type: value.type,
       content: value.content
     });
   });
   return items;
 };
Exemplo n.º 5
0
function createUnits(app) {
    var units = {};

    _.forOwn(app._class, function (UnitClass, name) {
        if (/^[a-z]/i.test(name)) {
            // public unit should be exposed to be a target or dependency
            units[name] = new UnitClass();
        }
    });

    return Object.freeze(units);
}
Exemplo n.º 6
0
        _.forOwn(staticAssets, function(avalue, akey) {

            if (_.contains(['html', 'img'], avalue.type)) {
                return;
            };

            _.forOwn(staticAssets, function(bvalue, bkey) {

                if (akey == bkey) return;
                var duplicate = checkDuplicate(avalue, bvalue);
                var duplicateLibrary = checkDuplicateLibrary(avalue, bvalue);
                if (duplicate || duplicateLibrary) {
                    if (!_.contains(duplicates, avalue.assetKey)) {
                        duplicates.push(bvalue.assetKey);
                    }
                }
            });
        });
Exemplo n.º 7
0
Sender.prototype.sendTemplate = function(templateName, mailObj, templateData, callback) {

  if (typeof templateData == 'function') {
    callback = templateData;
    templateData = [];
  }

  var valid = this.validateMessageObj(mailObj);

  if (valid.error) {
    return callback(valid.error);
  }

  if (mailObj.globalMergeVarObj) {
    mailObj.globalMergeVars = [];
    _.forOwn(mailObj.globalMergeVarObj, function(value, key) {
      mailObj.globalMergeVars.push({
        name: key,
        content: value
      });
    });
    delete mailObj.globalMergeVarObj;
  }

  if (this.options.globalMergeVars) {
    if (!mailObj.globalMergeVars) {
      mailObj.globalMergeVars = [];
    }
    _.forOwn(this.options.globalMergeVars, function(value, key) {
      mailObj.globalMergeVars.push({
        name: key,
        content: value
      });
    });
  }

  if (this.options.validations) {
    var requiredKeys = this.options.validations[templateName];
    if (!requiredKeys) {
      return callback(new Error('invalid template'));
    }
    var sentKeys = _.pluck(mailObj.globalMergeVars, 'name');
    var diff = _.difference(requiredKeys, sentKeys);

    if (diff.length !== 0) {
      return callback(new Error('incorrect keys for '+templateName+': '+diff.join(',')));
    }
  }

  mailObj = _.merge({}, this.options.defaults, mailObj);

  mailObj = this.objToUnderscores(mailObj);

  var dataObj = {
    template_name: templateName,
    message: mailObj,
    template_content: templateData
  };


  if (this.test) {
    return this.sendTest(dataObj, callback);
  }


  this.client.messages.sendTemplate(dataObj, function(result) {
    callback(null, result);
  }, function(err) {
    callback(err);
  });
};
WireDependencies.prototype.wire = function (dependencies, srcDir, destDir) {
  var self = this;

  var templates = {
    '.html': {
      'js': '<script src="{filePath}"></script>',
      'css': '<link href="{filePath}" rel="stylesheet" type="text/css">'
    },
    '.haml': {
      'js': '%script{src: "{filePath}"}',
      'css': '%link{href: "{filePath}", rel: "stylesheet", type: "text/css"}'
    },
    '.jade': {
      'js': 'script(src="{filePath}")',
      'css': 'link(href="{filePath}", rel="stylesheet", type="text/css")'
    }
  };

  var marker = {
    '.html': {
      js: /<!--\s*include:scripts\s*-->/gi,
      css: /<!--\s*include:styles\s*-->/gi
    },
    '.haml': {
      js: /-#\s*include:scripts/gi,
      css: /-#\s*include:styles/gi
    },
    '.jade': {
      js: /\/\/\s*include:scripts/gi,
      css: /\/\/\s*include:styles/gi
    }
  };

  var data = fs.readFileSync(srcDir + '/' + self.options.src, 'utf8');
  var extension = path.extname(self.options.src);

  var includes = {
    js: [],
    css: []
  };

  _.forOwn(dependencies, function (value, type) {
    _.forEach(value, function (filePath) {
      includes[type].push(templates[extension][type].replace('{filePath}', filePath));
    })
  });

  var replaceMarkerWithIncludes = function (type, data) {
    var lines = data.split('\n');
    var insertLines = [];

    _.forEach(lines, function (line) {
      if (line.match(marker[extension][type])) {
        _.forEach(includes[type], function (item) {
          insertLines.push(line.replace(marker[extension][type], item))
        });
      }
    });

    var indentationRegEx = /([ \t]*)/;

    var searchValue = new RegExp(indentationRegEx.source + marker[extension][type].source);
    var newValue = insertLines.join('\n');

    data = data.replace(searchValue, newValue);

    return data;
  };

  data = replaceMarkerWithIncludes('js', data);
  data = replaceMarkerWithIncludes('css', data);

  fs.outputFileSync(destDir + '/' + self.options.src, data);

};
Exemplo n.º 9
0
    function removeDuplicates(staticAssets, next) {

        var duplicates = [];

        var checkDuplicate = function(a, b) {
                var duplicate = false;
                if (a.checksum == b.checksum) {
                    if(_.contains(duplicates,b.assetKey) || _.contains(duplicates,a.assetKey)) return;
                    bosco.warn("Skipping duplicate file: " + a.assetKey + " <> " + b.assetKey);
                    duplicate = true;
                }
                return duplicate;
            },
            checkDuplicateLibrary = function(a, b) {
                var aLib = checkLibrary(a),
                    duplicate = false;
                if (aLib) {
                    var bLib = checkLibrary(b);
                    if (bLib && bLib.name == aLib.name) {
                        if(_.contains(duplicates, b.assetKey) || _.contains(duplicates, a.assetKey)) return;
                        if (bLib.version == aLib.version) {
                            bosco.warn("Duplicate library version: " + a.assetKey + " <> " + b.assetKey);
                        } else {
                            bosco.warn("Duplicate library with different version: " + a.assetKey + " <> " + b.assetKey);
                        }
                        duplicate = true;
                    }
                }
                return duplicate;
            },
            checkLibrary = function(a) {
                var dashSplit = a.asset.split("-");
                if (dashSplit[dashSplit.length - 1] == 'min.js') {
                    return {
                        version: dashSplit[dashSplit.length - 2],
                        name: dashSplit[dashSplit.length - 3]
                    };
                } else {
                    return null;
                }
            }

        _.forOwn(staticAssets, function(avalue, akey) {

            if (_.contains(['html', 'img'], avalue.type)) {
                return;
            };

            _.forOwn(staticAssets, function(bvalue, bkey) {

                if (akey == bkey) return;
                var duplicate = checkDuplicate(avalue, bvalue);
                var duplicateLibrary = checkDuplicateLibrary(avalue, bvalue);
                if (duplicate || duplicateLibrary) {
                    if (!_.contains(duplicates, avalue.assetKey)) {
                        duplicates.push(bvalue.assetKey);
                    }
                }
            });
        });

        // Now remove them all
        duplicates.forEach(function(key) {
            delete staticAssets[key];
        })

        next(null, staticAssets);

    }