gulpfile.js 1.79 KB
Newer Older
jatuporn Tonggasem's avatar
jatuporn Tonggasem committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
'use strict';

var gulp = require('gulp');
var runSequence = require('run-sequence');
var spawn = require('child_process').spawn;
var tslint = require('gulp-tslint');

var runSpawn = function(done, task, opt_arg) {
  var child = spawn(task, opt_arg, {stdio: 'inherit'});
  child.on('close', function() {
    done();
  });
};

gulp.task('built:copy', function() {
  return gulp.src(['lib/**/*','!lib/**/*.ts'])
      .pipe(gulp.dest('built/lib/'));
});

gulp.task('webdriver:update', function(done) {
  runSpawn(done, 'webdriver-manager', ['update']);
});

gulp.task('tslint', function() {
  return gulp.src(['lib/**/*.ts', 'spec/**/*.ts']).pipe(tslint()).pipe(tslint.report());
});

gulp.task('format:enforce', () => {
  const format = require('gulp-clang-format');
  const clangFormat = require('clang-format');
  return gulp.src(['lib/**/*.ts', 'spec/**/*.ts']).pipe(
    format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
});

gulp.task('format', () => {
  const format = require('gulp-clang-format');
  const clangFormat = require('clang-format');
  return gulp.src(['lib/**/*.ts', 'spec/**/*.ts'], { base: '.' }).pipe(
    format.format('file', clangFormat)).pipe(gulp.dest('.'));
});

gulp.task('tsc', function(done) {
  runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
});

gulp.task('lint', function(done) {
  runSequence('tslint', 'format:enforce', done);
});

gulp.task('prepublish', function(done) {
  runSequence('lint' ,'tsc', 'built:copy', done);
});

gulp.task('pretest', function(done) {
  runSequence(
    ['webdriver:update', 'tslint', 'clang'], 'tsc', 'built:copy', done);
});

gulp.task('default', ['prepublish']);
gulp.task('build', ['prepublish']);

gulp.task('test:copy', function(done) {
  return gulp.src(['spec/**/*','!spec/**/*.ts'])
      .pipe(gulp.dest('built/spec/'));
});