gulpfile.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. var gulp = require('gulp'),
  3. plugins = require('gulp-load-plugins')(),
  4. pkg = require('./package'),
  5. scripts = {
  6. all: [
  7. 'src/*.js',
  8. 'gulpfile.js',
  9. 'docs/js/main.js'
  10. ],
  11. src: 'src/*.js',
  12. docs: 'docs/js',
  13. dest: 'dist/js'
  14. },
  15. styles = {
  16. src: 'src/css/*.css',
  17. docs: 'docs/css',
  18. dest: 'dist/css'
  19. },
  20. images = {
  21. src: 'src/images/*.png',
  22. docs: 'docs/images',
  23. dest: 'dist/images'
  24. };
  25. gulp.task('jshint', function () {
  26. return gulp.src(scripts.all)
  27. .pipe(plugins.jshint())
  28. .pipe(plugins.jshint.reporter('default'));
  29. });
  30. gulp.task('jscs', function () {
  31. return gulp.src(scripts.all)
  32. .pipe(plugins.jscs());
  33. });
  34. gulp.task('js', ['jshint', 'jscs', 'copy'], function () {
  35. return gulp.src(scripts.src)
  36. .pipe(plugins.replace(/@\w+/g, function (placeholder) {
  37. switch (placeholder) {
  38. case '@VERSION':
  39. placeholder = pkg.version;
  40. break;
  41. case '@YEAR':
  42. placeholder = (new Date()).getFullYear();
  43. break;
  44. case '@DATE':
  45. placeholder = (new Date()).toISOString();
  46. break;
  47. }
  48. return placeholder;
  49. }))
  50. .pipe(gulp.dest(scripts.docs))
  51. .pipe(gulp.dest(scripts.dest))
  52. .pipe(plugins.rename({
  53. suffix: '.min'
  54. }))
  55. .pipe(plugins.uglify({
  56. preserveComments: 'license'
  57. }))
  58. .pipe(gulp.dest(scripts.dest));
  59. });
  60. gulp.task('jscopy', function () {
  61. return gulp.src(scripts.src)
  62. .pipe(gulp.dest(scripts.docs))
  63. .pipe(gulp.dest(scripts.dest));
  64. });
  65. gulp.task('csscopy', function () {
  66. return gulp.src(styles.src)
  67. .pipe(gulp.dest(styles.docs))
  68. .pipe(gulp.dest(styles.dest));
  69. });
  70. gulp.task('imagecopy', function () {
  71. return gulp.src(images.src)
  72. .pipe(gulp.dest(images.docs))
  73. .pipe(gulp.dest(images.dest));
  74. });
  75. gulp.task('copy', ['jscopy', 'csscopy', 'imagecopy'], function () {
  76. });
  77. gulp.task('docs', function () {
  78. return gulp.src('docs/**')
  79. .pipe(gulp.dest('_gh_pages'));
  80. });
  81. gulp.task('release', ['js', 'docs'], function () {
  82. return gulp.src('dist/**/*')
  83. .pipe(gulp.dest('_releases/' + pkg.version));
  84. });
  85. gulp.task('watch', function () {
  86. gulp.watch(scripts.src, ['jscopy']);
  87. gulp.watch(styles.src, ['csscopy']);
  88. });
  89. gulp.task('default', ['watch']);