<commit_before>//
//    █████╗ ██╗  ██╗██╗██╗     ███████╗███████╗███████╗
//   ██╔══██╗██║ ██╔╝██║██║     ██╔════╝██╔════╝╚══███╔╝
//   ███████║█████╔╝ ██║██║     █████╗  █████╗    ███╔╝
//   ██╔══██║██╔═██╗ ██║██║     ██╔══╝  ██╔══╝   ███╔╝
//   ██║  ██║██║  ██╗██║███████╗███████╗███████╗███████╗
//   ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚══════╝╚══════╝╚══════╝╚══════╝

// Rendr Requirements
// ///////////////////////////////////////////////////////////////////////////////

var writeFile          = require('fs').writeFile
var readFileSync       = require('fs').readFileSync
var path               = require('path')
var resolve            = require('resolve')
var Less               = require(resolve.sync('less', {basedir: '/usr/local/lib/node_modules'}))
var lessPlugAutoPrefix = require(resolve.sync('less-plugin-autoprefix', {basedir: '/usr/local/lib/node_modules'}))
var lessPlugCssComb    = require(resolve.sync('less-plugin-csscomb', {basedir: '/usr/local/lib/node_modules'}))
var assert             = require('assert')
var isBoolean          = require('toolz/src/lang/isBoolean')
var iterate            = require('toolz/src/async/iterate')
var concurrent         = require('toolz/src/async/concurrent')
var values             = require('toolz/src/object/values')
var pick               = require('toolz/src/object/pick')
var logger             = require('../util/logger')
var getBaseDir         = require('../util/getBaseDir')
var rsync              = require('./support').sync

// LESS engine
// ///////////////////////////////////////////////////////////////////////////////

function stylez (fp, globals, defaults, cb) {
  var ext
  var lineBreaks

  // LESS build configuration
  var env      = globals.BUILD_ENV
  var stage    = globals.BUILD_STAGE

  if (env === 'development') {
    ext = '.css'

    if (stage === 'dev') lineBreaks = 'none'
    else lineBreaks = true

    if (fp) {
      var keys = [getBaseDir(fp)]
    } else {
      var keys = ['development', 'theme', 'vendor', 'bootstrap']
    }

    var files = pick(defaults.LESSfilez, keys)

  } else {
    // For the production environment. Only difference is
    // the extension we use. module handles everything
    // else.
    if (stage === 'test') {
      ext = '.css'
      lineBreaks = true
    } else {
      ext = '-min.css'
      lineBreaks = false
    }

    var files = values(pick(defaults.LESSfilez, 'styles'))
  }

  concurrent.each(files, function (val, key, done) {
    engineLess(val, ext, lineBreaks, defaults.csscomb, function () {
      done(null, key)
    })
  }, function (err, res) {
    assert.ifError(err)
    rsync('static', 'css', defaults, function () {
      cb(null, 'stylez')
    })
  })
}

