gulpfile.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use strict';
  2. var gulp = require('gulp');
  3. var jshint = require('gulp-jshint');
  4. var exec = require('gulp-exec');
  5. var stylish = require('jshint-stylish');
  6. var browserify = require('gulp-browserify');
  7. var uglify = require('gulp-uglify');
  8. var rename = require('gulp-rename');
  9. var karma = require('karma');
  10. var coveralls = require('gulp-coveralls');
  11. var istanbul = require('gulp-istanbul');
  12. var mocha = require('gulp-mocha');
  13. var paths = {
  14. index: './index.js',
  15. tests: './test/**/*.js'
  16. };
  17. function preTest(src) {
  18. return gulp.src(src)
  19. .pipe(istanbul())
  20. .pipe(istanbul.hookRequire());
  21. }
  22. function test(src){
  23. return gulp.src(src)
  24. .pipe(mocha())
  25. .pipe(istanbul.writeReports());
  26. }
  27. function testKarma(done){
  28. new karma.Server({
  29. configFile: __dirname + '/karma.conf.js',
  30. singleRun: true
  31. }, done).start();
  32. }
  33. function lint(src){
  34. return gulp.src(src)
  35. .pipe(jshint('.jshintrc'))
  36. .pipe(jshint.reporter(stylish));
  37. }
  38. gulp.task('dist', function(){
  39. gulp.src([paths.index])
  40. .pipe(browserify({
  41. insertGlobals : true,
  42. debug: true,
  43. standalone: 'objectHash'
  44. }))
  45. .pipe(rename('object_hash.js'))
  46. .pipe(uglify({outSourceMap: true}))
  47. .pipe(gulp.dest('./dist'));
  48. // tests
  49. gulp.src([paths.tests])
  50. .pipe(browserify())
  51. .pipe(rename('object_hash_test.js'))
  52. .pipe(gulp.dest('./dist'));
  53. });
  54. gulp.task('pre-test', function() {
  55. preTest([paths.index]);
  56. });
  57. gulp.task('test', ['pre-test'], function() {
  58. test([paths.tests]);
  59. });
  60. gulp.task('karma', function() {
  61. testKarma();
  62. });
  63. gulp.task('coveralls', function() {
  64. gulp.src('coverage/**/lcov.info')
  65. .pipe(coveralls());
  66. });
  67. gulp.task('lint', function () {
  68. return lint([paths.index]);
  69. });
  70. gulp.task('watch', function () {
  71. // watch and lint any files that are added or changed
  72. gulp.watch([paths.index, paths.tests], function(event){
  73. if(event.type !== 'deleted') {
  74. lint([event.path]);
  75. }
  76. });
  77. // run the tests when something changes
  78. gulp.watch([paths.index, paths.tests], ['test', 'karma']);
  79. });
  80. gulp.task('default', ['watch']);