-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.coffee
133 lines (112 loc) · 2.93 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
# core
gulp = require 'gulp'
gutil = require 'gulp-util'
# stream utilities
gif = require 'gulp-if'
path = require 'path'
rimraf = require 'rimraf'
# plugins
imagemin = require 'gulp-imagemin'
htmlmin = require 'gulp-minify-html'
uglify = require 'gulp-uglify'
reload = require 'gulp-livereload'
cache = require 'gulp-cached'
replace = require 'gulp-replace'
sourcemaps = require 'gulp-sourcemaps'
# misc
nodemon = require 'gulp-nodemon'
autowatch = require 'gulp-autowatch'
nib = require 'nib'
# browserify crap
source = require 'vinyl-source-stream'
buffer = require 'vinyl-buffer'
coffeeify = require 'coffeeify'
envify = require 'envify'
browserify = require 'browserify'
watchify = require 'watchify'
production = process.env.NODE_ENV is 'production'
development = process.env.NODE_ENV is 'development'
local = !production and !development
# version
{version} = require './package.json'
# paths
paths =
img: './client/img/**/*'
vendor: './client/vendor/**/*'
fonts: './client/fonts/**/*'
bundle: './client/index.coffee'
html: './client/**/*.html'
gulp.task 'server', (cb) ->
watcher = nodemon
verbose: false
script: './server'
watch: ['./server']
ext: 'js json coffee'
ignore: './server/test'
watcher.once 'start', cb
watcher.on 'start', ->
# TODO: make sure this is actually right
setTimeout reload.reload, 1000
return
# javascript
args =
fullPaths: true
debug: !production
cache: {}
packageCache: {}
extensions: ['.coffee']
bundler = browserify paths.bundle, args
bundler = watchify bundler if local
bundler.transform coffeeify
bundler.transform
global: true
, envify
gulp.task 'rimraf', (cb) ->
rimraf.sync './public'
cb()
reportError = (err) ->
gutil.log gutil.colors.red err.message
gutil.beep()
bundle = ->
bundler.bundle()
.on 'error', reportError
.pipe source 'index.js'
.pipe buffer()
.pipe cache 'js'
.pipe sourcemaps.init
loadMaps: true
.pipe gif !local, uglify()
.pipe sourcemaps.write '.'
.pipe gulp.dest './public'
.pipe gif '*.js', reload quiet: true
gulp.task 'js', bundle
gulp.task 'html', ->
gulp.src paths.html
.pipe cache 'html'
.pipe replace '$CACHE_BUST', String Date.now()
.pipe htmlmin()
.pipe gulp.dest './public'
.pipe reload quiet: true
gulp.task 'img', ->
gulp.src paths.img
.pipe cache 'img'
.pipe imagemin()
.pipe gulp.dest './public/img'
.pipe reload quiet: true
gulp.task 'vendor', ->
gulp.src paths.vendor
.pipe cache 'vendor'
.pipe gulp.dest './public/vendor'
.pipe reload quiet: true
gulp.task 'fonts', ->
gulp.src paths.fonts
.pipe cache 'fonts'
.pipe gulp.dest './public/fonts'
.pipe reload quiet: true
gulp.task 'watch', (cb) ->
reload.listen()
bundler.on 'update', gulp.parallel 'js'
autowatch gulp, paths
cb()
gulp.task 'build', gulp.parallel 'html', 'img', 'vendor', 'fonts', 'js'
gulp.task 'default', gulp.series 'rimraf', 'build', 'server', 'watch'