<commit_before>'use strict';

var gulp = require('gulp'),
    plugins = require('gulp-load-plugins')(),
    task = (function (args) {
      var length = args.length,
          i = 0,
          n;

      while (i++ < length) {
        n = String(args[i]).match(/^-+(\w+)$/i);

        if (n) {
          n = n[1];
          break;
        }
      }

      return n;
    })(process.argv),
    tasks = {};


// Default
// Command: gulp [task]
// -----------------------------------------------------------------------------

tasks.base = function () {
  var pathto = function (file) {
        return ('admin/views/assets/' + file);
      },
      scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts'),
        qor: pathto('javascripts/qor/*.js'),
        all: [
          'gulpfile.js',
          pathto('javascripts/qor/*.js'),
          pathto('javascripts/app/*.js')
        ]
      },
      styles = {
        src: pathto('stylesheets/scss/*.scss'),
        dest: pathto('stylesheets'),
        main: pathto('stylesheets/{qor,app}.css'),
        scss: pathto('stylesheets/scss/**/*.scss')
      },
      fonts = {
        dest: pathto('fonts')
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.all)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.all)
    .pipe(plugins.jscs());
  });

  gulp.task('qor', ['jshint', 'jscs'], function () {
    return gulp.src(scripts.qor)
    .pipe(plugins.concat('qor.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('js', ['qor'], function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('qor+', function () {
    return gulp.src(scripts.qor)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat('qor.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('js+', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('jslib', function () {
    return gulp.src([
      'bower_components/jquery/dist/jquery.min.js',
      'bower_components/jquery/dist/jquery.min.map',
      'bower_components/material-design-lite/material.min.js',
      'bower_components/material-design-lite/material.min.js.map',
      'bower_components/cropper/dist/cropper.min.js',
      'bower_components/chosen/chosen.jquery.min.js'
    ])
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.sass())
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('fonts', function () {
    return gulp.src([
      'bower_components/material-design-icons/iconfont/codepoints',
      'bower_components/material-design-icons/iconfont/MaterialIcons*'
    ])
    .pipe(gulp.dest(fonts.dest));
  });

  gulp.task('csslib', ['fonts'], function () {
    return gulp.src([
      'bower_components/material-design-lite/material.min.css',
      'bower_components/material-design-lite/material.min.css.map',
      'bower_components/cropper/dist/cropper.min.css',
      'bower_components/chosen/chosen-sprite.png',
      'bower_components/chosen/chosen-sprite@2x.png',
      'bower_components/chosen/chosen.min.css'
    ])
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.qor, ['qor+']);
    gulp.watch(scripts.src, ['js+']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('lib', ['jslib', 'csslib']);
  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
};


// I18n (Internationalization)
// Command: gulp [task] --i18n
// -----------------------------------------------------------------------------

tasks.i18n = function () {
  var namespace = 'i18n',
      pathto = function (file) {
        return (namespace + '/views/themes/' + namespace + '/assets/' + file);
      },
      scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts/')
      },
      styles = {
        src: pathto('stylesheets/scss/*.scss'),
        dest: pathto('stylesheets/'),
        main: pathto('stylesheets/' + namespace + '.css'),
        scss: pathto('stylesheets/scss/**/*.scss')
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jscs());
  });

  gulp.task('js', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat(namespace + '.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('concat', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat(namespace + '.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sass())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.src, ['concat']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
};


// L10n (Localization)
// Command: gulp [task] --l10n
// -----------------------------------------------------------------------------

tasks.l10n = function () {
  var namespace = 'l10n',
      pathto = function (file) {
        return (namespace + '/views/themes/' + namespace + '/assets/' + file);
      },
      scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts/')
      },
      styles = {
        src: pathto('stylesheets/scss/*.scss'),
        dest: pathto('stylesheets/'),
        main: pathto('stylesheets/' + namespace + '.css'),
        scss: pathto('stylesheets/scss/**/*.scss')
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jscs());
  });

  gulp.task('js', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat(namespace + '.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('concat', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat(namespace + '.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sass())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.src, ['concat']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
};


// Publish
// Command: gulp [task] --publish
// -----------------------------------------------------------------------------

tasks.publish = function () {
  var namespace = 'publish',
      pathto = function (file) {
        return (namespace + '/views/themes/' + namespace + '/assets/' + file);
      },
      scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts/')
      },
      styles = {
        src: pathto('stylesheets/scss/*.scss'),
        dest: pathto('stylesheets/'),
        main: pathto('stylesheets/' + namespace + '.css'),
        scss: pathto('stylesheets/scss/**/*.scss')
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jscs());
  });

  gulp.task('js', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat(namespace + '.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('concat', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat(namespace + '.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sass())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.src, ['concat']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
};


// Sorting
// Command: gulp [task] --sorting
// -----------------------------------------------------------------------------

tasks.sorting = function () {
  var namespace = 'sorting',
      pathto = function (file) {
        return (namespace + '/views/themes/' + namespace + '/assets/' + file);
      },
      scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts/')
      },
      styles = {
        src: pathto('stylesheets/scss/*.scss'),
        dest: pathto('stylesheets/'),
        main: pathto('stylesheets/' + namespace + '.css'),
        scss: pathto('stylesheets/scss/**/*.scss')
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jscs());
  });

  gulp.task('js', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat(namespace + '.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('concat', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat(namespace + '.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sass())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.src, ['concat']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
};


