<commit_before>/*jslint node: true */ // allow 'require' global
'use strict';

var gulp = require('gulp'),
  concat = require('gulp-concat'),
  concatUtil = require('gulp-concat-util'),
  del = require('del'),
  util = require('gulp-util'),
  es = require('event-stream'),
  ts = require('gulp-typescript'),
  bump = require('gulp-bump'),
  git = require('gulp-git'),
  es = require('event-stream'),
  through = require('through2'),
  hyperShaders = require('./tools/gulp-hyper-shaders'),
  mainBowerFiles = require('main-bower-files'),
  filter = require('gulp-filter'),
  tagVersion = require('gulp-tag-version'),
  inquirer = require('inquirer'),
  path = require('path');

var sources = {
  lib: {
    js: ['./src/**/*.js'],
    tsd: ['./src/*.d.ts'],
    ts: ['./src/**/*.ts', '!./src/*.d.ts'],
    tsMain: ['./src/renderer/public/*.ts'],
    shaders: ['./src/renderer/shaders/**/*.glsl']
  }
};
var shaderTemplateSource = './src/renderer/shaders/ShadersTemplate.txt';

var destinations = {
  pub_js: './dist/',
  pub_lib: './dist/lib/'
};

gulp.task('dep:lib', function() {
  gulp.src(mainBowerFiles()).pipe(gulp.dest(destinations.pub_lib));
});

function addSource(inp) {
  var p = through.obj();
  return es.duplex(p, es.merge(inp, p));
}

gulp.task('js:lib', function() {
  var tsProject = ts.createProject('tsconfig.json', {
    sortOutput: true,
    out: 'hyper3d.js'
  });
  
  var tsFiles = gulp.src(sources.lib.tsMain);
    
  var shaderChunks = gulp.src(sources.lib.shaders)
    .pipe(hyperShaders(shaderTemplateSource ));
    
  var tsStream = tsFiles
    .pipe(addSource(shaderChunks))
    .pipe(ts(tsProject));

  return es.merge(
    tsStream.dts.pipe(gulp.dest(destinations.pub_js)),
    tsStream.js
    .pipe(concatUtil.header('(function(Hyper){\n"use strict";\n'))
    .pipe(concatUtil.footer('})(this.Hyper = this.Hyper || {});'))
    .pipe(gulp.dest(destinations.pub_js)),
    gulp.src(
      sources.lib.js,
      { base: 'src' }
    )
    .pipe( gulp.dest(destinations.pub_js) ),
    gulp.src(
      sources.lib.tsd,
      { base: 'src' }
    )
    .pipe( gulp.dest(destinations.pub_js) )
  );
});

// deletes the dist folder for a clean build
gulp.task('clean', function() {
  del(['./dist'], function(err, deletedFiles) {
    if(deletedFiles.length) {
      util.log('Deleted', util.colors.red(deletedFiles.join(' ,')) );
    } else {
      util.log(util.colors.yellow('/dist directory empty - nothing to delete'));
    }
  });
});

gulp.task('build', [
  'js:lib',
  'dep:lib'
]);

gulp.task('bump', function() {

  var questions = [
    {
      type: 'input',
      name: 'bump',
      message: 'Are you sure you want to bump the patch version? [Y/N]'
    }
  ];

  inquirer.prompt( questions, function( answers ) {
    if(answers.bump === 'Y') {

      return gulp.src(['./package.json', './bower.json'])
          .pipe(bump({type: 'patch'}))
          .pipe(gulp.dest('./'))
          .pipe(git.commit('bump patch version'))
          .pipe(filter('package.json'))  // read package.json for the new version
          .pipe(tagVersion());           // create tag

    }
  });
});

// watch scripts, styles, and templates
gulp.task('watch', function() {
  gulp.watch(sources.lib.ts, ['js:lib']);
  gulp.watch(sources.lib.js, ['js:lib']);
  gulp.watch(sources.lib.shaders, ['js:lib']);
  gulp.watch([shaderTemplateSource], ['js:lib']);
  gulp.watch(mainBowerFiles().concat(['bower.json']), ['dep:lib']);
});

// default
gulp.task('default', ['build', 'watch']);<commit_msg>AMD & CommonJS support (no d.ts yet)<commit_after>/*jslint node: true */ // allow 'require' global
'use strict';

