<commit_before>"use strict";

const path   = require('path');
const fs     = require('fs');
const semver = require('semver');
const webpack = require('webpack');

var plugins = require('webpack-load-plugins')();

const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), {encoding: 'utf8'}));

function getLicense(pkg) {
  return `@license twgl.js ${pkg.version} Copyright (c) 2015, <NAME> All Rights Reserved.
Available via the MIT license.
see: http://github.com/greggman/twgl.js for details`;
}

var replaceHandlers = {};
function registerReplaceHandler(keyword, handler) {
  replaceHandlers[keyword] = handler;
}

/**
 * Replace %(id)s in strings with values in objects(s)
 *
 * Given a string like `"Hello %(name)s from %(user.country)s"`
 * and an object like `{name:"Joe",user:{country:"USA"}}` would
 * return `"Hello Joe from USA"`.
 *
 * @param {string} str string to do replacements in
 * @param {Object|Object[]} params one or more objects.
 * @returns {string} string with replaced parts
 */
var replaceParams = (function() {
  var replaceParamsRE = /%\(([^\)]+)\)s/g;

  return function(str, params) {
    if (!params.length) {
      params = [params];
    }

    return str.replace(replaceParamsRE, function(match, key) {
      var colonNdx = key.indexOf(":");
      if (colonNdx >= 0) {
        try {
          var args = hanson.parse("{" + key + "}");
          var handlerName = Object.keys(args)[0];
          var handler = replaceHandlers[handlerName];
          if (handler) {
            return handler(args[handlerName]);
          }
          console.error("unknown substition handler: " + handlerName);
        } catch (e) {
          console.error(e);
          console.error("bad substitution: %(" + key + ")s");
        }
      } else {
        // handle normal substitutions.
        var keys = key.split('.');
        for (var ii = 0; ii < params.length; ++ii) {
          var obj = params[ii];
          for (var jj = 0; jj < keys.length; ++jj) {
            var key = keys[jj];
            obj = obj[key];
            if (obj === undefined) {
              break;
            }
          }
          if (obj !== undefined) {
            return obj;
          }
        }
      }
      console.error("unknown key: " + key);
      return "%(" + key + ")s";
    });
  };
}());

