/load-common-gulp-tasks

Load common gulp tasks and configs so you don't need to redefine them for every module

Primary LanguageJavaScript

load-common-gulp-tasks NPM version Build Status

Load common gulp tasks and configs so you don't need to redefine them for every module

Supplies a common interface to the following gulp modules:

  1. gulp-mocha
  2. gulp-jshint
  3. gulp-istanbul
  4. gulp-istanbul-enforcer
  5. gulp-plato
  6. gulp-help

Available Tasks

gulp help for available tasks. Right now these are the default tasks:

Debug Tests

You can debug your mocha tests using a tool like node-inspector combined with the gulp test-debug target

Basic Usage

// gulpfile.js
var gulp = require('gulp');
require('load-common-gulp-tasks')(gulp);

Options

load-common-gulp-tasks tries to assume smart defaults but also attempts to be very configurable. Each option can be overridden by passing an options object as the second parameter, e.g. require('load-common-gulp-tasks')(gulp, options);

options.coverageSettings

Type: Object
Default:

{
  thresholds: {
    statements: 80,
    branches: 70,
    lines: 80,
    functions: 80
  },
  coverageDirectory: './target/coverage',
  rootDirectory: ''
}

Coverage settings for gulp-istanbul-enforcer

options.paths

Type: Object
Default:

{
  lint: [
    './*.js',
    './lib/**/*.js',
    './test/**/*.js'
  ],
  felint: [
    './content/**/*.js'
  ],
  cover: [
    './lib/**/*.js'
  ],
  test: [
    './test/**/*.js'
  ]
}

Glob paths used by the associated targets

options.jshintrc.server

Type: String
Default: ./node_modules/load-common-gulp-tasks/lint/.jshintrc

.jshintrc file to use when running gulp lint target

options.jshintrc.client

Type: String
Default: ./node_modules/load-common-gulp-tasks/felint/.jshintrc

.jshintrc file to use when running gulp felint target

options.complexity.destDir

Type: String
Default: ./target/complexity

Report destination.

options.complexity.options

Type: Object
Default: {}

Options passed to complexity-report.

options.showStreamSize

Type: Boolean
Default: false

Optionally show the gulp stream size of each task

Advanced Usage

To override default tasks or create new ones, simply define them after calling require('load-common-gulp-tasks')(gulp); in your gulpfile.js, e.g.

var gulp = require('gulp'),
  sass = require('gulp-sass'),
  rename = require('gulp-rename'),
  bourbon = require('node-bourbon').includePaths,
  neat = require('node-neat').includePaths,
  libPath = 'lib',
  sassPath = libPath + '/*/sass',
  sassFiles = sassPath + '/*.scss',
  options;

// ------------------------
// custom coverage settings
// ------------------------
options = {
  coverageSettings: {
    thresholds: {
      statements: 83, // higher than default
      branches: 59, // lower than default
      // lines not defined. use default
      functions: 58
    }
  }
};

// ------------------------
// load common tasks
// ------------------------
require('load-common-gulp-tasks')(gulp, options);

// ------------------------
// custom tasks
// ------------------------
gulp.task('watch', 'Watch sass files and recompile on change', function () {
  gulp.watch([sassFiles], ['styles']);
});

gulp.task('styles', 'Compile sass to css', function () {
  return gulp.src(sassFiles)
    .pipe(sass({
      includePaths: [sassPath].concat(bourbon).concat(neat)
    }))
    .pipe(rename(function (path) {
      var moduleName = path.dirname.split('/')[0];
      path.dirname = moduleName + '/content/styles';
    }))
    .pipe(gulp.dest('./' + libPath));
});