gulpfile.coffee 6.7 KB

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