<commit_before>'use strict'

var watchify    = require("watchify")
var browserify  = require("browserify")
var source      = require("vinyl-source-stream")
var map         = require("vinyl-map")
var browserSync = require("browser-sync")
var gutil       = require("gulp-util")
var nodemon     = require("gulp-nodemon")
var rename      = require("gulp-rename")
var uglify      = require("gulp-uglify")
var CleanCSS    = require("clean-css")
var sourcemaps  = require("gulp-sourcemaps")
var reload      = browserSync.reload
var path        = require("path")
var assign      = require("object-assign")

var coffeeify   = require("coffeeify")
var stylus      = require("gulp-stylus")
var nib         = require("nib")

var historyApiFallback = require("connect-history-api-fallback")

var defaults = {
  port: 3000,
  scripts: [],
  styles: {
    src: [],
    watch: false
  },
  server: false,
  paths: {
    dest: 'public',
    scripts: 'js',
    styles: 'css'
  },
  browserify: {},
  uglify: {},
  minify: {},
}

var watch = false

module.exports = function(gulp, options) {
  var config = assign(defaults, options)

  gulp.task('scripts', function(done) {
    var browserifyConfig = assign({
      extensions: [".coffee"],
      debug: watch,
      cache: {},
      packageCache: {},
      fullPaths: true
    }, config.browserify);

    var queue = config.scripts.length || 1

    var handleComplete = function() {
      if (!queue) return
      queue--
      if (queue < 1) done()
    }

    var handleError = function(err) {
      gutil.log("Browserify Error:", err.message)
      this.emit('end')
    }

    var bundle = function(script) {
      var b = browserify(script, browserifyConfig)
      if (watch) b = watchify(b)
      var rebundle = function() {
        b.bundle()
          .on('error', handleError)
          .pipe(source(path.basename(script)))
          .pipe(rename({extname: ".js"}))
          .pipe(gulp.dest(path.join(config.paths.dest, config.paths.scripts)))
          .on('end', handleComplete)
          .pipe(reload({stream: true}))
      }

      config.onBundle && config.onBundle(b)
      b.on('update', rebundle)
      b.transform(coffeeify)
      rebundle()
    }

    config.scripts.forEach(bundle)
  });

  gulp.task('styles', function() {
    gulp.src(config.styles.src)
      .pipe(sourcemaps.init())
      .pipe(stylus({
        'include css': true,
        use: nib()
      }))
      .pipe(sourcemaps.write())
      .pipe(gulp.dest(path.join(config.paths.dest, config.paths.styles)))
      .pipe(reload({stream: true}))
  })

  gulp.task('uglify', ['scripts'], function(done) {
    gulp.src(path.join(config.paths.dest, config.paths.scripts, '**/*.js'))
      .pipe(uglify(config.uglify))
      .pipe(gulp.dest(path.join(config.paths.dest, config.paths.scripts)))
  })

  gulp.task('minify', ['styles'], function(done) {
    var minify = map(function(buff, filename) {
      return new CleanCSS(config.minify).minify(buff.toString()).styles
    })
    gulp.src(path.join(config.paths.dest, config.paths.styles, '**/*.css'))<commit_msg>return gulp.src for more reliable task dep timing<commit_after>'use strict'

var watchify    = require("watchify")
var browserify  = require("browserify")
var source      = require("vinyl-source-stream")
var map         = require("vinyl-map")
var browserSync = require("browser-sync")
var gutil       = require("gulp-util")
var nodemon     = require("gulp-nodemon")
var rename      = require("gulp-rename")
var uglify      = require("gulp-uglify")
var CleanCSS    = require("clean-css")
var sourcemaps  = require("gulp-sourcemaps")
var reload      = browserSync.reload
var path        = require("path")
var assign      = require("object-assign")

var coffeeify   = require("coffeeify")
var stylus      = require("gulp-stylus")
var nib         = require("nib")

var historyApiFallback = require("connect-history-api-fallback")

var defaults = {
  port: 3000,
  scripts: [],
  styles: {
    src: [],
    watch: false
  },
  server: false,
  paths: {
    dest: 'public',
    scripts: 'js',
    styles: 'css'
  },
  browserify: {},
  uglify: {},
  minify: {},
}

var watch = false

module.exports = function(gulp, options) {
  var config = assign(defaults, options)

  gulp.task('scripts', function(done) {
    var browserifyConfig = assign({
      extensions: [".coffee"],
      debug: watch,
      cache: {},
      packageCache: {},
      fullPaths: true
    }, config.browserify);

    var queue = config.scripts.length || 1

    var handleComplete = function() {
      if (!queue) return
      queue--
      if (queue < 1) done()
    }

    var handleError = function(err) {
      gutil.log("Browserify Error:", err.message)
      this.emit('end')
    }

    var bundle = function(script) {
      var b = browserify(script, browserifyConfig)
      if (watch) b = watchify(b)
      var rebundle = function() {
        b.bundle()
          .on('error', handleError)
          .pipe(source(path.basename(script)))
          .pipe(rename({extname: ".js"}))
          .pipe(gulp.dest(path.join(config.paths.dest, config.paths.scripts)))
          .on('end', handleComplete)
          .pipe(reload({stream: true}))
      }

      config.onBundle && config.onBundle(b)
      b.on('update', rebundle)
      b.transform(coffeeify)
      rebundle()
    }

    config.scripts.forEach(bundle)
  });

  gulp.task('styles', function() {
    return gulp.src(config.styles.src)
      .pipe(sourcemaps.init())
      .pipe(stylus({
        'include css': true,
        use: nib()
      }))
      .pipe(sourcemaps.write())
      .pipe(gulp.dest(path.join(config.paths.dest, config.paths.styles)))
      .pipe(reload({stream: true}))
  })

  gulp.task('uglify', ['scripts'], function(done) {
    return gulp.src(path.join(config.paths.dest, config.paths.scripts, '**/*.js'))
      .pipe(uglify(config.uglify))
      .pipe(gulp.dest(path.join(config.paths.dest, config.paths.scripts)))
  })

  gulp.task('minify', ['styles'], function(done) {
    var minify = map(function(buff, filename) {
      return new CleanCSS(config.minify).minify(buff.toString()).styles
    })
    return gulp.src(path.join(config.paths.dest, config.paths.styles, '**/*.css'))
{'fraction_non_alphanumeric': 0.16228847703464946, 'fraction_numerical': 0.0019339242546333602, 'mean_word_length': 2.8214285714285716, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1900164', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1991, 'n_words': 395}