gulpfile.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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('build/js'))
  38. .pipe(plugins.uglify())
  39. .pipe(plugins.header(banner, { pkg: pkg }))
  40. .pipe(plugins.rename({ suffix: '.min' }))
  41. .pipe(gulp.dest('build/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('build/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('build/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('build/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('build/css/bootstrap3'));
  70. });
  71. gulp.task('clean', function() {
  72. gulp.src(['build/css', 'build/js'], { read: false })
  73. .pipe(plugins.clean());
  74. });
  75. gulp.task('open', function(){
  76. gulp.src('index.html')
  77. .pipe(plugins.open());
  78. });
  79. gulp.task('watch', function () {
  80. gulp.watch('src/coffee/' + name + '.coffee', ['coffee']);
  81. gulp.watch('src/less/bootstrap2/*.less', ['less-bootstrap2']);
  82. gulp.watch('src/less/bootstrap3/*.less', ['less-bootstrap3']);
  83. });
  84. gulp.task('default', ['clean'], function() {
  85. gulp.start('coffee', 'less-bootstrap2', 'less-bootstrap3', 'open', 'watch')
  86. });