<commit_before>'use strict';

var _ = require('lodash');
var path = require('path');
var fs = require('fs');

module.exports = function exampleDependenciesBuilder (readFilesProcessor, log, generateExamplesProcessor, exampleMap) {
  /**
   * Regular expression to check if path is external
   * @type {RegExp}
   */
  var REMOTE_REG = /(https?:)?\/\//i;

  return {
    $runAfter: ['adding-extra-docs'],
    $runBefore: ['generateExamplesProcessor'],
//    $runBefore: ['extra-docs-added'],
    $process: function (docs) {
      /**
       * Deployments file storage, each de
       */
      var deployments = [];

      // traverse deployments, check project dependencies and add local file
      // dependencies to the list of generated documents
      generateExamplesProcessor.deployments.forEach(function(deployment) {
        var name = makeUniqueName(deployments, deployment.name);
        log.info(0, name)
        var commonFiles = deployment.examples && deployment.examples.commonFiles || {};
        (commonFiles.scripts || []).forEach(function(script, idx){
          log.info(1, script, idx, name)
          if (!REMOTE_REG.test(script)) {
            // local file, add to copy items
              log.info(2, script)
            var fileDoc = {
              docType: 'example-dependency',
              id: name + '/' + script,
              fileContents: fs.readFileSync(path.join(readFilesProcessor.basePath, script)),
              template: 'template' + path.extname(script),
              // make path relative to example output template examples/${example.id}/index,
              path: path.join('../../examples-dep', name, script),
              outputPath: path.join('examples-dep', name, script),
            };

            commonFiles.scripts[idx] = fileDoc.path;
            docs.push(fileDoc);
          }
         });
        (commonFiles.stylesheets || []).forEach(function(stylesheet){
          if (!REMOTE_REG.test(stylesheet)) {
            // local file, add to copy items

          }
         });
      })
    }
  };

  /**
   * Creates unique folder name for the current deployment
   */
  function makeUniqueName (deployments, name) {
      if (!name) {
        name = 'deployment';
      }
      var i = 0;
      while (deployments.indexOf((name + (i ? i : ''))) > -1) {
          i++;
      }
      if (i) {
          name = name + i;
      }
      deployments.push(name);
      return name;
  }
};<commit_msg>Added processing of the stylesheets dependencies<commit_after>'use strict';

var _ = require('lodash');
var path = require('path');
var fs = require('fs');

/**
 * Processor builds list of the project artifact dependencies to copy to the docs.
 *
 * Each deployment (defined for {@link generateExamplesProcessor generateExamplesProcessor}) will have the own set of artifacts
 * to make build docs available for the standalone usage.
 *
 * @name exampleDependenciesBuilder
 */
module.exports = function exampleDependenciesBuilder (readFilesProcessor, log, generateExamplesProcessor, exampleMap) {
  /**
   * Regular expression to check if path is external
   * @type {RegExp}
   */
  var REMOTE_REG = /(https?:)?\/\//i;

  /**
   * Document type for docs entries
   * @type {String}
   */
  var DOC_TYPE = 'example-dependency';

  return {
    $runAfter: ['adding-extra-docs'],
    $runBefore: ['generateExamplesProcessor'],
    $process: function (docs) {
      /**
       * Deployments file storage, each de
       */
      var deployments = [];

      // traverse deployments, check project dependencies and add local file
      // dependencies to the list of generated documents
      generateExamplesProcessor.deployments.forEach(function(deployment) {

        var name = makeUniqueName(deployments, deployment.name);
        var processor = processDependency.bind(null, docs, name);

        var commonFiles = deployment.examples && deployment.examples.commonFiles || {};
        (commonFiles.scripts || []).forEach(processor);
        (commonFiles.stylesheets || []).forEach(processor);
      })
    }
  };

  /**
   * Processes single dependency and creates new document if needed
   * @param {Array} docs array of generated documents
   * @param {String} name unique deployment name
   * @param {String} item deployment item, usually local or remote artifact (script, stylesheet, etc.)
   * @param {Number} index item index in arr
   * @param {Array} arr array of deployment dependencies
   */
  function processDependency (docs, name, item, index, arr) {
    if (!REMOTE_REG.test(item)) {
      // local file, add to copy items
      var fileDoc = makeFileDoc(name, item);

      arr[index] = fileDoc.path;
      docs.push(fileDoc);
    }
  }

  /**
   * Creates document entry for a given file
   * @param {String} name unique deployment name
   * @param {String} script example dependency
   * @returns {Object} document entry
   */
  function makeFileDoc (name, script) {
    return {
      docType: DOC_TYPE,
      id: name + '/' + script,
      fileContents: fs.readFileSync(path.join(readFilesProcessor.basePath, script)),
      template: 'template' + path.extname(script),
      // make path relative to example output template examples/${example.id}/index,
      path: path.join('../../examples-dep', name, script),
      outputPath: path.join('examples-dep', name, script),
    };
  }

  /**
   * Creates unique folder name for the current deployment
   */
  function makeUniqueName (deployments, name) {
    if (!name) {
      name = 'deployment';
    }
    var i = 0;
    while (deployments.indexOf((name + (i ? i : ''))) > -1) {
      i++;
    }
    if (i) {
      name = name + i;
    }
    deployments.push(name);
    return name;
  }
};
{'fraction_non_alphanumeric': 0.12760371083493785, 'fraction_numerical': 0.0012252756870295817, 'mean_word_length': 2.595972309628697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4545526', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1550, 'n_words': 456}