-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgulpfile.coffee
101 lines (80 loc) · 3.19 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
gulp = require 'gulp'
gp = do require "gulp-load-plugins"
spawn = require("child_process").spawn
streamqueue = require 'streamqueue'
combine = require 'stream-combiner'
p = require 'path'
# ==========================
# TODO: only runs @ root, should run anywhere in proj dir
destPath = './public/dist'
htmlminOptions =
removeComments: true
removeCommentsFromCDATA: true
collapseWhitespace: true
# conservativeCollapse: true # otherwise <i> & text squished
collapseBooleanAttributes: true
removeAttributeQuotes: true
removeRedundantAttributes: true
caseSensitive: true
minifyJS: true
minifyCSS: true
# ==========================
gulp.task 'css', ->
gulp.src './public/css/b-app.less'
# TODO: switch out font-awesome woff path w/ CDN path
# .pipe replace "../bower_components/font-awesome/fonts", "//cdn.jsdelivr.net/fontawesome/4.1.0/fonts"
.pipe gp.less paths: './public/b-*/b-*.less' # @import path
.pipe gp.minifyCss cache: true, keepSpecialComments: 0 # remove all
.pipe gulp.dest destPath
gulp.task 'html', ->
gulp.src ['./public/index.html']
.pipe gp.htmlReplace
js: 'b-app.js'
css: 'b-app.css'
.pipe gp.replace 'dist/', ''
.pipe gp.htmlmin htmlminOptions
.pipe gulp.dest destPath
gulp.task 'js', ->
# inline templates
ngTemplates = gulp.src './public/b-*/b-*.html'
.pipe gp.htmlmin htmlminOptions
.pipe gp.angularTemplatecache module: 'B.Templates', standalone: true # annotated already
# compile cs & annotate for min
ngModules = gulp.src ['./public/b-*/b-*.coffee', './public/js/b-app.coffee']
.pipe gp.plumber()
.pipe gp.replace 'dist/', '' # for b-map.coffee loading topojson
.pipe gp.replace "# 'B.Templates'", "'B.Templates'" # for b-app.coffee $templateCache
.pipe gp.coffee()
.pipe gp.ngAnnotate() # ngmin doesn't annotate coffeescript wrapped code
# src that need min
otherSrc = ['./public/bower_components/topojson/topojson.js']
other = gulp.src otherSrc
# min above
min = streamqueue(objectMode: true, ngTemplates, ngModules, other)
.pipe gp.uglify()
# src already min
otherMinSrc = [
'./public/bower_components/angular/angular.min.js'
'./public/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js'
'./public/bower_components/d3/d3.min.js'
] # order is respected
otherMin = gulp.src otherMinSrc
# concat
streamqueue objectMode: true, otherMin, min # other 1st b/c has angular
.pipe gp.concat 'b-app.js'
.pipe gulp.dest destPath
gulp.task 'server', -> spawn 'bash', ['./scripts/start.sh'], {stdio: 'inherit'}
# ==========================
gulp.task 'dev', ['server'], -> # not compiling js due to using un-min files
gulp.src ['./public/b-*/b-*.less', './public/css/b-app.less']
.pipe gp.watch {emit: 'one', name: 'css'}, ['css']
jsSrc = [
'./public/b-*/b-*.coffee', './public/js/b-app.coffee'
'./public/b-*/b-*.html'
# './public/bower_components/**/*.js' # gulp watch can't see added files unless using glob option
]
gulp.src(jsSrc).pipe gp.watch {emit: 'one', name: 'js'}, ['js']
gulp.src ['./public/index.html']
.pipe gp.watch {emit: 'one', name: 'html'}, ['html']
gulp.task 'prod', ['css', 'js', 'html']
gulp.task 'default', ['dev']