gulpfile.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. var SERVER_HOST = 'localhost';
  29. var SERVER_PORT = 3000;
  30. gulp.task('coffee', function(done) {
  31. gulp.src('./src/coffee/' + name + '.coffee')
  32. .pipe(plugins.coffeelint('./coffeelint.json'))
  33. .pipe(plugins.coffeelint.reporter())
  34. .pipe(plugins.coffee()).on('error', plugins.util.log)
  35. .pipe(plugins.header(banner, { pkg: pkg }))
  36. .pipe(gulp.dest('./dist/js'))
  37. .pipe(plugins.uglify())
  38. .pipe(plugins.header(banner, { pkg: pkg }))
  39. .pipe(plugins.rename({ suffix: '.min' }))
  40. .pipe(gulp.dest('./dist/js'))
  41. .on('end', done);
  42. });
  43. gulp.task('less-bootstrap2', function(done) {
  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. .on('end', done);
  57. });
  58. gulp.task('less-bootstrap3', function(done) {
  59. gulp.src('./src/less/bootstrap3/build.less')
  60. .pipe(plugins.less())
  61. .pipe(plugins.header(banner, { pkg: pkg }))
  62. .pipe(plugins.rename({ basename: name }))
  63. .pipe(gulp.dest('./dist/css/bootstrap3'))
  64. .pipe(plugins.less({
  65. compress: true,
  66. cleancss: true
  67. }))
  68. .pipe(plugins.header(banner, { pkg: pkg }))
  69. .pipe(plugins.rename({ suffix: '.min' }))
  70. .pipe(gulp.dest('./dist/css/bootstrap3'))
  71. .on('end', done);
  72. });
  73. gulp.task('docs', function(done) {
  74. gulp.src('./docs/index.jade')
  75. .pipe(plugins.jade({ pretty: true }))
  76. .pipe(gulp.dest('./'))
  77. .on('end', done);
  78. });
  79. gulp.task('open', ['connect'], function(done) {
  80. gulp.src('./index.html')
  81. .pipe(plugins.open('', { url: 'http://' + SERVER_HOST + ':' + SERVER_PORT }))
  82. .on('end', done);
  83. });
  84. gulp.task('connect', function(done) {
  85. plugins.connect.server({
  86. root: [__dirname],
  87. host: SERVER_HOST,
  88. port: SERVER_PORT,
  89. livereload: true
  90. });
  91. done();
  92. });
  93. gulp.task('watch', ['connect'], function() {
  94. var change = function(data) {
  95. gulp.src(data.path).pipe(plugins.connect.reload());
  96. };
  97. gulp.watch('./src/coffee/' + name + '.coffee', ['coffee']).on('change', change);
  98. gulp.watch('./src/less/bootstrap2/*.less', ['less-bootstrap2']).on('change', change);
  99. gulp.watch('./src/less/bootstrap3/*.less', ['less-bootstrap3']).on('change', change);
  100. gulp.watch('./docs/index.jade', ['docs']).on('change', change);
  101. });
  102. gulp.task('server', ['connect', 'open']);
  103. gulp.task('less', ['less-bootstrap2', 'less-bootstrap3']);
  104. gulp.task('build', ['coffee', 'less']);
  105. gulp.task('default', ['server', 'build', 'docs', 'watch']);