gulpfile.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. var gulp = require('gulp');
  3. var concat = require('gulp-concat');
  4. var uglify = require('gulp-uglify');
  5. var sourcemaps = require('gulp-sourcemaps');
  6. var rename = require('gulp-rename');
  7. var wrap = require('gulp-wrap');
  8. var Server = require('karma').Server;
  9. var src = [
  10. './src/utils.js',
  11. './src/locale/*.js',
  12. './src/HijrahDateFormatter.js',
  13. './src/HijrahDate.js'
  14. ];
  15. var dest = '.'
  16. var file = './hijrah-date.js';
  17. var minFile = './hijrah-date.min.js';
  18. var wrapTemplate = "(function (global, factory) {"+
  19. "typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :"+
  20. "typeof define === 'function' && define.amd ? define(factory) :"+
  21. "global.HijrahDate = factory()"+
  22. "}(this, function(){ 'use strict';<%= contents %>; return HijrahDate;}));"
  23. gulp.task('concat', function() {
  24. return gulp.src(src)
  25. .pipe(concat(file))
  26. .pipe(gulp.dest(dest))
  27. .pipe(wrap(wrapTemplate, {}, {parse: false}))
  28. .pipe(gulp.dest(dest))
  29. });
  30. gulp.task('test', ['concat'], function (done) {
  31. new Server({
  32. configFile: __dirname + '/karma.conf.js',
  33. singleRun: true
  34. }, done).start();
  35. });
  36. gulp.task('build', ['concat'], function() {
  37. return gulp.src(file)
  38. .pipe(sourcemaps.init())
  39. .pipe(rename(minFile))
  40. .pipe(uglify({strict:true}))
  41. .pipe(sourcemaps.write(dest))
  42. .pipe(gulp.dest(dest));
  43. });
  44. gulp.task('default', ['test', 'build']);