gulpfile.coffee 4.2 KB

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