<commit_before>// Load plugins
var del              = require('del');
var gulp             = require('gulp');
var autoprefixer     = require('gulp-autoprefixer');
var bower            = require('gulp-bower');
var csso             = require('gulp-csso');
var inject           = require('gulp-inject');
var livereload       = require('gulp-livereload');
var pixrem           = require('gulp-pixrem');
var rename           = require('gulp-rename');
var sass             = require('gulp-sass');
var sourcemaps       = require('gulp-sourcemaps');

// Define package types
var packageTypes = [
  'function',
  'system',
  'base',
  'utility',
  'object',
  'component'
];

// Styles
gulp.task('styles', function () {
  return gulp.src('scss/**/*.scss')
    .pipe(sourcemaps.init())
      .pipe(sass({ precision: 7, errLogToConsole: true }))
      .pipe(autoprefixer())
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('css'));
});

// Minify
gulp.task('minify', ['styles'], function () {
  return gulp.src('css/avalanche.css')
    .pipe(csso())
    .pipe(rename(function (path) {
      path.basename += '.min';
    }))
    .pipe(pixrem())
    .pipe(gulp.dest('css'))
    .pipe(livereload());
});

// Bower
gulp.task('bower', function () {
  gulp.start('inject');
  return bower();
});

// Inject
gulp.task('inject', ['bower'], function () {
  var src = gulp.src('scss/avalanche.scss');
  var packageSrc;

  packageTypes.forEach(function (packageType) {
    // Move package files to the scss directory
    gulp.src('vendor/avalanche_' + packageType + '_*/scss/*.scss')
      .pipe(rename(function (path) {
        path.dirname = '/' + packageType;
      }))
      .pipe(gulp.dest('scss'));

    // Inject files into avalanche.scss
    packageSrc = gulp.src('scss/' + packageType + '/*.scss', { read: false });

    src.pipe(inject(packageSrc, {
      starttag: '/** inject:' + packageType + ' **/',
      endtag: '/** endinject **/',
      transform: function (filepath, file, i, length) {
        return '@import \'' + filepath.substring(1).replace('scss/', '').replace('/_', '/').replace('.scss', '') + '\';';
      }
    }));
  });

  gulp.start('clean:vendor');

  return src.pipe(gulp.dest('scss'));
});

// Clean:vendor
gulp.task('clean:vendor', ['inject'], function () {
  // Remove avalanche packages from the vendor folder
  del([
    'vendor/avalanche_*'
  ]);<commit_msg>refactored gulpfile, optimized execution order of bower related tasks, fixes #81<commit_after>// Load plugins
var del              = require('del');
var gulp             = require('gulp');
var autoprefixer     = require('gulp-autoprefixer');
var bower            = require('gulp-bower');
var csso             = require('gulp-csso');
var inject           = require('gulp-inject');
var livereload       = require('gulp-livereload');
var pixrem           = require('gulp-pixrem');
var rename           = require('gulp-rename');
var sass             = require('gulp-sass');
var sourcemaps       = require('gulp-sourcemaps');

// Define package types
var packageTypes = [
  'function',
  'system',
  'base',
  'utility',
  'object',
  'component'
];

// Styles
gulp.task('styles', function () {
  return gulp.src('scss/**/*.scss')
    .pipe(sourcemaps.init())
      .pipe(sass({ precision: 7, errLogToConsole: true }))
      .pipe(autoprefixer())
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('css'));
});

// Minify
gulp.task('minify', ['styles'], function () {
  return gulp.src('css/avalanche.css')
    .pipe(csso())
    .pipe(rename(function (path) {
      path.basename += '.min';
    }))
    .pipe(pixrem())
    .pipe(gulp.dest('css'))
    .pipe(livereload());
});

// Bower
gulp.task('bower', function () {
  gulp.start('move');
  return bower();
});

// Inject
gulp.task('move', ['bower'], function () {
  gulp.start('inject');
  gulp.start('clean:vendor');
  return gulp.src('vendor/avalanche_*/scss/*.scss')
    .pipe(rename(function (path) {
      var packageType = path.dirname
        .replace('avalanche_', '')
        .replace(path.basename, '')
        .replace('/scss', '');
      path.dirname = '/' + packageType;
    }))
    .pipe(gulp.dest('scss'));
});

// Inject
gulp.task('inject', ['move'], function () {
  var src = gulp.src('scss/avalanche.scss');

  packageTypes.forEach(function (packageType) {
    src.pipe(inject(gulp.src('scss/' + packageType + '/*.scss', { read: false }), {
      starttag: '/** inject: ' + packageType + ' **/',
      endtag: '/** endinject **/',
      transform: function (filepath, file, i, length) {
        return '@import \'' + filepath.substring(1).replace('scss/', '').replace('/_', '/').replace('.scss', '') + '\';';
      }
    }));
  });

  return src.pipe(gulp.dest('scss'));
});

// Clean:vendor
gulp.task('clean:vendor', ['move'], function () {
  // Remove avalanche packages from the vendor folder
  del([
    'vendor/avalanche_*'
  ]);
{'fraction_non_alphanumeric': 0.20684005734179808, 'fraction_numerical': 0.0012287528158918697, 'mean_word_length': 2.904076738609113, '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': '1241490', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1642, 'n_words': 305}