-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.coffee
135 lines (120 loc) · 3.65 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
path = require 'path'
gulp = require 'gulp'
CSSmin = require 'gulp-minify-css'
uglify = require 'gulp-uglify'
coffee = require 'gulp-coffee'
ecstatic = require 'ecstatic'
livereload = require 'gulp-livereload'
prefix = require 'gulp-autoprefixer'
lr = require 'tiny-lr'
reloadServer = lr()
$ = require('gulp-load-plugins')()
config = require './package.json'
production = process.env.NODE_ENV is 'production'
paths =
scripts:
source: './src/app/**/*.coffee'
watch: './src/app/**/*.coffee'
destination: './public/js/'
templates:
source: './src/templates/**/*.html'
watch: './src/templates/**/*.html'
styles:
source: './src/stylus/style.styl'
watch: './src/stylus/**/*.styl'
destination: './public/css/'
assets:
source: './src/assets/**/*.*'
watch: './src/assets/**/*.*'
destination: './public/'
handleError = (err) ->
$.util.log err
$.util.beep()
this.emit('end')
gulp.task 'scripts', ->
scripts = gulp.src(paths.scripts.source)
.pipe($.ngClassify(
appName: 'ham'
))
.pipe($.coffee(bare: false)).on('error', handleError)
# make sure ham app is first module initialized
.pipe($.order(['main.js']))
.pipe($.filesize())
.pipe($.concat("app.js"))
scripts = scripts.pipe($.uglify()) if production
scripts.pipe(gulp.dest(paths.scripts.destination))
.pipe($.filesize())
.pipe livereload reloadServer
gulp.task 'js_libs', ->
bower_root = './bower_components/'
# move to package.json?
lib_list = [
'angular/angular.js'
'angular-animate/angular-animate.js'
'angular-leaflet-directive/dist/angular-leaflet-directive.js'
'marked/lib/marked.js'
'angular-marked/angular-marked.js'
'gsap/src/uncompressed/TweenMax.js'
'ng-Fx/dist/ng-Fx.js'
'angularjs-geolocation/src/geolocation.js'
'angular-ui-router/release/angular-ui-router.js'
'angular-touch/angular-touch.js'
'angular-carousel/dist/angular-carousel.js'
]
src_list = lib_list.map (lib) ->
return bower_root+lib
lib_names = lib_list.map (lib) ->
return path.basename(lib)
libs = gulp
.src(src_list)
.pipe($.order(lib_names))
libs = libs.pipe($.uglify()) if production
libs
.pipe($.concat("libs.js"))
.pipe($.filesize())
.on 'error', handleError
.pipe gulp.dest paths.scripts.destination
gulp.task 'templates', ->
gulp
.src paths.templates.source
.pipe($.angularTemplatecache(
module: 'ham'
))
.on 'error', handleError
.pipe gulp.dest paths.scripts.destination
.pipe($.filesize())
.pipe livereload(reloadServer)
gulp.task 'styles', ->
styles = gulp
.src paths.styles.source
.pipe($.stylus({
set: ['include css']
use: ['nib']
}))
.on 'error', handleError
.pipe prefix 'last 2 versions', 'Chrome 34', 'Firefox 28', 'iOS 7'
styles = styles.pipe(CSSmin()) if production
styles.pipe gulp.dest paths.styles.destination
.pipe livereload reloadServer
gulp.task 'assets', ->
gulp
.src paths.assets.source
.pipe gulp.dest paths.assets.destination
.pipe($.filesize())
.pipe livereload(reloadServer)
gulp.task 'server', ->
require('http')
.createServer ecstatic(root: __dirname + '/public')
.listen 9001
gulp.task "watch", ->
reloadServer.listen 35729
gulp.watch paths.templates.watch, ['templates']
gulp.watch paths.scripts.watch, ['scripts']
gulp.watch paths.styles.watch, ['styles']
gulp.watch paths.assets.watch, ['assets']
# TODO: test
gulp.task 'deploy', ->
gulp.src("./public/**/*")
.pipe($.ghPages())
gulp.task "build", ['scripts', 'templates', 'styles', 'assets', 'js_libs']
gulp.task "default", ["build", "watch", "server"]