<commit_before>#=========================================================================================
# Dependencies
#=========================================================================================
pkg = require('./package')
config = require('config')
_ = require('underscore')

gulp = require('gulp')
clean = require('gulp-clean')

browserify = require('browserify')
watchify = require('watchify')
source = require('vinyl-source-stream')

stylus = require('gulp-stylus')
rename = require('gulp-rename')
nib = require('nib')

jade = require('gulp-jade')

uglify = require('gulp-uglify')
minifyCSS = require('gulp-minify-css')
htmlmin = require('gulp-htmlmin')

rev = require('gulp-rev')
gzip = require('gulp-gzip')

livereload = require('gulp-livereload') if config.livereload

helpers = require('app/javascripts/shared/helpers')
log = _.bind(helpers.log, logPrefix: '[gulp]')

bundler = null # for watchify to avoid memory leaks
lastBrowserified = 0


#=========================================================================================
# Settings
#=========================================================================================
RELOAD_TRIGGERS = ['rs', 'regulp']

ASSETS_LOCATION = './public/assets'
PUBLIC_LOCATION = './public'
CORE_LOCATION = './app'

JS_TRANSFORMS = ['coffeeify', 'jadeify', 'browserify-shim']
MINIFIED_NAME = suffix: '.min'

BROWSERIFY_RATELIMIT = 1000


