<commit_before>/**
 * The packager contains logic for compiling components and javascript
 * dependencies, as well as the endpoints for serving them as multiplexed XHR
 * Requests.
 *
 * @class packager (server)
 * @module Superfluous
 * @submodule Server
 */

"use strict";

var fs = require("fs");
var module_grapher = require("module-grapher");
var async = require("async");
var _ = require_vendor("underscore");
var less = require("less");
var path = require("path");
var quick_hash = require_core("server/hash");
var readfile = require_core("server/readfile");

var less_header = readfile("app/static/styles/definitions.less") +
  readfile("core/static/styles/definitions.less");

function package_less(includes, cb) {
  var included = _.map(includes, function(s) { return s.trim(); });

  var ret = {};
  async.each(included, function(mod, done) {
    var data = readfile(mod + ".css");
    if (data) {
      var hash = quick_hash(data.toString());
      less.render(less_header + data.toString(), function(err, css) {
        if (err) {
          console.log("Error rendering less module:", mod, err);
        }

        ret[mod] = {
          code: css,
          signature: hash,
          name: mod,
          type: "css",
          timestamp: parseInt(+Date.now() / 1000, 10)
        };
        done();
      });
    } else {
      done();
    }

  }, function(err) {
    cb(ret);
  });
}

function package_and_scope_less(component, module, cb) {
  var ret = {};
  var data = readfile(module + ".css");

  var module_css = ".cmp-" + component + " {\n";
  var module_end = "\n}";
  var hash = quick_hash(data.toString());
  less.render(less_header + module_css + (data || "") + module_end, function(err, css) {
    ret[module] = {
      code: css,
      signature: hash,
      name: module,
      type: "css"
    };

    cb(ret);
  });
}

function package_js(includes, cb) {
  var included = _.map(includes, function(s) { return s.trim(); });
  var excluded = [];


  var definition = {
    baseUrl: "./",
    include: included,
    out: "tmp-build",
    optimize: "uglify",
    excludeShallow: excluded
  };

<commit_msg>fallback to .less for rendering styles if .css file doesn't exist<commit_after>/**
 * The packager contains logic for compiling components and javascript
 * dependencies, as well as the endpoints for serving them as multiplexed XHR
 * Requests.
 *
 * @class packager (server)
 * @module Superfluous
 * @submodule Server
 */

"use strict";

var fs = require("fs");
var module_grapher = require("module-grapher");
var async = require("async");
var _ = require_vendor("underscore");
var less = require("less");
var path = require("path");
var quick_hash = require_core("server/hash");
var readfile = require_core("server/readfile");

var less_header = readfile("app/static/styles/definitions.less") +
  readfile("core/static/styles/definitions.less");

function readstyle(mod) {
  var data = readfile(mod + ".css");
  if (!data) {    
    data = readfile(mod + ".less");
  }
  return data;
}

function package_less(includes, cb) {
  var included = _.map(includes, function(s) { return s.trim(); });

  var ret = {};
  async.each(included, function(mod, done) {
    var data = readstyle(mod);
    if (data) {
      var hash = quick_hash(data.toString());
      less.render(less_header + data.toString(), function(err, css) {
        if (err) {
          console.log("Error rendering less module:", mod, err);
        }

        ret[mod] = {
          code: css,
          signature: hash,
          name: mod,
          type: "css",
          timestamp: parseInt(+Date.now() / 1000, 10)
        };
        done();
      });
    } else {
      done();
    }

  }, function(err) {
    cb(ret);
  });
}

function package_and_scope_less(component, module, cb) {
  var ret = {};
  var data = readstyle(module);

  var module_css = ".cmp-" + component + " {\n";
  var module_end = "\n}";
  var hash = quick_hash(data.toString());
  less.render(less_header + module_css + (data || "") + module_end, function(err, css) {
    ret[module] = {
      code: css,
      signature: hash,
      name: module,
      type: "css"
    };

    cb(ret);
  });
}

function package_js(includes, cb) {
  var included = _.map(includes, function(s) { return s.trim(); });
  var excluded = [];


  var definition = {
    baseUrl: "./",
    include: included,
    out: "tmp-build",
    optimize: "uglify",
    excludeShallow: excluded
  };


{'fraction_non_alphanumeric': 0.15743243243243243, 'fraction_numerical': 0.002702702702702703, 'mean_word_length': 2.933569530558016, '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': '2870186', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1395, 'n_words': 363}