-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.coffee
133 lines (114 loc) · 3.36 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
gulp = require('gulp')
coffee = require('gulp-coffee')
rename = require('gulp-rename')
gutil = require('gulp-util')
jade = require('gulp-jade')
jshint = require('gulp-jshint')
sass = require('gulp-sass')
rename = require('gulp-rename')
modRewrite = require('connect-modrewrite')
source = require('vinyl-source-stream')
browserify = require('gulp-browserify')
autoprefixer = require('gulp-autoprefixer')
rimraf = require('gulp-rimraf')
runSequence = require('run-sequence')
isProd = gutil.env.type == 'prod'
changedFile = (file) ->
refresh.changed file.path
return
sources =
sass: 'app/styles/**'
html: 'app/**/*.html'
jade: 'app/**/*.jade'
js: 'app/**/*.js'
coffee: 'app/**/*.coffee'
assets: 'app/assets/**/*'
lib: 'app/scripts/lib/*.js'
destinations =
css: 'dist/'
html: 'dist/'
js: 'dist/'
coffee: 'app/'
assets: 'dist/assets'
lib: 'dist/scripts/lib/'
# Modules for webserver and livereload
express = require('express')
refresh = require('gulp-livereload')
liveReload = require('connect-livereload')
liveReloadPort = 35729
serverPort = 7000
server = express()
server.set 'view engine', 'jade'
server.use liveReload(port: liveReloadPort) # Add live reload
server.use express.static('dist') # Use our 'dist' folder as rootfolder
server.all '/*', (req, res) -> # Because I like HTML5 pushstate .. this redirects everything back to our index.html
res.sendFile 'index.html', root: 'dist'
return
gulp.task 'js', ->
gulp.src('app/scripts/main.coffee', read: false)
.pipe(browserify(
transform: ['coffeeify']
extensions: ['.coffee', '.js']
insertGlobals: true
debug: !isProd))
.pipe(rename('app.js'))
.pipe(gulp.dest(destinations.js))
gulp.task 'sass', ->
gulp.src('app/styles/styles.sass')
.pipe(sass(
indentedSyntax: true
onError: (e) ->
console.log e
))
.pipe(autoprefixer('last 2 versions', '> 1%', 'ie 8'))
.pipe(gulp.dest(destinations.css))
gulp.task 'lint', ->
gulp.src(sources.js)
.pipe(jshint())
.pipe(jshint.reporter('default'))
gulp.task 'html', ->
gulp.src(sources.html)
.pipe(gulp.dest(destinations.html))
gulp.task 'jade', ->
gulp.src(sources.jade)
.pipe(jade())
.pipe(gulp.dest(destinations.html))
gulp.task 'assets', ->
gulp.src(sources.assets)
.pipe(gulp.dest(destinations.assets))
gulp.task 'lib', ->
gulp.src(sources.lib)
.pipe(gulp.dest(destinations.lib))
gulp.task 'server', ->
gutil.log 'Express Server Running on Port:', gutil.colors.cyan(serverPort)
gutil.log 'LiveReload Server Running on Port:', gutil.colors.cyan(liveReloadPort)
server.listen(serverPort)
refresh.listen(liveReloadPort)
return
gulp.task 'watch', ->
gulp.watch(sources.sass, [ 'sass' ]).on 'change', changedFile
gulp.watch(sources.assets, [ 'assets' ]).on 'change', changedFile
gulp.watch(sources.jade, [ 'jade' ]).on 'change', changedFile
gulp.watch(sources.html, [ 'html' ]).on 'change', changedFile
gulp.watch(sources.js, [ 'js' ]).on 'change', changedFile
gulp.watch(sources.coffee, [ 'js' ]).on 'change', changedFile
gulp.watch(sources.lib, [ 'lib' ]).on 'change', changedFile
return
gulp.task 'clean', ->
gulp
.src([ 'dist/' ], read: false)
.pipe(rimraf(force: true))
gulp.task 'build', ->
runSequence 'clean', [
'js'
'sass'
'jade'
'html'
'lib'
'assets'
]
gulp.task 'default', [
'build'
'server'
'watch'
]