<commit_before>var fs = require('fs');
var del = require('del');
var gulp = require('gulp');
var path = require('path');
var stream = require('stream');
var jimp = require('gulp-jimp');
var batch = require('gulp-batch');
var through = require('through2');
var watch = require('gulp-watch');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var svg2png = require('gulp-svg2png');
var ghPages = require('gulp-gh-pages');
var iconfont = require('gulp-iconfont');
var runSequence = require('run-sequence');
var gulpImagemin = require('gulp-imagemin');
var child_process = require('child_process');
var consolidate = require('gulp-consolidate');

var FONT_NAME = 'cubing-icons';
var SVG_FILES = 'svgs/*/*.svg';
var TEMPLATE_FILES = 'templates/*.lodash';
var SRC_FILES = [ SVG_FILES, TEMPLATE_FILES ];

var runTimestamp = Math.round(Date.now()/1000);

gulp.task('default', ['copySvgs'], function() {
  var fontCss = fontCssPipe();
  return gulp.src(SVG_FILES)

    // We convert the SVGs to PNG, to BMP, and then back to SVG
    // in order to produce the simplest SVGs possible, as iconfont
    // is not very resilient in what it accepts.
    .pipe(svg2png())

    // svg2png looks for files on the filesystem by name, so we cannot
    // rename until after svg2png. We should really fix this bug in svg2png.
    .pipe(through.obj(function(file, enc, next) {
      file.path = path.join(path.dirname(file.path), file.relative.replace("/", "-"));
      next(null, file);
    }))

    .pipe(jimp({
      '': {
        background: '#FFFFFF', // Convert transparent to white
        type: 'bitmap',
      }
    }))
    .pipe(bmp2svg())

    // iconfont doesn't handle transformations, so we run our images through
    // gulp-imagemin first. See:
    //  https://github.com/nfroidure/svgicons2svgfont/issues/6.
    .pipe(gulpImagemin())

    // Dirty hack here to resize SVGs back to 500x500. For some reason
    // potrace is doing some scaling that iconfont doesn't like.
    .pipe(replace(/(<svg.*)width="[^"]*"/g, '$1width="500"'))
    .pipe(replace(/(<svg.*)height="[^"]*"/g, '$1height="500"'))

    .pipe(iconfont({
      fontName: FONT_NAME,
      formats: ['ttf', 'woff'],
      timestamp: runTimestamp, // get consistent builds when watching files
    }))
      .on('glyphs', function(glyphs, options) {
        // Stash glyphs so we can generate the CSS at the end.
        fontCss.glyphs = glyphs;

        gulp.src('templates/index.html.lodash')
          .pipe(consolidate('lodash', {
            glyphs: glyphs,
          }))
          .pipe(rename('index.html'))
          .pipe(gulp.dest('www/'));
      })
    .pipe(gulp.dest('www/fonts/'))
    .pipe(fontCss);
});

gulp.task('copySvgs', function() {
  return gulp.src(SVG_FILES)
           .pipe(gulp.dest('www/svgs/'));
});

gulp.task('watch', function() {
  gulp.start('default', function() {
    watch(SRC_FILES, batch(function(events, done) {
      gulp.start('default', done);
    }));
  });
});

gulp.task('deployHelper', function() {
  return gulp.src('./www/**/*.*')
    .pipe(ghPages());
});
gulp.task('deploy', function(done) {
  return runSequence('clean', 'default', 'deployHelper', done);
});

// Inspired by https://gist.github.com/domenic/ec8b0fc8ab45f39403dd
gulp.task('deployTravisHelper', function() {
  if(process.env.TRAVIS_PULL_REQUEST !== "false") {
    console.log(`Building PR #${process.env.TRAVIS_PULL_REQUEST}, not deploying`);
  } else {<commit_msg>Don't deploy when building branches that are not the master branch.<commit_after>var fs = require('fs');
var del = require('del');
var gulp = require('gulp');
var path = require('path');
var stream = require('stream');
var jimp = require('gulp-jimp');
var batch = require('gulp-batch');
var through = require('through2');
var watch = require('gulp-watch');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var svg2png = require('gulp-svg2png');
var ghPages = require('gulp-gh-pages');
var iconfont = require('gulp-iconfont');
var runSequence = require('run-sequence');
var gulpImagemin = require('gulp-imagemin');
var child_process = require('child_process');
var consolidate = require('gulp-consolidate');

var FONT_NAME = 'cubing-icons';
var SVG_FILES = 'svgs/*/*.svg';
var TEMPLATE_FILES = 'templates/*.lodash';
var SRC_FILES = [ SVG_FILES, TEMPLATE_FILES ];

var runTimestamp = Math.round(Date.now()/1000);

gulp.task('default', ['copySvgs'], function() {
  var fontCss = fontCssPipe();
  return gulp.src(SVG_FILES)

    // We convert the SVGs to PNG, to BMP, and then back to SVG
    // in order to produce the simplest SVGs possible, as iconfont
    // is not very resilient in what it accepts.
    .pipe(svg2png())

    // svg2png looks for files on the filesystem by name, so we cannot
    // rename until after svg2png. We should really fix this bug in svg2png.
    .pipe(through.obj(function(file, enc, next) {
      file.path = path.join(path.dirname(file.path), file.relative.replace("/", "-"));
      next(null, file);
    }))

    .pipe(jimp({
      '': {
        background: '#FFFFFF', // Convert transparent to white
        type: 'bitmap',
      }
    }))
    .pipe(bmp2svg())

    // iconfont doesn't handle transformations, so we run our images through
    // gulp-imagemin first. See:
    //  https://github.com/nfroidure/svgicons2svgfont/issues/6.
    .pipe(gulpImagemin())

    // Dirty hack here to resize SVGs back to 500x500. For some reason
    // potrace is doing some scaling that iconfont doesn't like.
    .pipe(replace(/(<svg.*)width="[^"]*"/g, '$1width="500"'))
    .pipe(replace(/(<svg.*)height="[^"]*"/g, '$1height="500"'))

    .pipe(iconfont({
      fontName: FONT_NAME,
      formats: ['ttf', 'woff'],
      timestamp: runTimestamp, // get consistent builds when watching files
    }))
      .on('glyphs', function(glyphs, options) {
        // Stash glyphs so we can generate the CSS at the end.
        fontCss.glyphs = glyphs;

        gulp.src('templates/index.html.lodash')
          .pipe(consolidate('lodash', {
            glyphs: glyphs,
          }))
          .pipe(rename('index.html'))
          .pipe(gulp.dest('www/'));
      })
    .pipe(gulp.dest('www/fonts/'))
    .pipe(fontCss);
});

gulp.task('copySvgs', function() {
  return gulp.src(SVG_FILES)
           .pipe(gulp.dest('www/svgs/'));
});

gulp.task('watch', function() {
  gulp.start('default', function() {
    watch(SRC_FILES, batch(function(events, done) {
      gulp.start('default', done);
    }));
  });
});

gulp.task('deployHelper', function() {
  return gulp.src('./www/**/*.*')
    .pipe(ghPages());
});
gulp.task('deploy', function(done) {
  return runSequence('clean', 'default', 'deployHelper', done);
});

// Inspired by https://gist.github.com/domenic/ec8b0fc8ab45f39403dd
gulp.task('deployTravisHelper', function() {
  if(process.env.TRAVIS_PULL_REQUEST !== "false") {
    console.log(`Building PR #${process.env.TRAVIS_PULL_REQUEST} on branch ${process.env.TRAVIS_BRANCH}, not deploying`);
  } else if(process.env.TRAVIS_BRANCH !== "master") {
    console.log(`Building non-master branch ${process.env.TRAVIS_BRANCH}, not deploying`);
  } else {
{'fraction_non_alphanumeric': 0.1737370918224951, 'fraction_numerical': 0.010605637733742674, 'mean_word_length': 3.4654205607476634, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 8, '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': '2581341', 'n_tokens_mistral': 2523, 'n_tokens_neox': 2386, 'n_words': 562}