<commit_before>'use strict';

var gulp = require('gulp');
var es = require("event-stream")
var $ = require('gulp-load-plugins')({
  pattern: ['gulp-*', 'main-bower-files', 'uglify-save-license', 'del']
});
// TODO require gulp plugins normally instead of using gulp-load-plugins - makes the code easier to understand

var connect = require('gulp-connect');

function handleError(err) {
  console.error(err.toString());
  this.emit('end');
}

gulp.task('styles', ['wiredep'],  function () {
  return gulp.src([
      'src/{app,components}/**/*.less',
      '!src/{app,components}/**/_*.less'
    ])
    .pipe($.less({
      paths: [
        'src/bower_components',
        'src/app',
        'src/components'
      ]
    }))
    .on('error', handleError)
    .pipe($.autoprefixer('last 1 version'))
    .pipe(gulp.dest('.tmp'))
    .pipe($.size());
});

gulp.task('scripts', function () {
  var angularticsFilter = $.filter('!**/angulartics-ga.js');
  return gulp.src('src/{app,components}/**/*.js')
    .pipe(angularticsFilter)
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.size());
});

gulp.task('partials', function () {
  return gulp.src('src/{app,components}/**/*.html')
    .pipe($.htmlmin({
      collapseWhitespace: true
    }))
    .pipe($.ngHtml2js({
      moduleName: 'civicClient'
    }))
    .pipe(gulp.dest('.tmp'))
    .pipe($.size());
});

gulp.task('html', ['styles', 'scripts', 'partials', 'cdnize'], function () {
  var htmlFilter = $.filter('*.html', {restore: true});
  var jsFilter = $.filter('**/*.js', {restore: true});
  var cssFilter = $.filter('**/*.css', {restore: true});

  return gulp.src('.tmp/*.html')
    .pipe($.inject(
      // stream JS files in app/component directories
      gulp.src('.tmp/{app,components}/**/*.js'),
      {
        starttag: '<!-- inject:partials -->',
        addRootSlash: false,
        addPrefix: '../'
      }))


    // parse index.html for links to asset (scripts, html, css), group, concatenate, add to stream
    //This call to useref will parse all app assets and concatenate
    //It also filters out any remote assets which have been cdnized,
    //leaving only those which couldn't behind to be parsed into vendor files
    .pipe($.useref({
      //this function scans build:filter_cdn blocks for assets which have been cdnized
      filter_cdn: function(content, target, mode, altPath){
        var scripts = content.split(/\r?\n/gm);
        var output = "";
        //prepare the build tag for the next run of useref
        var parse = "<!-- build:"+mode+"("+altPath+") "+target+" -->\n";
        scripts.forEach(function(line){
          if(line.search(/(cloudflare\.com|googleapis\.com|jsdelivr\.net)/g)!=-1)
          {
            output+=line+"\n";
          }
          else {
            parse+=line+"\n";
          }
        });
        parse+="<!-- endbuild -->";
        return output+"\n"+parse;
      }
    }))

    .pipe($.useref()) //Second call to useref picks up the vendor files which weren't cdnized
    //and concatenates into vendor.{js,css}
<commit_msg>Fixed logic in useref cdn filtering<commit_after>'use strict';

var gulp = require('gulp');
var es = require("event-stream")
var $ = require('gulp-load-plugins')({
  pattern: ['gulp-*', 'main-bower-files', 'uglify-save-license', 'del']
});
// TODO require gulp plugins normally instead of using gulp-load-plugins - makes the code easier to understand

var connect = require('gulp-connect');

function handleError(err) {
  console.error(err.toString());
  this.emit('end');
}

gulp.task('styles', ['wiredep'],  function () {
  return gulp.src([
      'src/{app,components}/**/*.less',
      '!src/{app,components}/**/_*.less'
    ])
    .pipe($.less({
      paths: [
        'src/bower_components',
        'src/app',
        'src/components'
      ]
    }))
    .on('error', handleError)
    .pipe($.autoprefixer('last 1 version'))
    .pipe(gulp.dest('.tmp'))
    .pipe($.size());
});

gulp.task('scripts', function () {
  var angularticsFilter = $.filter('!**/angulartics-ga.js');
  return gulp.src('src/{app,components}/**/*.js')
    .pipe(angularticsFilter)
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.size());
});

gulp.task('partials', function () {
  return gulp.src('src/{app,components}/**/*.html')
    .pipe($.htmlmin({
      collapseWhitespace: true
    }))
    .pipe($.ngHtml2js({
      moduleName: 'civicClient'
    }))
    .pipe(gulp.dest('.tmp'))
    .pipe($.size());
});

gulp.task('html', ['styles', 'scripts', 'partials', 'cdnize'], function () {
  var htmlFilter = $.filter('*.html', {restore: true});
  var jsFilter = $.filter('**/*.js', {restore: true});
  var cssFilter = $.filter('**/*.css', {restore: true});

  return gulp.src('.tmp/*.html')
    .pipe($.inject(
      // stream JS files in app/component directories
      gulp.src('.tmp/{app,components}/**/*.js'),
      {
        starttag: '<!-- inject:partials -->',
        addRootSlash: false,
        addPrefix: '../'
      }))


    // parse index.html for links to asset (scripts, html, css), group, concatenate, add to stream
    //This call to useref will parse all app assets and concatenate
    //It also filters out any remote assets which have been cdnized,
    //leaving only those which couldn't behind to be parsed into vendor files
    .pipe($.useref({
      //this function scans build:filter_cdn blocks for assets which have been cdnized
      filter_cdn: function(content, target, mode, altPath){
        var scripts = content.split(/\r?\n/gm);
        var output = "";
        //prepare the build tag for the next run of useref
        var parse = "<!-- build:"+mode+(altPath?"("+altPath+") ":' ')+target+" -->\n";
        scripts.forEach(function(line){
          if(line.search(/(cloudflare\.com|googleapis\.com|jsdelivr\.net)/g)!=-1)
          {
            output+=line+"\n";
          }
          else {
            parse+=line+"\n";
          }
        });
        parse+="<!-- endbuild -->";
        return output+"\n"+parse;
      }
    }))

    .pipe($.useref()) //Second call to useref picks up the vendor files which weren't cdnized
    //and concatenates into vendor.{js,css}

{'fraction_non_alphanumeric': 0.19593941347083468, 'fraction_numerical': 0.0009668063164679343, 'mean_word_length': 2.705671641791045, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 9, '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': '1144638', 'n_tokens_mistral': 2050, 'n_tokens_neox': 1991, 'n_words': 457}