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