// Init
// -----------------------------------------------------------------------------

if (task && typeof tasks[task] === 'function') {
  console.log('Running "' + task + '" task...');
  tasks[task]();
} else {
  console.log('Running "admin" task...');
  tasks.base();
}
<commit_msg>Simplify code<commit_after>'use strict';

var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var moduleName = (function () {
      var args = process.argv;
      var length = args.length;
      var i = 0;
      var matched;
      var name;

      while (i++ < length) {
        matched = String(args[i]).match(/^--+(\w+)$/i);

        if (matched) {
          name = matched[1];
          break;
        }
      }

      return name;
    })();


// Admin
// Command: gulp [task]
// -----------------------------------------------------------------------------

function adminTasks() {
  var pathto = function (file) {
        return ('admin/views/assets/' + file);
      };
  var scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts'),
        qor: pathto('javascripts/qor/*.js'),
        all: [
          'gulpfile.js',
          pathto('javascripts/qor/*.js'),
          pathto('javascripts/app/*.js'),
        ],
      };
  var styles = {
        src: pathto('stylesheets/scss/*.scss'),
        dest: pathto('stylesheets'),
        main: pathto('stylesheets/{qor,app}.css'),
        scss: pathto('stylesheets/scss/**/*.scss'),
      };
  var fonts = {
        dest: pathto('fonts'),
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.all)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.all)
    .pipe(plugins.jscs());
  });

  gulp.task('qor', ['jshint', 'jscs'], function () {
    return gulp.src(scripts.qor)
    .pipe(plugins.concat('qor.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('js', ['qor'], function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('qor+', function () {
    return gulp.src(scripts.qor)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat('qor.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('js+', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('jslib', function () {
    return gulp.src([
      'bower_components/jquery/dist/jquery.min.js',
      'bower_components/jquery/dist/jquery.min.map',
      'bower_components/material-design-lite/material.min.js',
      'bower_components/material-design-lite/material.min.js.map',
      'bower_components/cropper/dist/cropper.min.js',
      'bower_components/chosen/chosen.jquery.min.js'
    ])
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.sass())
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('fonts', function () {
    return gulp.src([
      'bower_components/material-design-icons/iconfont/codepoints',
      'bower_components/material-design-icons/iconfont/MaterialIcons*'
    ])
    .pipe(gulp.dest(fonts.dest));
  });

  gulp.task('csslib', ['fonts'], function () {
    return gulp.src([
      'bower_components/material-design-lite/material.min.css',
      'bower_components/material-design-lite/material.min.css.map',
      'bower_components/cropper/dist/cropper.min.css',
      'bower_components/chosen/chosen-sprite.png',
      'bower_components/chosen/chosen-sprite@2x.png',
      'bower_components/chosen/chosen.min.css'
    ])
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.qor, ['qor+']);
    gulp.watch(scripts.src, ['js+']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('lib', ['jslib', 'csslib']);
  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
};


// Modules
// Command: gulp [task] --moduleName
// -----------------------------------------------------------------------------

function moduleTasks(moduleName) {
  var pathto = function (file) {
        return (moduleName + '/views/themes/' + moduleName + '/assets/' + file);
      };
  var scripts = {
        src: pathto('javascripts/app/*.js'),
        dest: pathto('javascripts/'),
      };
  var styles = {
        src: pathto('stylesheets/scss/*.scss'),
        dest: pathto('stylesheets/'),
        main: pathto('stylesheets/' + moduleName + '.css'),
        scss: pathto('stylesheets/scss/**/*.scss'),
      };

  gulp.task('jshint', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'));
  });

  gulp.task('jscs', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.jscs());
  });

  gulp.task('js', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.concat(moduleName + '.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('concat', function () {
    return gulp.src(scripts.src)
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat(moduleName + '.js'))
    .pipe(plugins.sourcemaps.write('./'))
    .pipe(gulp.dest(scripts.dest));
  });

  gulp.task('sass', function () {
    return gulp.src(styles.src)
    .pipe(plugins.sass())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('csslint', ['sass'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.csslint('.csslintrc'))
    .pipe(plugins.csslint.reporter());
  });

  gulp.task('css', ['csslint'], function () {
    return gulp.src(styles.main)
    .pipe(plugins.autoprefixer())
    .pipe(plugins.csscomb())
    .pipe(plugins.minifyCss())
    .pipe(gulp.dest(styles.dest));
  });

  gulp.task('watch', function () {
    gulp.watch(scripts.src, ['concat']);
    gulp.watch(styles.scss, ['sass']);
  });

  gulp.task('release', ['js', 'css']);

  gulp.task('default', ['watch']);
};


// Init
// -----------------------------------------------------------------------------

if (moduleName) {
  console.log('Running "' + moduleName + '" task...');
  moduleTasks(moduleName);
} else {
  console.log('Running "admin" task...');
  adminTasks();
}

{'fraction_non_alphanumeric': 0.23892568826329952, 'fraction_numerical': 0.001138480645829021, 'mean_word_length': 2.4952070898896728, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5949774', 'n_tokens_mistral': 6824, 'n_tokens_neox': 6660, 'n_words': 879}