gulpfile.coffee 4.3 KB

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