-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.coffee
129 lines (105 loc) · 3.35 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
browserify = require 'browserify'
chalk = require 'chalk'
CSSmin = require 'gulp-minify-css'
ecstatic = require 'ecstatic'
gulp = require 'gulp'
gutil = require 'gulp-util'
jade = require 'gulp-jade'
livereload = require 'gulp-livereload'
path = require 'path'
prefix = require 'gulp-autoprefixer'
prettyTime = require 'pretty-hrtime'
source = require 'vinyl-source-stream'
streamify = require 'gulp-streamify'
stylus = require 'gulp-stylus'
uglify = require 'gulp-uglify'
watchify = require 'watchify'
production = process.env.NODE_ENV is 'production'
config =
scripts:
source: './app/main.js'
extensions: ['.jsx']
destination: './dist/js/'
filename: 'bundle.js'
templates:
source: './app/index.jade'
watch: './app/**/*.jade'
destination: './dist/'
styles:
source: './app/style.styl'
watch: './app/**/*.styl'
destination: './dist/css/'
assets:
source: './app/assets/**/*.*'
watch: './app/assets/**/*.*'
destination: './dist/'
handleError = (err) ->
gutil.log err
gutil.beep()
this.emit 'end'
gulp.task 'scripts', ->
bundle = browserify
entries: [config.scripts.source]
extensions: config.scripts.extensions
debug: not production
build = bundle.bundle()
.on 'error', handleError
.pipe source config.scripts.filename
build.pipe(streamify(uglify())) if production
build
.pipe gulp.dest config.scripts.destination
gulp.task 'templates', ->
pipeline = gulp
.src config.templates.source
.pipe(jade(pretty: not production))
.on 'error', handleError
.pipe gulp.dest config.templates.destination
pipeline = pipeline.pipe livereload(auto: false) unless production
pipeline
gulp.task 'styles', ->
styles = gulp
.src config.styles.source
.pipe stylus
'include css': true
.on 'error', handleError
.pipe prefix 'last 2 versions', 'Chrome 34', 'Firefox 28', 'iOS 7'
styles = styles.pipe(CSSmin()) if production
styles = styles.pipe gulp.dest config.styles.destination
styles = styles.pipe livereload(auto: false) unless production
styles
gulp.task 'assets', ->
gulp
.src config.assets.source
.pipe gulp.dest config.assets.destination
gulp.task 'server', ->
require('http')
.createServer ecstatic root: path.join(__dirname, 'dist')
.listen 9001
gulp.task 'watch', ->
livereload.listen()
gulp.watch config.templates.watch, ['templates']
gulp.watch config.styles.watch, ['styles']
gulp.watch config.assets.watch, ['assets']
bundle = watchify browserify
entries: [config.scripts.source]
extensions: config.scripts.extensions
debug: not production
cache: {}
packageCache: {}
fullPaths: true
bundle.on 'update', ->
gutil.log "Starting '#{chalk.cyan 'rebundle'}'..."
start = process.hrtime()
build = bundle.bundle()
.on 'error', handleError
.pipe source config.scripts.filename
build
.pipe gulp.dest config.scripts.destination
.pipe(livereload())
gutil.log "Finished '#{chalk.cyan 'rebundle'}' after #{chalk.magenta prettyTime process.hrtime start}"
.emit 'update'
gulp.task 'no-js', ['templates', 'styles', 'assets']
gulp.task 'build', ['scripts', 'no-js']
# scripts and watch conflict and will produce invalid js upon first run
# which is why the no-js task exists.
gulp.task 'default', ['watch', 'no-js', 'server']