gulpfile.coffee 3.8 KB

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