gulpfile.coffee 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. base: './'
  12. src: 'src'
  13. dist: 'dist'
  14. test: 'test'
  15. docs: "docs"
  16. components: "components"
  17. src =
  18. scripts: "#{paths.src}/coffee/#{name}.coffee"
  19. stylesheets:
  20. bootstrap2: "#{paths.src}/less/bootstrap2/build.less"
  21. bootstrap3: "#{paths.src}/less/bootstrap3/build.less"
  22. test: "#{paths.src}/coffee/#{name}.tests.coffee"
  23. docs:
  24. vendor:
  25. scripts: [
  26. "#{paths.components}/jquery/dist/jquery.min.js"
  27. "#{paths.components}/bootstrap/dist/js/bootstrap.min.js"
  28. "#{paths.src}/docs/js/*.js"
  29. ]
  30. stylesheets: [
  31. "#{paths.components}/bootstrap/dist/css/bootstrap.min.css"
  32. "#{paths.src}/docs/css/*.css"
  33. ]
  34. fonts: "#{paths.components}/bootstrap/dist/fonts/*"
  35. scripts: "#{paths.src}/docs/coffee/main.coffee"
  36. stylesheets: "#{paths.src}/docs/less/main.less"
  37. markup: "#{paths.src}/docs/jade/*.jade"
  38. dest =
  39. scripts: "#{paths.dist}/js"
  40. stylesheets:
  41. bootstrap2: "#{paths.dist}/css/bootstrap2"
  42. bootstrap3: "#{paths.dist}/css/bootstrap3"
  43. test: paths.test
  44. docs:
  45. scripts: "#{paths.docs}/js"
  46. stylesheets: "#{paths.docs}/css"
  47. fonts: "#{paths.docs}/fonts"
  48. markup: paths.base
  49. server =
  50. host: 'localhost'
  51. port: 3000
  52. banner = """
  53. /* ========================================================================
  54. * <%= pkg.name %> - v<%= pkg.version %>
  55. * <%= pkg.homepage %>
  56. * ========================================================================
  57. * Copyright 2012-2013 <%= pkg.author.name %>
  58. *
  59. * ========================================================================
  60. * Licensed under the Apache License, Version 2.0 (the "License");
  61. * you may not use this file except in compliance with the License.
  62. * You may obtain a copy of the License at
  63. *
  64. * http://www.apache.org/licenses/LICENSE-2.0
  65. *
  66. * Unless required by applicable law or agreed to in writing, software
  67. * distributed under the License is distributed on an "AS IS" BASIS,
  68. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  69. * See the License for the specific language governing permissions and
  70. * limitations under the License.
  71. * ========================================================================
  72. */
  73. """
  74. # build
  75. gulp.task 'coffee', ->
  76. gulp
  77. .src src.scripts
  78. .pipe $.changed dest.scripts
  79. .pipe $.coffeelint 'coffeelint.json'
  80. .pipe $.coffeelint.reporter()
  81. .pipe $.coffeelint.reporter("fail")
  82. .pipe $.coffee()
  83. .on 'error', $.util.log
  84. .pipe $.header banner, pkg: pkg
  85. .pipe gulp.dest dest.scripts
  86. .pipe gulp.dest dest.test
  87. .pipe $.uglify()
  88. .pipe $.header banner, pkg: pkg
  89. .pipe $.rename suffix: '.min'
  90. .pipe gulp.dest dest.scripts
  91. gulp.task 'less-bootstrap2', ->
  92. gulp
  93. .src src.stylesheets.bootstrap2
  94. .pipe $.changed dest.stylesheets.bootstrap2
  95. .pipe $.less()
  96. .on 'error', $.util.log
  97. .pipe $.header banner, pkg: pkg
  98. .pipe $.rename basename: name
  99. .pipe gulp.dest dest.stylesheets.bootstrap2
  100. .pipe $.less plugins: [cleanCss]
  101. .pipe $.header banner, pkg: pkg
  102. .pipe $.rename suffix: '.min'
  103. .pipe gulp.dest dest.stylesheets.bootstrap2
  104. gulp.task 'less-bootstrap3', ->
  105. gulp
  106. .src src.stylesheets.bootstrap3
  107. .pipe $.changed dest.stylesheets.bootstrap3
  108. .pipe $.less()
  109. .pipe $.header banner, pkg: pkg
  110. .pipe $.rename basename: name
  111. .pipe gulp.dest dest.stylesheets.bootstrap3
  112. .pipe $.less compress: true, cleancss: true
  113. .pipe $.header banner, pkg: pkg
  114. .pipe $.rename suffix: '.min'
  115. .pipe gulp.dest dest.stylesheets.bootstrap3
  116. # docs
  117. vendorTask = (name) ->
  118. return ->
  119. gulp
  120. .src src.docs.vendor[name]
  121. .pipe $.changed dest.docs[name]
  122. .pipe gulp.dest dest.docs[name]
  123. gulp.task 'docs-vendor-scripts', vendorTask 'scripts'
  124. gulp.task 'docs-vendor-stylesheets', vendorTask 'stylesheets'
  125. gulp.task 'docs-vendor-fonts', vendorTask 'fonts'
  126. gulp.task 'docs-coffee', ->
  127. gulp
  128. .src src.docs.scripts
  129. .pipe $.changed dest.docs.scripts
  130. .pipe $.coffeelint 'coffeelint.json'
  131. .pipe $.coffeelint.reporter()
  132. .pipe $.coffeelint.reporter("fail")
  133. .pipe $.coffee()
  134. .on 'error', $.util.log
  135. .pipe gulp.dest dest.docs.scripts
  136. gulp.task 'docs-less', ->
  137. gulp
  138. .src src.docs.stylesheets
  139. .pipe $.changed dest.docs.stylesheets
  140. .pipe $.less()
  141. .pipe gulp.dest dest.docs.stylesheets
  142. gulp.task 'docs-jade', ->
  143. gulp
  144. .src src.docs.markup
  145. .pipe $.changed dest.docs.markup
  146. .pipe $.jade pretty: true
  147. .pipe gulp.dest dest.docs.markup
  148. # test
  149. gulp.task 'test-coffee', ['coffee'], ->
  150. gulp
  151. .src src.test
  152. .pipe $.changed dest.test
  153. .pipe $.coffeelint 'coffeelint.json'
  154. .pipe $.coffeelint.reporter()
  155. .pipe $.coffeelint.reporter("fail")
  156. .pipe $.coffee()
  157. .on 'error', $.util.log
  158. .pipe gulp.dest dest.test
  159. gulp.task 'test-go', ['test-coffee'], (done) ->
  160. karma.start extend(karmaConfig, singleRun: true), done
  161. # extra
  162. gulp.task 'connect', ['docs'], ->
  163. $.connect.server
  164. root: [__dirname]
  165. host: server.host
  166. port: server.port
  167. livereload: true
  168. gulp.task 'open', ['connect'], ->
  169. gulp
  170. .src 'index.html'
  171. .pipe $.open '', url: "http://#{server.host}:#{server.port}"
  172. # watch
  173. gulp.task 'watch', ['connect'], ->
  174. gulp.watch src.scripts, ['coffee']
  175. gulp.watch src.stylesheets.bootstrap2, ['less-bootstrap2']
  176. gulp.watch src.stylesheets.bootstrap3, ['less-bootstrap3']
  177. gulp.watch src.docs.vendor.scripts, ['docs-vendor-scripts']
  178. gulp.watch src.docs.vendor.stylesheets, ['docs-vendor-stylesheets']
  179. gulp.watch src.docs.vendor.fonts, ['docs-vendor-fonts']
  180. gulp.watch src.docs.scripts, ['docs-coffee']
  181. gulp.watch src.docs.stylesheets, ['docs-less']
  182. gulp.watch src.docs.markup, ['docs-jade']
  183. gulp.watch('package.json', ['dist']).on 'change', -> pkg = require './package.json'
  184. gulp.watch [
  185. "#{dest.scripts}/*.js"
  186. "#{dest.stylesheets.bootstrap2}/*.css"
  187. "#{dest.stylesheets.bootstrap3}/*.css"
  188. "*.html"
  189. ]
  190. .on 'change', (event) ->
  191. gulp.src event.path
  192. .pipe $.connect.reload()
  193. gulp.task 'docs', ['docs-vendor-scripts', 'docs-vendor-stylesheets', 'docs-vendor-fonts', 'docs-coffee', 'docs-less', 'docs-jade']
  194. gulp.task 'less', ['less-bootstrap2', 'less-bootstrap3']
  195. gulp.task 'dist', ['coffee', 'less']
  196. gulp.task 'test', ['coffee', 'test-coffee', 'test-go']
  197. gulp.task 'server', ['connect', 'open', 'watch']
  198. gulp.task 'default', ['dist', 'docs', 'server']