#=========================================================================================
# Reporters
#=========================================================================================
pathNormalize = (path)-> path.replace("#{__dirname}/", '').replace(/^\.\//, '')

benchmarkReporter = (action, startTime)->
  log("#{action} in #{((Date.now() - startTime) / 1000).toFixed(2)}s", 'magenta')

watchReporter = (e)->
  livereload.changed() if config.livereload
  log("File #{pathNormalize(e.path)} #{e.type}, flexing 💪", 'cyan')

errorReporter = (e)->
  stack = e.stack or e
  log("Browserify error!\n#{stack}", 'red bold')


#=========================================================================================
# Compilers
#=========================================================================================
compileJavascripts = (src, options)->
  bundler.close?() if bundler
  args = [src, extensions: ['.coffee', '.jade']]
  bundler = if options.watch then watchify(args...) else browserify(args...)

  bundler.require(key) for key of pkg['browserify-shim']
  bundler.transform(transform) for transform in JS_TRANSFORMS

  compile = (files)->
    startTime = Date.now()

    return if startTime - lastBrowserified < BROWSERIFY_RATELIMIT
    lastBrowserified = startTime

    watchReporter(path: file, type: 'changed') for file in files if files

    bundler.bundle(debug: config.source_maps)
      .on('error', errorReporter)
      .pipe(source(options.name))
      .pipe(gulp.dest(options.dest))
      .on('end', -> benchmarkReporter("Browserified #{src}", startTime))

  # bundler.on('file', (file)-> log("Browserifying #{pathNormalize(file)}", 'cyan'))
  bundler.on('update', compile) if options.watch
  compile()

compileStylesheets = (src, options)->
  startTime = Date.now()

  gulp.src(src)
    .pipe(stylus(
      errors: true
      # sourcemaps: config.source_maps
      use: [nib()]
      paths: ["#{__dirname}/node_modules"]
      'include css': true
      urlfunc: 'embedurl'
      linenos: true
      define:
        '$version': pkg.version
    ))
    .pipe(rename(options.name))
    .pipe(gulp.dest(options.dest))
    .on('end', -> benchmarkReporter("Stylusified #{src}", startTime))

compileTemplates = (src, options)->
  startTime = Date.now()
  env = {}

  gulp.src(src)
    .pipe(jade(
      pretty: true
      compileDebug: false
      locals: { config, env, _, helpers }
    ))
    .pipe(gulp.dest(options.dest))
    .on('end', -> benchmarkReporter("Jadeified #{src}", startTime))

processJavascripts = (options = {})->
  settings = _.extend {}, options,
    name: 'app.js'
    dest: ASSETS_LOCATION

  compileJavascripts("#{CORE_LOCATION}/javascripts/client/index.coffee", settings)

processStylesheets = (options = {})->
  settings = _.extend {}, options,
    name: 'app.css'
    dest: ASSETS_LOCATION

  compileStylesheets("#{CORE_LOCATION}/stylesheets/index.styl", settings)

processStatic = ->
  compileStylesheets "#{CORE_LOCATION}/stylesheets/static.styl",
    name: 'static.css'
    dest: PUBLIC_LOCATION

  compileTemplates ["#{CORE_LOCATION}/templates/static/**/*.jade", "!#{CORE_LOCATION}/templates/static/**/_*.jade"],
    dest: PUBLIC_LOCATION

gulp.task 'clean', -> gulp.src(ASSETS_LOCATION, read: false).pipe(clean())
gulp.task 'browserify', -> processJavascripts()
gulp.task 'stylus', -> processStylesheets()
gulp.task 'static', -> processStatic()
<commit_msg>static fix<commit_after>#=========================================================================================
# Dependencies
#=========================================================================================
pkg = require('./package')
config = require('config')
_ = require('underscore')

gulp = require('gulp')
clean = require('gulp-clean')

browserify = require('browserify')
watchify = require('watchify')
source = require('vinyl-source-stream')

stylus = require('gulp-stylus')
rename = require('gulp-rename')
nib = require('nib')

jade = require('gulp-jade')

uglify = require('gulp-uglify')
minifyCSS = require('gulp-minify-css')
htmlmin = require('gulp-htmlmin')

rev = require('gulp-rev')
gzip = require('gulp-gzip')

livereload = require('gulp-livereload') if config.livereload

helpers = require('app/javascripts/shared/helpers')
log = _.bind(helpers.log, logPrefix: '[gulp]')

bundler = null # for watchify to avoid memory leaks
lastBrowserified = 0


#=========================================================================================
# Settings
#=========================================================================================
RELOAD_TRIGGERS = ['rs', 'regulp']

ASSETS_LOCATION = './public/assets'
PUBLIC_LOCATION = './public'
CORE_LOCATION = './app'

JS_TRANSFORMS = ['coffeeify', 'jadeify', 'browserify-shim']
MINIFIED_NAME = suffix: '.min'

BROWSERIFY_RATELIMIT = 1000


#=========================================================================================
# Reporters
#=========================================================================================
pathNormalize = (path)-> path.replace("#{__dirname}/", '').replace(/^\.\//, '')

benchmarkReporter = (action, startTime)->
  log("#{action} in #{((Date.now() - startTime) / 1000).toFixed(2)}s", 'magenta')

watchReporter = (e)->
  livereload.changed() if config.livereload
  log("File #{pathNormalize(e.path)} #{e.type}, flexing 💪", 'cyan')

errorReporter = (e)->
  stack = e.stack or e
  log("Browserify error!\n#{stack}", 'red bold')


#=========================================================================================
# Compilers
#=========================================================================================
compileJavascripts = (src, options)->
  bundler.close?() if bundler
  args = [src, extensions: ['.coffee', '.jade']]
  bundler = if options.watch then watchify(args...) else browserify(args...)

  bundler.require(key) for key of pkg['browserify-shim']
  bundler.transform(transform) for transform in JS_TRANSFORMS

  compile = (files)->
    startTime = Date.now()

    return if startTime - lastBrowserified < BROWSERIFY_RATELIMIT
    lastBrowserified = startTime

    watchReporter(path: file, type: 'changed') for file in files if files

    bundler.bundle(debug: config.source_maps)
      .on('error', errorReporter)
      .pipe(source(options.name))
      .pipe(gulp.dest(options.dest))
      .on('end', -> benchmarkReporter("Browserified #{src}", startTime))

  # bundler.on('file', (file)-> log("Browserifying #{pathNormalize(file)}", 'cyan'))
  bundler.on('update', compile) if options.watch
  compile()

compileStylesheets = (src, options)->
  startTime = Date.now()

  gulp.src(src)
    .pipe(stylus(
      errors: true
      # sourcemaps: config.source_maps
      use: [nib()]
      paths: ["#{__dirname}/node_modules"]
      'include css': true
      urlfunc: 'embedurl'
      linenos: true
      define:
        '$version': pkg.version
    ))
    .pipe(rename(options.name))
    .pipe(gulp.dest(options.dest))
    .on('end', -> benchmarkReporter("Stylusified #{src}", startTime))

compileTemplates = (src, options)->
  startTime = Date.now()
  env = {}
  getAsset = helpers.noop

  gulp.src(src)
    .pipe(jade(
      pretty: true
      compileDebug: false
      locals: { config, env, _, helpers, getAsset }
    ))
    .pipe(gulp.dest(options.dest))
    .on('end', -> benchmarkReporter("Jadeified #{src}", startTime))

processJavascripts = (options = {})->
  settings = _.extend {}, options,
    name: 'app.js'
    dest: ASSETS_LOCATION

  compileJavascripts("#{CORE_LOCATION}/javascripts/client/index.coffee", settings)

processStylesheets = (options = {})->
  settings = _.extend {}, options,
    name: 'app.css'
    dest: ASSETS_LOCATION

  compileStylesheets("#{CORE_LOCATION}/stylesheets/index.styl", settings)

processStatic = ->
  compileStylesheets "#{CORE_LOCATION}/stylesheets/static.styl",
    name: 'static.css'
    dest: PUBLIC_LOCATION

  compileTemplates ["#{CORE_LOCATION}/templates/static/**/*.jade", "!#{CORE_LOCATION}/templates/static/**/_*.jade"],
    dest: PUBLIC_LOCATION

gulp.task 'clean', -> gulp.src(ASSETS_LOCATION, read: false).pipe(clean())
gulp.task 'browserify', -> processJavascripts()
gulp.task 'stylus', -> processStylesheets()
gulp.task 'static', -> processStatic()

{'fraction_non_alphanumeric': 0.29434858973034406, 'fraction_numerical': 0.0020663291662361815, 'mean_word_length': 5.138237159162967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '3897686', 'n_tokens_mistral': 3011, 'n_tokens_neox': 2853, 'n_words': 562}