gulpfile.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. var gulp = require('gulp');
  2. var plugins = require('gulp-load-plugins')();
  3. var pkg = require('./package.json');
  4. var name = pkg.name;
  5. var banner = [
  6. '/* ========================================================================',
  7. ' * <%= pkg.name %> - v<%= pkg.version %>',
  8. ' * <%= pkg.homepage %>',
  9. ' * ========================================================================',
  10. ' * Copyright 2012-2013 <%= pkg.author.name %>',
  11. ' *',
  12. ' * ========================================================================',
  13. ' * Licensed under the Apache License, Version 2.0 (the \"License\");',
  14. ' * you may not use this file except in compliance with the License.',
  15. ' * You may obtain a copy of the License at',
  16. ' *',
  17. ' * http://www.apache.org/licenses/LICENSE-2.0',
  18. ' *',
  19. ' * Unless required by applicable law or agreed to in writing, software',
  20. ' * distributed under the License is distributed on an \"AS IS\" BASIS,',
  21. ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.',
  22. ' * See the License for the specific language governing permissions and',
  23. ' * limitations under the License.',
  24. ' * ========================================================================',
  25. ' */',
  26. '',
  27. ''].join('\n');
  28. gulp.task('coffee', function() {
  29. gulp.src('src/coffee/' + name + '.coffee')
  30. .pipe(plugins.coffeelint({
  31. indentation: 2,
  32. no_trailing_semicolons: true,
  33. no_trailing_whitespace: true
  34. }))
  35. .pipe(plugins.coffee()).on('error', plugins.util.log)
  36. .pipe(plugins.header(banner, { pkg: pkg }))
  37. .pipe(gulp.dest('dist/js'))
  38. .pipe(plugins.uglify())
  39. .pipe(plugins.header(banner, { pkg: pkg }))
  40. .pipe(plugins.rename({ suffix: '.min' }))
  41. .pipe(gulp.dest('dist/js'));
  42. });
  43. gulp.task('less-bootstrap2', function() {
  44. gulp.src('src/less/bootstrap2/build.less')
  45. .pipe(plugins.less())
  46. .pipe(plugins.header(banner, { pkg: pkg }))
  47. .pipe(plugins.rename({ basename: name }))
  48. .pipe(gulp.dest('dist/css/bootstrap2'))
  49. .pipe(plugins.less({
  50. compress: true,
  51. cleancss: true
  52. }))
  53. .pipe(plugins.header(banner, { pkg: pkg }))
  54. .pipe(plugins.rename({ suffix: '.min' }))
  55. .pipe(gulp.dest('dist/css/bootstrap2'));
  56. });
  57. gulp.task('less-bootstrap3', function() {
  58. gulp.src('src/less/bootstrap3/build.less')
  59. .pipe(plugins.less())
  60. .pipe(plugins.header(banner, { pkg: pkg }))
  61. .pipe(plugins.rename({ basename: name }))
  62. .pipe(gulp.dest('dist/css/bootstrap3'))
  63. .pipe(plugins.less({
  64. compress: true,
  65. cleancss: true
  66. }))
  67. .pipe(plugins.header(banner, { pkg: pkg }))
  68. .pipe(plugins.rename({ suffix: '.min' }))
  69. .pipe(gulp.dest('dist/css/bootstrap3'));
  70. });
  71. gulp.task('docs', function() {
  72. gulp.src('docs/index.jade')
  73. .pipe(plugins.jade({ pretty: true }))
  74. .pipe(gulp.dest('./'));
  75. });
  76. gulp.task('connect', ['docs'], plugins.connect.server({
  77. root: [__dirname],
  78. open: true
  79. }));
  80. gulp.task('watch', ['connect'], function() {
  81. gulp.watch('src/coffee/' + name + '.coffee', ['coffee']).on('change', function(data) {
  82. gulp.src(data.path).pipe(plugins.connect.reload());
  83. });
  84. gulp.watch('src/less/bootstrap2/*.less', ['less-bootstrap2']).on('change', function(data) {
  85. gulp.src(data.path).pipe(plugins.connect.reload());
  86. });
  87. gulp.watch('src/less/bootstrap3/*.less', ['less-bootstrap3']).on('change', function(data) {
  88. gulp.src(data.path).pipe(plugins.connect.reload());
  89. });
  90. gulp.watch('docs/index.jade', ['docs']).on('change', function(data) {
  91. gulp.src(data.path).pipe(plugins.connect.reload());
  92. });
  93. });
  94. gulp.task('less', ['less-bootstrap2', 'less-bootstrap3']);
  95. gulp.task('build', ['coffee', 'less']);
  96. gulp.task('default', ['connect', 'build', 'docs', 'watch']);