module.exports = function(grunt) {

  require('load-grunt-tasks')(grunt);

  var srcFiles = [
    'src/twgl.js',
    'src/attributes.js',
    'src/draw.js',
    'src/framebuffers.js',
    'src/programs.js',
    'src/textures.js',
    'src/typedarrays.js',
    'src/vertex-arrays.js',
  ];

  var thirdPartyFiles = [
  ];

  var extraFiles = [
    'src/v3.js',
    'src/m4.js',
    'src/primitives.js',
  ];

  var docsFiles = srcFiles.concat(extraFiles, 'README.md');
  var libFiles = srcFiles.concat(thirdPartyFiles);
  var fullLibFiles = [].concat(srcFiles, extraFiles, thirdPartyFiles);

  grunt.initConfig({
    jsdoc: {
      docs: {
        src: docsFiles,
        options: {
          destination: 'docs',
          configure: 'build/jsdoc.conf.json',
//          template: 'build/jsdoc-template/template',
          template: './node_modules/minami',
          outputSourceFiles: false,
        },
      },
    },
    webpack: {
      full: {
        entry: './src/twgl-full.js',
        plugins: [
          new webpack.BannerPlugin(getLicense(pkg)),
        ],
        module: {
          loaders: [
            {
              test: /\.js$/,
              loader: 'babel-loader',
              query: {
                presets: ['stage-0', 'es2015'],
              },
            },
          ],
        },
        output: {
          path: path.join(__dirname, 'dist/2.x'),
          filename: 'twgl-full.js',
          library: 'twgl',
          libraryTarget: 'umd',
        },
      },
      base: {
        entry: './src/twgl-base.js',
        plugins: [
          new webpack.BannerPlugin(getLicense(pkg)),
        ],
        module: {
          loaders: [
            {
              test: /\.js$/,
              loader: 'babel-loader',
              query: {
                presets: ['stage-0', 'es2015'],
              },
            },
          ],
        },
        output: {
          path: path.join(__dirname, 'dist/2.x'),
          filename: 'twgl.js',
          library: 'twgl',
          libraryTarget: 'umd',
        },
      },
      fullMin: {
        entry: './src/twgl-full.js',
        plugins: [
          new webpack.BannerPlugin(getLicense(pkg)),
          new webpack.optimize.UglifyJsPlugin({
            compress: {
              warnings: false,
            },
            mangle: true,
          }),
        ],
        module: {<commit_msg>add example of mangling properties<commit_after>"use strict";

const path   = require('path');
const fs     = require('fs');
const semver = require('semver');
const webpack = require('webpack');

var plugins = require('webpack-load-plugins')();

const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), {encoding: 'utf8'}));

function getLicense(pkg) {
  return `@license twgl.js ${pkg.version} Copyright (c) 2015, <NAME> All Rights Reserved.
Available via the MIT license.
see: http://github.com/greggman/twgl.js for details`;
}

var replaceHandlers = {};
function registerReplaceHandler(keyword, handler) {
  replaceHandlers[keyword] = handler;
}

/**
 * Replace %(id)s in strings with values in objects(s)
 *
 * Given a string like `"Hello %(name)s from %(user.country)s"`
 * and an object like `{name:"Joe",user:{country:"USA"}}` would
 * return `"Hello Joe from USA"`.
 *
 * @param {string} str string to do replacements in
 * @param {Object|Object[]} params one or more objects.
 * @returns {string} string with replaced parts
 */
var replaceParams = (function() {
  var replaceParamsRE = /%\(([^\)]+)\)s/g;

  return function(str, params) {
    if (!params.length) {
      params = [params];
    }

    return str.replace(replaceParamsRE, function(match, key) {
      var colonNdx = key.indexOf(":");
      if (colonNdx >= 0) {
        try {
          var args = hanson.parse("{" + key + "}");
          var handlerName = Object.keys(args)[0];
          var handler = replaceHandlers[handlerName];
          if (handler) {
            return handler(args[handlerName]);
          }
          console.error("unknown substition handler: " + handlerName);
        } catch (e) {
          console.error(e);
          console.error("bad substitution: %(" + key + ")s");
        }
      } else {
        // handle normal substitutions.
        var keys = key.split('.');
        for (var ii = 0; ii < params.length; ++ii) {
          var obj = params[ii];
          for (var jj = 0; jj < keys.length; ++jj) {
            var key = keys[jj];
            obj = obj[key];
            if (obj === undefined) {
              break;
            }
          }
          if (obj !== undefined) {
            return obj;
          }
        }
      }
      console.error("unknown key: " + key);
      return "%(" + key + ")s";
    });
  };
}());

module.exports = function(grunt) {

  require('load-grunt-tasks')(grunt);

  var srcFiles = [
    'src/twgl.js',
    'src/attributes.js',
    'src/draw.js',
    'src/framebuffers.js',
    'src/programs.js',
    'src/textures.js',
    'src/typedarrays.js',
    'src/vertex-arrays.js',
  ];

  var thirdPartyFiles = [
  ];

  var extraFiles = [
    'src/v3.js',
    'src/m4.js',
    'src/primitives.js',
  ];

  var docsFiles = srcFiles.concat(extraFiles, 'README.md');
  var libFiles = srcFiles.concat(thirdPartyFiles);
  var fullLibFiles = [].concat(srcFiles, extraFiles, thirdPartyFiles);

  grunt.initConfig({
    jsdoc: {
      docs: {
        src: docsFiles,
        options: {
          destination: 'docs',
          configure: 'build/jsdoc.conf.json',
//          template: 'build/jsdoc-template/template',
          template: './node_modules/minami',
          outputSourceFiles: false,
        },
      },
    },
    webpack: {
      full: {
        entry: './src/twgl-full.js',
        plugins: [
          new webpack.BannerPlugin(getLicense(pkg)),
        ],
        module: {
          loaders: [
            {
              test: /\.js$/,
              loader: 'babel-loader',
              query: {
                presets: ['stage-0', 'es2015'],
              },
            },
          ],
        },
        output: {
          path: path.join(__dirname, 'dist/2.x'),
          filename: 'twgl-full.js',
          library: 'twgl',
          libraryTarget: 'umd',
        },
      },
      base: {
        entry: './src/twgl-base.js',
        plugins: [
          new webpack.BannerPlugin(getLicense(pkg)),
        ],
        module: {
          loaders: [
            {
              test: /\.js$/,
              loader: 'babel-loader',
              query: {
                presets: ['stage-0', 'es2015'],
              },
            },
          ],
        },
        output: {
          path: path.join(__dirname, 'dist/2.x'),
          filename: 'twgl.js',
          library: 'twgl',
          libraryTarget: 'umd',
        },
      },
      fullMin: {
        entry: './src/twgl-full.js',
        plugins: [
          new webpack.BannerPlugin(getLicense(pkg)),
          new webpack.optimize.UglifyJsPlugin({
            compress: {
              warnings: false,
            },
            mangle: true,
            //mangle: {
            //  props: {
            //    ignore_quoted: true,
            //    regex: /^((?!(createElement|getContext)).)*$/,
            //  },
            //},
          }),
        ],
        module: {
{'fraction_non_alphanumeric': 0.15835929387331257, 'fraction_numerical': 0.004776739356178609, 'mean_word_length': 1.754862700228833, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 7, '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': '4457736', 'n_tokens_mistral': 3019, 'n_tokens_neox': 2934, 'n_words': 626}