-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.coffee
330 lines (281 loc) · 12.6 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
gulp = require 'gulp'
autoprefixer = require 'gulp-autoprefixer'
combine = require 'stream-combiner2'
concat = require 'gulp-concat'
rename = require 'gulp-rename'
less = require 'gulp-less'
minifyCSS = require 'gulp-minify-css'
minifyHTML = require 'gulp-minify-html'
sourcemaps = require 'gulp-sourcemaps'
uglify = require 'gulp-uglify'
merge = require 'merge-stream'
nodemon = require 'nodemon'
hbs = require 'express-hbs'
through = require 'through2'
clean = require 'gulp-clean'
coffee = require 'gulp-coffee'
addSrc = require 'gulp-add-src'
jasmine = require 'gulp-jasmine-phantom'
replace = require 'gulp-replace'
svgstore = require 'gulp-svgstore'
svgmin = require 'gulp-svgmin'
pkg = require './package.json'
notifier = require 'node-notifier'
inject = require 'gulp-inject'
streamqueue = require 'streamqueue'
es = require 'event-stream'
__base = './www/'
inlineSvgsAndTemplatesTransform = (filePath, file) ->
return file.contents.toString().replace(/"/g, '\\"')
appendStream = () ->
pass = through.obj()
return es.duplex(pass, streamqueue({ objectMode: true }, pass, arguments[0]))
gulp.task 'less-concat', ->
concatenated = combine.obj [
gulp.src [ './src/less/cyclops.less', './src/less/site/site.less' ]
sourcemaps.init()
less()
autoprefixer
browsers: [ 'ie >= 9', 'last 2 versions', 'ff >20', 'ie >10' ]
cascade: false
sourcemaps.write './'
gulp.dest './www/assets/css'
]
concatenated.on 'error', (error) ->
console.error.bind(console)
notifier.notify
title: 'Less Compilation Error'
message: error.message
icon: './www/assets/img/centurylink-cyclops.png'
concatenated
gulp.task 'less-min', ->
return gulp.src [ './src/less/cyclops.less', './src/less/site/site.less' ]
.pipe sourcemaps.init()
.pipe less()
.pipe autoprefixer
browsers: [ 'ie >= 9', 'last 2 versions' ]
cascade: false
.pipe minifyCSS()
.pipe rename { suffix: '.min' }
.pipe sourcemaps.write './'
.pipe gulp.dest './www/assets/css'
gulp.task 'less', ['less-concat', 'less-min']
gulp.task 'script-concat', ->
# inline icons SVGs
svgs = gulp.src './src/svg/**/*.svg'
.pipe rename { prefix: 'icon-' }
.pipe svgmin()
.pipe svgstore { inlineSvg: true }
templates = gulp.src './src/templates/**/*.tmpl.html'
.pipe concat 'cyclops.tmpl.html'
.pipe minifyHTML { empty: true }
afterFile = gulp.src './build/after.js'
.pipe inject(svgs, { name: 'icons', transform: inlineSvgsAndTemplatesTransform })
.pipe inject(templates, { name: 'templates', transform: inlineSvgsAndTemplatesTransform })
concatenated = combine.obj [
gulp.src './src/scripts/helpers/init.coffee'
addSrc.append [ './src/scripts/helpers/**/*.*', '!./src/scripts/helpers/init.coffee' ]
addSrc.append './src/scripts/extensions/**/*.*'
addSrc.append './src/scripts/bindings/**/*.*'
addSrc.append './src/scripts/widgets/**/*.*'
addSrc.append './src/scripts/models/**/*.*'
addSrc.append [ './src/scripts/validators/**/*.*', '!./src/scripts/validators/register.coffee' ]
addSrc.append './src/scripts/validators/register.coffee'
addSrc.append './src/scripts/*.*'
addSrc.prepend './src/scripts/polyfills/**/*'
coffee({ bare: true })
addSrc.prepend './build/before.js'
appendStream afterFile
addSrc.prepend './src/scripts/vendor/polyfill.js'
addSrc.prepend './src/scripts/globalnavigation/navmenu.js'
sourcemaps.init()
concat('cyclops.js')
sourcemaps.write './'
gulp.dest './www/assets/scripts'
]
concatenated.on 'error', (error) ->
console.error.bind(console)
notifier.notify
title: 'Script Compilation Error'
message: error.message
icon: './www/assets/img/centurylink-cyclops.png'
concatenated
gulp.task 'script-minify', ['script-concat'], ->
gulp.src ['./www/assets/scripts/cyclops.js']
.pipe sourcemaps.init()
.pipe uglify()
.pipe rename { suffix: '.min' }
.pipe sourcemaps.write './'
.pipe gulp.dest './www/assets/scripts'
gulp.task 'test-build', ->
buildCyclops = gulp.src './src/scripts/helpers/init.coffee'
.pipe addSrc.append ['./src/scripts/helpers/**/*.*',
'!./src/scripts/helpers/init.coffee']
.pipe addSrc.append './src/scripts/extensions/**/*.*'
.pipe addSrc.append './src/scripts/bindings/**/*.*'
.pipe addSrc.append './src/scripts/widgets/**/*.*'
.pipe addSrc.append './src/scripts/models/**/*.*'
.pipe addSrc.append ['./src/scripts/validators/**/*.*',
'!./src/scripts/validators/register.coffee']
.pipe addSrc.append './src/scripts/validators/register.coffee'
.pipe addSrc.append './src/scripts/*.*'
.pipe coffee({bare: true})
.pipe sourcemaps.init()
.pipe concat('cyclops.test.only.js')
.pipe sourcemaps.write './'
.pipe gulp.dest './temp'
buildTests = gulp.src ['./specs/testHelpers/*.coffee', './specs/**/*.spec.coffee']
.pipe coffee({bare: true})
.pipe gulp.dest './temp/tests'
return merge buildCyclops, buildTests
gulp.task 'test-run', ['test-build'], ->
return gulp.src './temp/tests/**/*.js'
.pipe jasmine {
abortOnFail: true
integration: true
keepRunner: true
vendor: [
'http://code.jquery.com/jquery-2.2.0.min.js'
'http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.3.0.js'
'http://cdnjs.cloudflare.com/ajax/libs/knockout-validation/2.0.3/knockout.validation.min.js'
'http://code.jquery.com/ui/1.11.4/jquery-ui.min.js'
'http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js'
'./temp/cyclops.test.only.js'
]
}
gulp.task 'test', ['test-run'], ->
gulp.src './temp'
.pipe clean()
gulp.task 'client-watch', ->
gulp.watch './src/less/**/**', ['less-concat']
gulp.watch './src/templates/**/**', ['template-concat']
gulp.watch './src/scripts/**/**', ['script-concat']
gulp.watch './src/svg/**/**', ['svg-concat']
gulp.task 'server-watch', ->
return nodemon
script: 'app.coffee'
ext: 'js,coffee'
ignore: [
'./gulpfile.coffee'
'node_modules/*'
'src/*'
'www/*'
'.git/*'
]
gulp.task 'cleanDist', ->
return gulp.src "./dist/#{pkg.version}", { read: false }
.pipe clean()
gulp.task 'compile', ['cleanDist', 'less-min', 'script-minify'], ->
copyCSS = gulp.src './www/assets/css/**/*'
.pipe gulp.dest "./dist/#{pkg.version}/css/"
copyScripts = gulp.src './www/assets/scripts/**/*'
.pipe replace /\/templates\/cyclops\.tmpl\.html/i, "https://assets.ctl.io/cyclops/#{pkg.version}/templates/cyclops.tmpl.min.html"
.pipe replace /\/svg\/cyclops\.icons\.svg/i, "https://assets.ctl.io/cyclops/#{pkg.version}/svg/cyclops.icons.min.svg"
.pipe gulp.dest "./dist/#{pkg.version}/scripts/"
copyTemplates = gulp.src './www/assets/templates/**/*'
.pipe gulp.dest "./dist/#{pkg.version}/templates/"
copySvg = gulp.src './www/assets/svg/**/*'
.pipe gulp.dest "./dist/#{pkg.version}/svg/"
copyStarterPages = gulp.src './www/starterPages/**/*'
.pipe replace /\/css\/cyclops\.css/i, "https://assets.ctl.io/cyclops/#{pkg.version}/css/cyclops.min.css"
.pipe replace /\/scripts\/cyclops\.js/i, "https://assets.ctl.io/cyclops/#{pkg.version}/scripts/cyclops.min.js"
.pipe gulp.dest "./dist/#{pkg.version}/starterPages/"
copyExamplePages = gulp.src './www/examplePages/**/*'
.pipe replace /\/css\/cyclops\.css/i, "https://assets.ctl.io/cyclops/#{pkg.version}/css/cyclops.min.css"
.pipe replace /\/scripts\/cyclops\.js/i, "https://assets.ctl.io/cyclops/#{pkg.version}/scripts/cyclops.min.js"
.pipe gulp.dest "./dist/#{pkg.version}/examplePages/"
copyImages = gulp.src './www/assets/img/**/*'
.pipe gulp.dest "./dist/#{pkg.version}/img/"
renderHTML = gulp.src './www/views/**/*.html'
.pipe through.obj (file, enc, cb) ->
render = hbs.create().express3
viewsDir: './www/views'
partialsDir: './www/views/partials'
layoutDir: './www/views/layouts'
defaultLayout: './www/views/layouts/default.html'
extName: 'html'
locals = {
settings: {
views: './www/views'
},
version: "#{pkg.version}"
enviroment: "release"
}
self = this;
render file.path, locals, (err, html) ->
if(!err)
file.contents = new Buffer(html);
self.push(file);
cb();
else
console.log "failed to render #{file.path}"
.pipe replace /\/css\/cyclops\.css/i, "https://assets.ctl.io/cyclops/#{pkg.version}/css/cyclops.min.css"
.pipe replace /\/css\/site\.css/i, "https://assets.ctl.io/cyclops/#{pkg.version}/css/site.min.css"
.pipe replace /\/scripts\/cyclops\.js/i, "https://assets.ctl.io/cyclops/#{pkg.version}/scripts/cyclops.min.js"
.pipe replace /\/img\/favicon\//gi, "https://assets.ctl.io/cyclops/#{pkg.version}/img/favicon/"
.pipe gulp.dest "./dist/#{pkg.version}/"
return merge copyCSS, copyScripts, copyTemplates, copySvg, copyStarterPages, copyExamplePages, copyImages, renderHTML
gulp.task 'dev', ['less-concat', 'script-concat', 'client-watch', 'server-watch']
gulp.task 'build', ['less-concat', 'script-concat']
gulp.task 'dist', ['compile'], ->
console.log 'To distribute a new version of cyclops'
console.log ' * Pull and get latests from https://github.com/CenturyLinkCloud/AssetsServer.git'
console.log ' * Copy the contents of the \'dist\' folder from Cyclops to the the \'cyclops\' folder'
console.log ' * Commit the changes to the AssetsServer Repository'
console.log ' * Create a tag for the release in this repository'
console.log " * git tag -a v#{pkg.version} -m 'Add tag v#{pkg.version}'"
console.log ' * git push origin --tags'
console.log ' * Go bump the version in package.json to the next version and commit that as a \'version bump\''
# TRAVIS CRAP
gulp.task 'travis-compile', ['less-concat', 'script-concat'], ->
copyCSS = gulp.src './www/assets/css/**/*'
.pipe gulp.dest "./devDist/css/"
copyScripts = gulp.src './www/assets/scripts/**/*'
.pipe replace /\/templates\/cyclops\.tmpl\.html/i, "https://cyclops-dev.uswest.appfog.ctl.io/templates/cyclops.tmpl.html"
.pipe replace /\/svg\/cyclops\.icons\.svg/i, "https://cyclops-dev.uswest.appfog.ctl.io/svg/cyclops.icons.svg"
.pipe gulp.dest "./devDist/scripts/"
copyTemplates = gulp.src './www/assets/templates/**/*'
.pipe gulp.dest "./devDist/templates/"
copySvg = gulp.src './www/assets/svg/**/*'
.pipe gulp.dest "./devDist/svg/"
copyStarterPages = gulp.src './www/starterPages/**/*'
.pipe replace /\/css\/cyclops\.css/i, "https://cyclops-dev.uswest.appfog.ctl.io/css/cyclops.css"
.pipe replace /\/scripts\/cyclops\.js/i, "https://cyclops-dev.uswest.appfog.ctl.io/scripts/cyclops.js"
.pipe gulp.dest "./devDist/starterPages/"
copyExamplePages = gulp.src './www/examplePages/**/*'
.pipe replace /\/css\/cyclops\.css/i, "https://cyclops-dev.uswest.appfog.ctl.io/css/cyclops.css"
.pipe replace /\/scripts\/cyclops\.js/i, "https://cyclops-dev.uswest.appfog.ctl.io/scripts/cyclops.js"
.pipe gulp.dest "./devDist/examplePages/"
copyImages = gulp.src './www/assets/img/**/*'
.pipe gulp.dest "./devDist/img/"
renderHTML = gulp.src './www/views/**/*.html'
.pipe through.obj (file, enc, cb) ->
render = hbs.create().express3
viewsDir: './www/views'
partialsDir: './www/views/partials'
layoutDir: './www/views/layouts'
defaultLayout: './www/views/layouts/default.html'
extName: 'html'
locals = {
settings: {
views: './www/views'
},
version: "#{pkg.version}"
enviroment: "release"
}
self = this;
render file.path, locals, (err, html) ->
if(!err)
file.contents = new Buffer(html);
self.push(file);
cb();
else
console.log "failed to render #{file.path}"
.pipe replace /\/css\/cyclops\.css/i, "https://cyclops-dev.uswest.appfog.ctl.io/css/cyclops.css"
.pipe replace /\/css\/site\.css/i, "https://cyclops-dev.uswest.appfog.ctl.io/css/site.min.css"
.pipe replace /\/scripts\/cyclops\.js/i, "https://cyclops-dev.uswest.appfog.ctl.io/scripts/cyclops.js"
.pipe replace /\/img\/favicon\//gi, "https://assets.ctl.io/cyclops/#{pkg.version}/img/favicon/"
.pipe gulp.dest "./devDist/"
copyStaticBuildPackFiles = gulp.src ['./.travis/Staticfile','./.travis/nginx.conf']
.pipe gulp.dest './devDist/'
return merge copyCSS, copyScripts, copyTemplates, copySvg, copyStarterPages, copyExamplePages, copyImages, renderHTML, copyStaticBuildPackFiles