<commit_before>beeper = require 'beeper'

gulp = require 'gulp'
plumber = require 'gulp-plumber'
sourcemaps = require 'gulp-sourcemaps'
header = require 'gulp-header'

less = require 'gulp-less'
babel = require 'gulp-babel'
gif = require 'gulp-if'

embedlr = require 'gulp-embedlr'
livereload = require 'gulp-livereload'
{platform} = require './utils'
manifest = require '../src/package.json'
args = require './args'

[
  ['darwin64', './build/darwin64/' + manifest.productName + '.app/Contents/Resources/app']
  ['linux32', './build/linux32/opt/' + manifest.name + '/resources/app']
  ['linux64', './build/linux64/opt/' + manifest.name + '/resources/app']
  ['win32', './build/win32/resources/app']
].forEach (item) ->
  [dist, dir] = item

  handleError = (err) ->
    console.error err
    beeper()

  # Compile styles
  gulp.task 'compile:' + dist + ':styles', ['clean:build:' + dist], ->
    gulp.src './src/styles/**/*.less'
      .pipe plumber handleError
      .pipe less()
      .pipe plumber.stop()
      .pipe gulp.dest dir + '/styles'
      .pipe livereload()

  # Compile browser scripts
  gulp.task 'compile:' + dist + ':scripts:browser', ['clean:build:' + dist], ->
    loggerHeader = [
      "if (__filename.indexOf('logger.js') == -1)"
      "{"
      "var __LOGGER = require.main.require('./utils/logger');"
      "var log = __LOGGER.debugLogger(__filename);"
      "var logError = __LOGGER.errorLogger(__filename, false);"
      "var logFatal = __LOGGER.errorLogger(__filename, true);"
      "__LOGGER = undefined;"
      "}"
    ].join ''

    gulp.src './src/scripts/browser/**/*.js'
      .pipe plumber handleError
      .pipe gif args.dev, sourcemaps.init()
      .pipe babel
        presets: [
          'es2015'
          'stage-0'
        ]
        plugins: [
          'transform-runtime'
          'default-import-checker'
        ]
      .pipe gif args.dev, sourcemaps.write {sourceRoot: 'src/scripts/browser'}
      .pipe gif args.dev, header "require('source-map-support').install();"
      .pipe header loggerHeader
      .pipe plumber.stop()
      .pipe gulp.dest dir + '/scripts/browser'

  # Compile renderer scripts
  gulp.task 'compile:' + dist + ':scripts:renderer', ['clean:build:' + dist], ->
    loggerHeader = [
      "if (__filename.indexOf('logger.js') == -1)"
      "{"
      "var __LOGGER = require.main.require('../scripts/renderer/logger');"
      "var log = __LOGGER.debugLogger(__filename);"
      "var logError = __LOGGER.errorLogger(__filename, false);"<commit_msg>Fixes require of logger in preload scripts<commit_after>beeper = require 'beeper'

gulp = require 'gulp'
plumber = require 'gulp-plumber'
sourcemaps = require 'gulp-sourcemaps'
header = require 'gulp-header'

less = require 'gulp-less'
babel = require 'gulp-babel'
gif = require 'gulp-if'

embedlr = require 'gulp-embedlr'
livereload = require 'gulp-livereload'
{platform} = require './utils'
manifest = require '../src/package.json'
args = require './args'

[
  ['darwin64', './build/darwin64/' + manifest.productName + '.app/Contents/Resources/app']
  ['linux32', './build/linux32/opt/' + manifest.name + '/resources/app']
  ['linux64', './build/linux64/opt/' + manifest.name + '/resources/app']
  ['win32', './build/win32/resources/app']
].forEach (item) ->
  [dist, dir] = item

  handleError = (err) ->
    console.error err
    beeper()

  # Compile styles
  gulp.task 'compile:' + dist + ':styles', ['clean:build:' + dist], ->
    gulp.src './src/styles/**/*.less'
      .pipe plumber handleError
      .pipe less()
      .pipe plumber.stop()
      .pipe gulp.dest dir + '/styles'
      .pipe livereload()

  # Compile browser scripts
  gulp.task 'compile:' + dist + ':scripts:browser', ['clean:build:' + dist], ->
    loggerHeader = [
      "if (__filename.indexOf('logger.js') == -1)"
      "{"
      "var __LOGGER = require(require('app').getAppPath() + '/scripts/browser/utils/logger');"
      "var log = __LOGGER.debugLogger(__filename);"
      "var logError = __LOGGER.errorLogger(__filename, false);"
      "var logFatal = __LOGGER.errorLogger(__filename, true);"
      "__LOGGER = undefined;"
      "}"
    ].join ''

    gulp.src './src/scripts/browser/**/*.js'
      .pipe plumber handleError
      .pipe gif args.dev, sourcemaps.init()
      .pipe babel
        presets: [
          'es2015'
          'stage-0'
        ]
        plugins: [
          'transform-runtime'
          'default-import-checker'
        ]
      .pipe gif args.dev, sourcemaps.write {sourceRoot: 'src/scripts/browser'}
      .pipe gif args.dev, header "require('source-map-support').install();"
      .pipe header loggerHeader
      .pipe plumber.stop()
      .pipe gulp.dest dir + '/scripts/browser'

  # Compile renderer scripts
  gulp.task 'compile:' + dist + ':scripts:renderer', ['clean:build:' + dist], ->
    loggerHeader = [
      "if (__filename.indexOf('logger.js') == -1)"
      "{"
      "var __LOGGER = require(require('remote').app.getAppPath() + '/scripts/renderer/logger');"
      "var log = __LOGGER.debugLogger(__filename);"
      "var logError = __LOGGER.errorLogger(__filename, false);"
{'fraction_non_alphanumeric': 0.17197576705100645, 'fraction_numerical': 0.008989642368575338, 'mean_word_length': 2.868480725623583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6397567', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1659, 'n_words': 359}