<commit_before>var _ = require('lodash'),
  objectPath = require('object-path'),
  glob = require('glob');


function isUrl(url) {
  return (/^http[s]?:\/\/./).test(url);
}

var self = module.exports = {
  __module: {
    properties: {
      log: 'grunt/log',
      config: 'config',
      use_scripts: 'svc!assetManager/use_scripts',
      use_stylesheets: 'svc!assetManager/use_stylesheets'
    },
    provides: {configure_task: {}}
  },

  configure_task: function(input) {
    return self.use_scripts.invoke().then(function(scripts) {
      scripts = _.compact(_.flatten(scripts, true));
      input.scripts = self.groupByNamespaceAndNormalize(scripts);
    }).then(function() {
      return self.use_stylesheets.invoke();
    }).then(function(styles) {
      styles = _.compact(_.flatten(styles, true));
      input.stylesheets = self.groupByNamespaceAndNormalize(styles);

      return input;
    });
  },

  /**
   * Group by namespace, type (file/url) and expand blogs
   */ 
  groupByNamespaceAndNormalize: function(declarations) {
    var namespaces = {};
    var args = null;
    //build the namespaces
    _.each(declarations, function(resourceDeclaration) {
      _.each(resourceDeclaration, function(resources, namespace) {
        resources = _.flatten(resources);
        _.each(resources, function(resource) {
          //resource can be
          //"some/file.js"
          //{cwd: ,file: ""}

          var file, root;
          if(_.isString(resource)) {
            file = resource;
          } else {
            file = resource.file;
            root = resource.cwd;
          }

          var type = 'files';
          if(isUrl(file)) {
            type = 'urls';
            args = [file];
          } else if(root) {
            args = glob.sync(file, {cwd: root});
          } else {
            args = [file];
          }

          args.unshift(namespaces, [namespace, type]);
          objectPath.push.apply(null, args);<commit_msg>Compact namespace's resources before processing<commit_after>var _ = require('lodash'),
  objectPath = require('object-path'),
  glob = require('glob');


function isUrl(url) {
  return (/^http[s]?:\/\/./).test(url);
}

var self = module.exports = {
  __module: {
    properties: {
      log: 'grunt/log',
      config: 'config',
      use_scripts: 'svc!assetManager/use_scripts',
      use_stylesheets: 'svc!assetManager/use_stylesheets'
    },
    provides: {configure_task: {}}
  },

  configure_task: function(input) {
    return self.use_scripts.invoke().then(function(scripts) {
      scripts = _.compact(_.flatten(scripts, true));
      input.scripts = self.groupByNamespaceAndNormalize(scripts);
    }).then(function() {
      return self.use_stylesheets.invoke();
    }).then(function(styles) {
      styles = _.compact(_.flatten(styles, true));
      input.stylesheets = self.groupByNamespaceAndNormalize(styles);

      return input;
    });
  },

  /**
   * Group by namespace, type (file/url) and expand blogs
   */ 
  groupByNamespaceAndNormalize: function(declarations) {
    var namespaces = {};
    var args = null;
    //build the namespaces
    _.each(declarations, function(resourceDeclaration) {
      _.each(resourceDeclaration, function(resources, namespace) {
        resources = _.compact(_.flatten(resources));
        _.each(resources, function(resource) {
          //resource can be
          //"some/file.js"
          //{cwd: ,file: ""}

          var file, root;
          if(_.isString(resource)) {
            file = resource;
          } else {
            file = resource.file;
            root = resource.cwd;
          }

          var type = 'files';
          if(isUrl(file)) {
            type = 'urls';
            args = [file];
          } else if(root) {
            args = glob.sync(file, {cwd: root});
          } else {
            args = [file];
          }

          args.unshift(namespaces, [namespace, type]);
          objectPath.push.apply(null, args);
{'fraction_non_alphanumeric': 0.1436130007558579, 'fraction_numerical': 0.0, 'mean_word_length': 2.2918739635157546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2981405', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1171, 'n_words': 225}