var gulp = require('gulp'),
  concat = require('gulp-concat'),
  concatUtil = require('gulp-concat-util'),
  del = require('del'),
  util = require('gulp-util'),
  es = require('event-stream'),
  ts = require('gulp-typescript'),
  bump = require('gulp-bump'),
  git = require('gulp-git'),
  es = require('event-stream'),
  through = require('through2'),
  hyperShaders = require('./tools/gulp-hyper-shaders'),
  mainBowerFiles = require('main-bower-files'),
  filter = require('gulp-filter'),
  tagVersion = require('gulp-tag-version'),
  inquirer = require('inquirer'),
  path = require('path');

var sources = {
  lib: {
    js: ['./src/**/*.js'],
    tsd: ['./src/*.d.ts'],
    ts: ['./src/**/*.ts', '!./src/*.d.ts'],
    tsMain: ['./src/renderer/public/*.ts'],
    shaders: ['./src/renderer/shaders/**/*.glsl']
  }
};
var shaderTemplateSource = './src/renderer/shaders/ShadersTemplate.txt';

var destinations = {
  pub_js: './dist/',
  pub_lib: './dist/lib/'
};

gulp.task('dep:lib', function() {
  gulp.src(mainBowerFiles()).pipe(gulp.dest(destinations.pub_lib));
});

function addSource(inp) {
  var p = through.obj();
  return es.duplex(p, es.merge(inp, p));
}

gulp.task('js:lib', function() {
  var tsProject = ts.createProject('tsconfig.json', {
    sortOutput: true,
    out: 'hyper3d.js'
  });
  
  var tsFiles = gulp.src(sources.lib.tsMain);
    
  var shaderChunks = gulp.src(sources.lib.shaders)
    .pipe(hyperShaders(shaderTemplateSource ));
    
  var tsStream = tsFiles
    .pipe(addSource(shaderChunks))
    .pipe(ts(tsProject));

  return es.merge(
    tsStream.dts
    .pipe(gulp.dest(destinations.pub_js)),
    
    tsStream.js
    .pipe(concatUtil.header(
      '(function(Hyper){\n"use strict";\n'))
    .pipe(concatUtil.footer(
      '})(function(){\n' + 
      '  if (typeof define === "function" && define.amd) {\n' +
      '    var obj = {}; define(function(){return obj;});\n' +
      '    return obj;\n' +
      '  } else if (typeof module !== "undefined" && module.exports) {\n' +
      '    return module.exports = {};\n' +
      '  } else {\n' +
      '    return this.Hyper = this.Hyper || {};\n' +
      '  }\n' +
      '}.call(this));'))
    .pipe(gulp.dest(destinations.pub_js)),
    
    gulp.src(
      sources.lib.js,
      { base: 'src' }
    )
    .pipe( gulp.dest(destinations.pub_js) ),
    
    gulp.src(
      sources.lib.tsd,
      { base: 'src' }
    )
    .pipe( gulp.dest(destinations.pub_js) )
  );
});

// deletes the dist folder for a clean build
gulp.task('clean', function() {
  del(['./dist'], function(err, deletedFiles) {
    if(deletedFiles.length) {
      util.log('Deleted', util.colors.red(deletedFiles.join(' ,')) );
    } else {
      util.log(util.colors.yellow('/dist directory empty - nothing to delete'));
    }
  });
});

gulp.task('build', [
  'js:lib',
  'dep:lib'
]);

gulp.task('bump', function() {

  var questions = [
    {
      type: 'input',
      name: 'bump',
      message: 'Are you sure you want to bump the patch version? [Y/N]'
    }
  ];

  inquirer.prompt( questions, function( answers ) {
    if(answers.bump === 'Y') {

      return gulp.src(['./package.json', './bower.json'])
          .pipe(bump({type: 'patch'}))
          .pipe(gulp.dest('./'))
          .pipe(git.commit('bump patch version'))
          .pipe(filter('package.json'))  // read package.json for the new version
          .pipe(tagVersion());           // create tag

    }
  });
});

// watch scripts, styles, and templates
gulp.task('watch', function() {
  gulp.watch(sources.lib.ts, ['js:lib']);
  gulp.watch(sources.lib.tsd, ['js:lib']);
  gulp.watch(sources.lib.js, ['js:lib']);
  gulp.watch(sources.lib.shaders, ['js:lib']);
  gulp.watch([shaderTemplateSource], ['js:lib']);
  gulp.watch(mainBowerFiles().concat(['bower.json']), ['dep:lib']);
});

// default
gulp.task('default', ['build', 'watch']);
{'fraction_non_alphanumeric': 0.2119754076450147, 'fraction_numerical': 0.0005346164127238706, 'mean_word_length': 3.069059271343121, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7094272', 'n_tokens_mistral': 2701, 'n_tokens_neox': 2685, 'n_words': 462}