-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.coffee
165 lines (145 loc) · 4.09 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
gulp = require 'gulp'
argv = require('yargs').argv
cache = require 'gulp-cached'
gulpif = require 'gulp-if'
open = require 'open'
es = require 'event-stream'
coffee = require 'gulp-coffee'
less = require 'gulp-less'
concat = require 'gulp-concat'
uglify = require 'gulp-uglify'
inject = require 'gulp-inject'
connect = require 'gulp-connect'
imagemin = require 'gulp-imagemin'
bowerFiles = require 'main-bower-files'
rimraf = require 'rimraf'
classify = require 'gulp-ng-classify'
rename = require "gulp-rename"
templateCache = require 'gulp-angular-templatecache'
runSequence = require 'run-sequence'
preprocess = require 'gulp-preprocess'
rev = require 'gulp-rev'
paths =
base: 'src/'
index: 'src/index.html'
fonts: 'src/fonts/**/*'
images: 'src/images/**/*'
styles: 'src/styles/**/*.less'
base_style: 'src/styles/base.less'
scripts: 'src/scripts/**/*.coffee'
partials: 'src/partials/**/*.html'
folder = if (argv.compress) then 'dist' else 'www'
env = if (argv.compress) then 'production' else 'testing'
gulp.task "clean", (cb) ->
rimraf.sync "./#{folder}"
cb null
gulp.task "concat_bower", ->
gulp.src bowerFiles({
filter: /\.js$/i,
paths: {
bowerDirectory: './bower_components',
}
})
.pipe(concat( 'dependencies.js') )
.pipe gulpif(argv.compress, uglify())
.pipe gulpif(argv.compress, rev())
.pipe gulp.dest "#{folder}/scripts"
gulp.task 'scripts', ->
gulp.src paths.scripts
.pipe cache('scripts')
.pipe preprocess context: NODE_ENV: env
.pipe do classify
.pipe coffee bare: false
.pipe gulpif(argv.compress, uglify())
.pipe gulpif(argv.compress, concat('app.js'))
.pipe gulpif(argv.compress, rev())
.pipe gulp.dest "#{folder}/scripts"
gulp.task 'styles', ->
gulp.src paths.base_style
.pipe less()
.pipe gulpif(argv.compress, rev())
.pipe gulp.dest "#{folder}/styles"
gulp.task 'styles:reload', ->
gulp.src paths.base_style
.pipe less()
.pipe gulp.dest "#{folder}/styles"
.pipe connect.reload()
gulp.task 'images', ->
gulp.src paths.images
.pipe cache('images')
.pipe gulpif(argv.compress, imagemin())
.pipe gulp.dest "#{folder}/images"
gulp.task 'fonts', ->
gulp.src paths.fonts
.pipe cache('fonts')
.pipe gulp.dest "#{folder}/fonts"
gulp.task 'partials', ->
gulp.src paths.partials
.pipe templateCache('templates', {standalone:true, root: '/partials/'} )
.pipe rename(extname: '.js')
.pipe gulpif(argv.compress, uglify())
.pipe gulpif(argv.compress, rev())
.pipe gulp.dest "#{folder}/scripts"
gulp.task 'index', ->
if(argv.compress)
scripts = [
"./#{folder}/scripts/dependencies-*.js"
"./#{folder}/scripts/templates-*.js"
"./#{folder}/scripts/app-*.js"
]
else
scripts = "./#{folder}/scripts/**/*.js"
gulp.src paths.index
.pipe inject(es.merge(
gulp.src "./#{folder}/styles/**/*.css", read: no
,
gulp.src scripts, read: no
), ignorePath: "/#{folder}", addRootSlash: false)
.pipe gulp.dest "#{folder}/"
gulp.task 'server', ->
connect.server
port : 1337
root : "#{folder}"
livereload : yes
fallback : "#{folder}/index.html"
open 'http://localhost:1337'
gulp.task 'up', (cb) ->
runSequence(
'clean',
'concat_bower',
'compile',
'watch',
'server'
cb
);
gulp.task 'reload', ->
gulp.src paths.index
.pipe connect.reload()
# Register tasks
gulp.task 'watch', ->
gulp.watch paths.partials , ['compile']
gulp.watch paths.scripts , ['compile']
gulp.watch paths.styles , ['styles:reload']
gulp.watch paths.images , ['compile']
gulp.watch paths.index , ['compile']
gulp.task 'compile', (cb) ->
runSequence(
[
'scripts',
'styles',
'images',
'fonts'
],
'partials',
'index',
'reload',
cb
);
gulp.task 'build', (cb) ->
runSequence(
'clean',
'concat_bower',
'compile',
cb
);
gulp.task 'default' , ['up']