<commit_before>const gulp = require('gulp');
const { series } = gulp;
const glob = require('glob');
const shell = cmd => require('child_process').execSync(cmd, { stdio: [0, 1, 2] });
const del = require('del');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const $ = require('gulp-load-plugins')();
const browserify = require('browserify');
const tsify = require('tsify');
const Server = require('karma').Server;

const pkg = require('./package.json');
const config = {
  browsers: ['Chrome', 'Firefox'].concat((os => {
    switch (os) {
      case 'Windows_NT':
        return [];
      case 'Darwin':
        return [];
     default:
        return [];
    }
  })(require('os').type())),
  ts: {
    dist: {
      src: [
        '*.ts'
      ],
      dest: 'dist'
    },
    test: {
      src: [
        '*.ts',
        'src/**/*.ts',
        'test/**/*.ts'
      ],
      dest: 'dist'
    }
  },
  site: {
    js: './gh-pages/assets/js/lib',
  },
  banner: [
    `/*! ${pkg.name} v${pkg.version} ${pkg.repository.url} | (c) 2012, ${pkg.author} | ${pkg.license} License */`,
    ''
  ].join('\n'),
  module: `
(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
      define([], factory);
  } else if (typeof module === 'object' && module.exports) {
      module.exports = factory();
  } else {
      root.commonJsStrict = factory();
  }
}(typeof self !== 'undefined' ? self : this, function () {
  return require('${pkg.name}');
}));
`,
  clean: [
    'dist',
    'gh-pages/assets/*/**/lib',
  ]
};

function parallel(...tasks) {
  return () =>
    shell(`concurrently ${tasks.map(task => `"gulp ${task}"`).join(' ')}`);
}

function compile(src, watch = false) {
  let done = true;
  return browserify(
    Object.values(src).map(p => glob.sync(p)),
    {
      cache: {},
      packageCache: {},
    })
    .require(`./index.ts`, { expose: pkg.name })
    .plugin(tsify, { global: true, ...require('./tsconfig.json').compilerOptions })
    .bundle()
    .on("error", err => done = console.log(err + '') || watch)
    .pipe(source(`${pkg.name}.js`))
    .pipe(buffer())
    .pipe($.derequire())
    .once("finish", () => done || process.exit(1))
    .pipe($.footer(config.module));
}

gulp.task('ts:dev', () =>
  gulp.watch(config.ts.test.src, { ignoreInitial: false }, () =>
    compile(config.ts.test.src, true)
      .pipe($.rename({ extname: '.test.js' }))
      .pipe(gulp.dest(config.ts.test.dest))));

gulp.task('ts:test', () =>
  compile(config.ts.test.src)
    .pipe($.rename({ extname: '.test.js' }))
    .pipe(gulp.dest(config.ts.test.dest))
    .pipe($.eslint({
      'parserOptions': {
        'ecmaVersion': 2020,
      },
      'env': {
        'es2020': true,
      },
      'plugins': ['redos'],
      'rules': {
        'redos/no-vulnerable': [
          'error',
          {
            ignoreErrors: false,
          },
        ],
      },
    }))
    .pipe($.eslint.format())
    .pipe($.eslint.failAfterError()));

gulp.task('ts:dist', () =>
  compile(config.ts.dist.src)
    .pipe($.unassert())
    .pipe($.header(config.banner))
    .pipe(gulp.dest(config.site.js))
    .pipe(gulp.dest(config.ts.dist.dest)));

gulp.task('ts:view', () =>
  gulp.watch(config.ts.dist.src, { ignoreInitial: false }, () =>
    compile(config.ts.dist.src, true)
      .pipe($.unassert())
      .pipe($.header(config.banner))
      .pipe(gulp.dest(config.site.js))));

gulp.task('karma:dev', done =>
  void new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    preprocessors: {
      'dist/*.js': ['espower']
    },
    singleRun: false,
  }, done).start());

