-
Notifications
You must be signed in to change notification settings - Fork 61
/
gulpfile.coffee
173 lines (150 loc) · 4.23 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
'use strict'
gulp = require 'gulp'
rjs = require 'requirejs'
runs = require 'run-sequence'
$ = require('gulp-load-plugins')()
production = true if $.util.env.env is 'production'
filename = require('uuid').v4()
lazypipe = require 'lazypipe'
browserSync = require 'browser-sync'
reload = browserSync.reload
$.help gulp
paths =
src: 'app'
script: 'app/assets/js'
coffee: 'app/assets/coffee'
sass: 'app/assets/sass'
css: 'app/assets/css'
images: 'app/assets/images'
test: 'test'
dist: 'dist'
vendor: 'app/assets/vendor'
coffeelintTasks = lazypipe()
.pipe $.coffeelint
.pipe $.coffeelint.reporter
.pipe $.coffee, bare: true
gulp.task 'coffee', ->
gulp.src paths.coffee + '/**/*.coffee'
.pipe $.if !production, $.changed paths.script,
extension: '.js'
.pipe coffeelintTasks()
.pipe gulp.dest paths.script
gulp.task 'test_coffee', ->
gulp.src paths.test + '/**/*.coffee'
.pipe $.if !production, $.changed paths.test,
extension: '.js'
.pipe coffeelintTasks()
.pipe gulp.dest paths.test
gulp.task 'html', ->
gulp.src paths.src + '/*.html'
.pipe $.if !production, $.changed paths.dist
.pipe $.if production, $.minifyHtml()
.pipe $.if production, $.replace 'js/main', 'js/' + filename
.pipe $.if production, $.replace 'vendor/requirejs/require.js', 'js/require.js'
.pipe gulp.dest paths.dist
gulp.task 'compass', ->
gulp.src paths.sass + '/**/*.scss'
.pipe $.if !production, $.changed paths.css,
extension: '.css'
.pipe $.if !production, $.plumber
errorHandler: (error) ->
$.util.log $.util.colors.red error.message
this.emit('end')
.pipe $.compass
css: paths.css
sass: paths.sass
image: paths.image
.pipe $.if production, $.minifyCss()
.pipe gulp.dest paths.dist + '/assets/css/'
gulp.task 'lint', ->
gulp.src 'gulpfile.js'
.pipe $.jshint()
.pipe $.jshint.reporter 'default'
# Clean
gulp.task 'clean', require('del').bind null, [
paths.dist
'.sass-cache'
paths.script
paths.css
]
# Images
gulp.task 'images', ->
gulp.src paths.images + '/**/*.{jpg,jpeg,png,gif}'
.pipe $.changed paths.dist + '/assets/images'
.pipe $.cache $.imagemin
progressive: true
.pipe gulp.dest paths.dist + '/assets/images'
# testing via mocha tool
gulp.task 'test', ->
gulp.src paths.test + '/test.js'
.pipe $.mocha
reporter: 'spec'
# Connect
gulp.task 'connect:app', ->
browserSync
notify: false
server:
baseDir: [paths.src]
# run tasks automatically when files change
gulp.watch paths.coffee + '/**/*.coffee', ['coffee']
gulp.watch paths.test + '/**/*.coffee', ['test_coffee']
gulp.watch paths.src + '/*.html', ['html', reload]
gulp.watch paths.sass + '/**/*.scss', ['compass']
gulp.watch paths.images + '/**/*.{jpg,jpeg,png,gif}', ['images', reload]
gulp.watch paths.script + '/**/*.js', reload
gulp.watch paths.css + '/**/*.css', reload
# Build and serve the output from the dist build
gulp.task 'connect:dist', ->
browserSync
notify: false
server:
baseDir: 'dist'
gulp.task 'copy', ->
gulp.src [
paths.src + '/favicon.ico'
paths.src + '/robots.txt'
'node_modules/apache-server-configs/dist/.htaccess']
.pipe gulp.dest paths.dist
gulp.task 'rjs', ['build'], (cb) ->
rjs.optimize
baseUrl: paths.script
name: 'main'
out: paths.script + '/main-built.js'
mainConfigFile: paths.script + '/main.js'
preserveLicenseComments: false
, (buildResponse) ->
cb()
gulp.task 'rename', ['rjs'], ->
gulp.src paths.script + '/main-built.js'
.pipe $.rename 'assets/js/' + filename + '.js'
.pipe gulp.dest 'dist'
gulp.src paths.vendor + '/requirejs/require.js'
.pipe $.uglify()
.pipe gulp.dest paths.dist + '/assets/js/'
# The default task (called when you run `gulp`)
gulp.task 'default', (cb) ->
runs(
['coffee', 'compass']
'connect:app'
cb)
# Build
gulp.task 'build', [
'coffee'
'images'
'compass'
'html'
'copy'
], ->
gulp.src paths.dist + '/**/*'
.pipe $.size
showFiles: true,
gzip: true
gulp.task 'release', (cb) ->
runs(
['build', 'rjs', 'rename']
cb)
# Load custom tasks from the `tasks` directory
try
require('require-dir')('tasks')
catch error
module.exports = gulp