function engineLess (files, ext, lineBreaks, cssCombDefaults, cb) {
  var PLUGINS

  // Autoprefix variables
  var AUTOPREFIXER_BROWSERS = [
    'ie >= 10',
    'ie_mob >= 10',
    'ff >= 30',
    'chrome >= 34',
    'safari >= 7',
    'opera >= 23',
    'ios >= 7',
    'android >= 4.4',
    'bb >= 10'
  ]

  // LESS plugins configuration
  var autoprefix = new lessPlugAutoPrefix({
    browsers: AUTOPREFIXER_BROWSERS
  })

  var ccomb = new lessPlugCssComb(cssCombDefaults)

  PLUGINS = [autoprefix, ccomb]

  files = Array.isArray(files) ? files : [files]

  files.forEach(function (f) {
    var fn = path.basename(f, path.extname(f)) // fn = filename
    var fc = readFileSync(f, 'utf8')        // fc = file content
    Less.render(fc, {
      plugins: PLUGINS
    }, function (err, res) {
      assert.ifError(err)

      if (isBoolean(lineBreaks)) {
        var CleanCSS = require('clean-css')
        var minified = new CleanCSS({
          advanced: false,
          keepBreaks: lineBreaks
        }).minify(res.css).styles<commit_msg>replace fs.writeFile and readFileSync with toolz version<commit_after>//
//    █████╗ ██╗  ██╗██╗██╗     ███████╗███████╗███████╗
//   ██╔══██╗██║ ██╔╝██║██║     ██╔════╝██╔════╝╚══███╔╝
//   ███████║█████╔╝ ██║██║     █████╗  █████╗    ███╔╝
//   ██╔══██║██╔═██╗ ██║██║     ██╔══╝  ██╔══╝   ███╔╝
//   ██║  ██║██║  ██╗██║███████╗███████╗███████╗███████╗
//   ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚══════╝╚══════╝╚══════╝╚══════╝

// Rendr Requirements
// ///////////////////////////////////////////////////////////////////////////////

var writeFile          = require('toolz/src/file/writeFile')
var readFile           = require('toolz/src/file/readFile')
var path               = require('path')
var resolve            = require('resolve')
var Less               = require(resolve.sync('less', {basedir: '/usr/local/lib/node_modules'}))
var lessPlugAutoPrefix = require(resolve.sync('less-plugin-autoprefix', {basedir: '/usr/local/lib/node_modules'}))
var lessPlugCssComb    = require(resolve.sync('less-plugin-csscomb', {basedir: '/usr/local/lib/node_modules'}))
var assert             = require('assert')
var isBoolean          = require('toolz/src/lang/isBoolean')
var iterate            = require('toolz/src/async/iterate')
var concurrent         = require('toolz/src/async/concurrent')
var values             = require('toolz/src/object/values')
var pick               = require('toolz/src/object/pick')
var logger             = require('../util/logger')
var getBaseDir         = require('../util/getBaseDir')
var rsync              = require('./support').sync

// LESS engine
// ///////////////////////////////////////////////////////////////////////////////

function stylez (fp, globals, defaults, cb) {
  var ext
  var lineBreaks

  // LESS build configuration
  var env      = globals.BUILD_ENV
  var stage    = globals.BUILD_STAGE

  if (env === 'development') {
    ext = '.css'

    if (stage === 'dev') lineBreaks = 'none'
    else lineBreaks = true

    if (fp) {
      var keys = [getBaseDir(fp)]
    } else {
      var keys = ['development', 'theme', 'vendor', 'bootstrap']
    }

    var files = pick(defaults.LESSfilez, keys)

  } else {
    // For the production environment. Only difference is
    // the extension we use. module handles everything
    // else.
    if (stage === 'test') {
      ext = '.css'
      lineBreaks = true
    } else {
      ext = '-min.css'
      lineBreaks = false
    }

    var files = values(pick(defaults.LESSfilez, 'styles'))
  }

  concurrent.each(files, function (val, key, done) {
    engineLess(val, ext, lineBreaks, defaults.csscomb, function () {
      done(null, key)
    })
  }, function (err, res) {
    assert.ifError(err)
    rsync('static', 'css', defaults, function () {
      cb(null, 'stylez')
    })
  })
}

function engineLess (files, ext, lineBreaks, cssCombDefaults, cb) {
  var PLUGINS

  // Autoprefix variables
  var AUTOPREFIXER_BROWSERS = [
    'ie >= 10',
    'ie_mob >= 10',
    'ff >= 30',
    'chrome >= 34',
    'safari >= 7',
    'opera >= 23',
    'ios >= 7',
    'android >= 4.4',
    'bb >= 10'
  ]

  // LESS plugins configuration
  var autoprefix = new lessPlugAutoPrefix({
    browsers: AUTOPREFIXER_BROWSERS
  })

  var ccomb = new lessPlugCssComb(cssCombDefaults)

  PLUGINS = [autoprefix, ccomb]

  files = Array.isArray(files) ? files : [files]

  files.forEach(function (f) {
    var fn = path.basename(f, path.extname(f)) // fn = filename
    var fc = readFile(f, 'utf8')        // fc = file content
    Less.render(fc, {
      plugins: PLUGINS
    }, function (err, res) {
      assert.ifError(err)

      if (isBoolean(lineBreaks)) {
        var CleanCSS = require('clean-css')
        var minified = new CleanCSS({
          advanced: false,
          keepBreaks: lineBreaks
        }).minify(res.css).styles
{'fraction_non_alphanumeric': 0.23820911385678226, 'fraction_numerical': 0.004517071874584828, 'mean_word_length': 2.2143467122117846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '461040', 'n_tokens_mistral': 2708, 'n_tokens_neox': 2639, 'n_words': 547}