gulp.task('karma:test', done =>
  void new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    reporters: ['dots', 'coverage-istanbul'],
    preprocessors: {<commit_msg>Refactoring<commit_after>const gulp = require('gulp');
const { series } = gulp;
const glob = require('glob');
const shell = cmd => require('child_process').execSync(cmd, { stdio: [0, 1, 2] });
const del = require('del');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const $ = require('gulp-load-plugins')();
const browserify = require('browserify');
const tsify = require('tsify');
const Server = require('karma').Server;

const pkg = require('./package.json');
const config = {
  browsers: ['Chrome', 'Firefox'].concat((os => {
    switch (os) {
      case 'Windows_NT':
        return [];
      case 'Darwin':
        return [];
     default:
        return [];
    }
  })(require('os').type())),
  ts: {
    dist: {
      src: [
        '*.ts'
      ],
      dest: 'dist'
    },
    test: {
      src: [
        '*.ts',
        'src/**/*.ts',
        'test/**/*.ts'
      ],
      dest: 'dist'
    }
  },
  site: {
    js: './gh-pages/assets/js/lib',
  },
  banner: [
    `/*! ${pkg.name} v${pkg.version} ${pkg.repository.url} | (c) 2012, ${pkg.author} | ${pkg.license} License */`,
    ''
  ].join('\n'),
  module: `
(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
      define([], factory);
  } else if (typeof module === 'object' && module.exports) {
      module.exports = factory();
  } else {
      root.commonJsStrict = factory();
  }
}(typeof self !== 'undefined' ? self : this, function () {
  return require('${pkg.name}');
}));
`,
  clean: [
    'dist',
    'gh-pages/assets/*/**/lib',
  ]
};

function parallel(...tasks) {
  return () =>
    shell(`concurrently ${tasks.map(task => `"gulp ${task}"`).join(' ')}`);
}

function compile(src, watch = false) {
  let done = true;
  return browserify(
    Object.values(src).map(p => glob.sync(p)),
    {
      cache: {},
      packageCache: {},
    })
    .require(`./index.ts`, { expose: pkg.name })
    .plugin(tsify, { global: true, ...require('./tsconfig.json').compilerOptions })
    .bundle()
    .on("error", err => done = console.log(err + '') || watch)
    .pipe(source(`${pkg.name}.js`))
    .pipe(buffer())
    .pipe($.derequire())
    .once("finish", () => done || process.exit(1))
    .pipe($.footer(config.module));
}

gulp.task('ts:dev', () =>
  gulp.watch(config.ts.test.src, { ignoreInitial: false }, () =>
    compile(config.ts.test.src, true)
      .pipe($.rename({ extname: '.test.js' }))
      .pipe(gulp.dest(config.ts.test.dest))));

gulp.task('ts:test', () =>
  compile(config.ts.test.src)
    .pipe($.rename({ extname: '.test.js' }))
    .pipe(gulp.dest(config.ts.test.dest))
    .pipe($.eslint({
      'parserOptions': {
        'ecmaVersion': 2020,
      },
      'env': {
        'es2020': true,
      },
      'plugins': ['redos'],
      'rules': {
        'redos/no-vulnerable': [
          'error',
          {
            ignoreErrors: false,
          },
        ],
      },
    }))
    .pipe($.eslint.format())
    .pipe($.eslint.failAfterError()));

gulp.task('ts:dist', () =>
  compile(config.ts.dist.src)
    .pipe($.unassert())
    .pipe($.header(config.banner))
    .pipe(gulp.dest(config.site.js))
    .pipe(gulp.dest(config.ts.dist.dest)));

gulp.task('ts:view', () =>
  gulp.watch(config.ts.test.src, { ignoreInitial: false }, () =>
    compile(config.ts.dist.src, true)
      .pipe($.unassert())
      .pipe($.header(config.banner))
      .pipe(gulp.dest(config.site.js))));

gulp.task('karma:dev', done =>
  void new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    preprocessors: {
      'dist/*.js': ['espower']
    },
    singleRun: false,
  }, done).start());

gulp.task('karma:test', done =>
  void new Server({
    configFile: __dirname + '/karma.conf.js',
    browsers: config.browsers,
    reporters: ['dots', 'coverage-istanbul'],
    preprocessors: {
{'fraction_non_alphanumeric': 0.22577319587628866, 'fraction_numerical': 0.004123711340206186, 'mean_word_length': 2.638537271448664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '1241530', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2728, 'n_words': 464}