This repository has been archived by the owner on Mar 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.coffee
294 lines (214 loc) · 7.66 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#########################################################
# Gulp Config
# Author: [email protected] @ WINTR
#########################################################
#--------------------------------------------------------
# Requirements
#--------------------------------------------------------
gulp = require 'gulp'
coffeeify = require 'coffeeify'
handleify = require 'handleify'
runSequence = require 'run-sequence'
eventStream = require 'event-stream'
mainBowerFiles = require 'main-bower-files'
spawn = require('child_process').spawn
plugins = require('gulp-load-plugins')()
#--------------------------------------------------------
# Variables
#--------------------------------------------------------
# Source path
sourcePath = "source"
# Public directory
outputPath = "public"
# Views directory
viewsPath = "sinatra/views"
# Directory where vendor files live
vendorPath = "vendor"
# Name of JavaScript directory
jsDirectory = "javascripts"
# Name of CSS directory
cssDirectory = "stylesheets"
# Name of Images directory
imagesDirectory = "images"
# Name of SVG directory
svgDirectory = "svg"
# Name of Fonts directory
fontsDirectory = "fonts"
# Name of main JS file
jsMainFile = "main"
# Name of main CSS file
cssMainFile = "main"
# Travis server running
serverRunning = false
#--------------------------------------------------------
# Compile Stylesheets
#--------------------------------------------------------
gulp.task "stylesheets", ->
gulp.src ["#{sourcePath}/#{cssDirectory}/#{cssMainFile}.styl"]
.pipe plugins.plumber()
.pipe plugins.stylus()
.pipe plugins.autoprefixer()
.pipe gulp.dest "#{outputPath}/#{cssDirectory}"
gulp.src ["#{sourcePath}/#{cssDirectory}/ie.styl"]
.pipe plugins.plumber()
.pipe plugins.stylus()
.pipe plugins.autoprefixer()
.pipe gulp.dest "#{outputPath}/#{cssDirectory}"
gulp.task "stylesheet-images", ->
gulp.src "#{sourcePath}/#{cssDirectory}/images/*"
.pipe gulp.dest "#{outputPath}/#{cssDirectory}/images"
#--------------------------------------------------------
# Compile JavaScripts
#--------------------------------------------------------
gulp.task "javascripts", ->
gulp.src "#{sourcePath}/#{jsDirectory}/#{jsMainFile}.coffee", read: false
.pipe plugins.plumber()
.pipe plugins.browserify
transform: ["handleify", "coffeeify", "jadeify"]
extensions: [".coffee", ".js", ".jade"]
debug: true
.pipe plugins.rename "#{jsMainFile}.js"
.pipe gulp.dest "#{outputPath}/#{jsDirectory}"
#--------------------------------------------------------
# Concatenate Bower libraries
#--------------------------------------------------------
gulp.task "bower", ->
gulp.src mainBowerFiles()
.pipe plugins.concat("vendor.js")
.pipe gulp.dest "#{outputPath}/#{jsDirectory}"
# --------------------------------------------------------
# Clean output directories
# --------------------------------------------------------
gulp.task "clean", ->
directoriesToClean = [
"#{outputPath}/#{jsDirectory}"
"#{outputPath}/#{cssDirectory}"
"#{outputPath}/#{imagesDirectory}"
]
gulp.src directoriesToClean, read: false
.pipe plugins.clean()
#--------------------------------------------------------
# Copy images
#--------------------------------------------------------
gulp.task "copy-images", ->
gulp.src "#{sourcePath}/#{imagesDirectory}/**/*"
.pipe gulp.dest "#{outputPath}/#{imagesDirectory}"
copyImage = (path) ->
console.log chalk.cyan "copying #{path}"
gulp.src path
.pipe gulp.dest "#{outputPath}/#{imagesDirectory}"
#--------------------------------------------------------
# Minify
#--------------------------------------------------------
gulp.task "minify", ->
# Compress images
gulp.src "#{outputPath}/#{imagesDirectory}/*"
.pipe plugins.imagemin
optimizationLevel: 5
.pipe plugins.plumber()
.pipe gulp.dest "#{outputPath}/#{imagesDirectory}"
# Compress Main JavaScript
gulp.src "#{outputPath}/#{jsDirectory}/#{jsMainFile}.js"
.pipe plugins.uglify()
.pipe gulp.dest "#{outputPath}/#{jsDirectory}/"
# Compress Vendor JavaScript
gulp.src "#{outputPath}/#{jsDirectory}/vendor.js"
.pipe plugins.uglify()
.pipe gulp.dest "#{outputPath}/#{jsDirectory}/"
# Minify CSS and Combine MediaQueries
# gulp.src "#{outputPath}/#{cssDirectory}/*.css"
# .pipe plugins.combineMediaQueries()
# .pipe plugins.minifyCss()
# .pipe gulp.dest "#{outputPath}/#{cssDirectory}"
#--------------------------------------------------------
# Watch for changes and reload
#--------------------------------------------------------
gulp.task "watch", ->
gulp.watch "#{sourcePath}/#{cssDirectory}/**/*.{styl,sass,scss,css}", ->
gulp.start "stylesheets"
plugins.watch "#{sourcePath}/#{imagesDirectory}/**/*.{svg,jpg,gif,png}", (file) ->
# gulp.start "copy-images"
copyImage file.path
gulp.watch "#{sourcePath}/#{jsDirectory}/**/*.{coffee,js,haml,hbs}", ->
gulp.start "javascripts"
gulp.watch "bower.json", ->
gulp.start "bower"
server = plugins.livereload()
plugins.livereload.listen()
plugins.watch "#{outputPath}/**/*.{css,js,svg,jpg,gif,png}"
.pipe plugins.livereload()
gulp.watch "#{viewsPath}/**/*.haml", ->
server.changed()
return
#--------------------------------------------------------
# Lint
#--------------------------------------------------------
gulp.task "lint", ->
gulp.src "#{sourcePath}/#{jsDirectory}/**/*.coffee"
.pipe plugins.coffeelint()
.pipe plugins.coffeelint.reporter()
gulp.src "#{outputPath}/#{cssDirectory}/#{cssMainFile}.css"
.pipe plugins.csslint()
.pipe plugins.csslint.reporter()
#--------------------------------------------------------
# Icon Font
#--------------------------------------------------------
gulp.task "icon-font", ->
cssTemplateFilename = "icon-font-template.css"
cssOutputFilename = "_icons.styl"
fontName = "icons"
fontPath = "../fonts/"
className = "icon"
# Grab SVGs from Sketch.
# Requires Sketch Tools http://sketchtool.bohemiancoding.com/sketchtool-latest.zip
sketchSvgStream = gulp.src "#{sourcePath}/#{svgDirectory}/*.sketch"
.pipe plugins.sketch
export: 'artboards'
formats: 'svg'
# Grab SVGs from 'svg' directory
fileSvgStream = gulp.src "#{sourcePath}/#{svgDirectory}/*.svg"
# Merge svg streams together
allSvgStream = eventStream.merge sketchSvgStream, fileSvgStream
# Generate Font and CSS from all SVGs
allSvgStream
.pipe(plugins.iconfont
fontName: "icons"
normalize: true
).on("codepoints", (codepoints, options) ->
gulp.src "#{sourcePath}/#{svgDirectory}/#{cssTemplateFilename}"
.pipe(plugins.consolidate "lodash",
glyphs: codepoints
fontName: fontName
fontPath: fontPath
className: className
).pipe plugins.rename cssOutputFilename
.pipe gulp.dest "#{sourcePath}/#{cssDirectory}"
).pipe gulp.dest "#{outputPath}/#{fontsDirectory}"
#--------------------------------------------------------
# Sinatra/Shotgun Server
#--------------------------------------------------------
gulp.task "server", ->
child = spawn('bundle', ['exec','ruby', 'app.rb', '-p 9395'])
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
#---------------------------------------------------------
gulp.task "default", ["dev"]
gulp.task "dev", ->
runSequence "clean", [
"copy-images"
"bower"
"javascripts"
"stylesheets"
"stylesheet-images"
], [
"server"
"watch"
]
gulp.task "build", ->
runSequence "clean", [
"copy-images"
"bower"
"javascripts"
"stylesheets"
"stylesheet-images"
], "minify"