gulpfile.js 3.3 KB

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