gulpfile.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict';
  2. const gulp = require('gulp');
  3. const jshint = require('gulp-jshint');
  4. const stylish = require('jshint-stylish');
  5. const rename = require('gulp-rename');
  6. const jscs = require('gulp-jscs');
  7. const uglify = require('gulp-uglify');
  8. const livereload = require('gulp-livereload');
  9. const exec = require('child_process').exec;
  10. gulp.task('default', ['watch']);
  11. gulp.task('watch', () => {
  12. livereload.listen(35730);
  13. gulp.watch([
  14. './src/*.js',
  15. './src/*.hbs'
  16. ], ['reload-js'])
  17. .on('change', function(e) {
  18. console.log(
  19. '[gulp-watch] file ' +
  20. e.path +
  21. ' was ' +
  22. e.type +
  23. ', building'
  24. );
  25. });
  26. });
  27. gulp.task('reload-js', ['build-dist'], () => {
  28. return livereload.changed();
  29. });
  30. gulp.task('prod', ['uglify']);
  31. gulp.task('uglify', ['build'], () => {
  32. return gulp.src([
  33. './dist/mixitup.js'
  34. ])
  35. .pipe(uglify({
  36. preserveComments: 'license'
  37. }))
  38. .pipe(rename('mixitup.min.js'))
  39. .on('error', e => console.error('[uglify] ' + e.message))
  40. .pipe(gulp.dest('./dist/'))
  41. .pipe(gulp.dest('./demos/'));
  42. });
  43. gulp.task('build', ['build-dist'], done => {
  44. exec('node node_modules/mixitup-build/docs.js -s mixitup.js', (e, out) => {
  45. if (out) {
  46. console.log(out);
  47. }
  48. done(e);
  49. });
  50. });
  51. gulp.task('build-dist', ['lint', 'code-style'], done => {
  52. exec('node node_modules/mixitup-build/dist.js -o mixitup.js', (e, out) => {
  53. if (out) {
  54. console.log(out);
  55. }
  56. done(e);
  57. });
  58. });
  59. gulp.task('lint', () => {
  60. return gulp.src([
  61. './src/*.js'
  62. ], {
  63. base: '/'
  64. })
  65. .pipe(jshint('./.jshintrc'))
  66. .pipe(jshint.reporter(stylish))
  67. .pipe(jshint.reporter('fail'));
  68. });
  69. gulp.task('code-style', () => {
  70. return gulp.src([
  71. './src/*.js'
  72. ], {
  73. base: '/'
  74. })
  75. .pipe(jscs())
  76. .pipe(jscs.reporter());
  77. });