-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
130 lines (102 loc) · 3.58 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
require 'coffee-script/register'
gulp = require 'gulp'
$ = require('gulp-load-plugins')()
del = require 'del'
runSequence = require 'run-sequence'
webpack = require 'webpack'
WebpackDevServer = require 'webpack-dev-server'
webpack_dev_config = require './webpack.config'
webpack_dev_runner = webpack webpack_dev_config
webpack_dist_config = require './webpack.config.dist'
webpack_stream = require 'webpack-stream'
http = require 'http'
# web server handle
wds = null
paths =
src: './src'
dist: './dist'
############################################
# dev
############################################
gulp.task 'webpack', () ->
webpack_dev_runner.run (err, stats) ->
throw new $.util.PluginError('webpack', err) if err
$.util.log "[webpack]", stats.toString
colors: true
source: true
timings: true
gulp.task 'jade', () ->
# uncache data.coffee from require cache
delete require.cache[require.resolve("#{paths.src}/jade/data")]
gulp.src("#{paths.src}/jade/index.jade")
.pipe $.plumber()
.pipe $.jade
data: require("#{paths.src}/jade/data")
pretty: true
.pipe gulp.dest(paths.dist)
gulp.task 'copy:assets', () ->
gulp.src("#{paths.src}/assets/**/*", { base: paths.src })
.pipe gulp.dest(paths.dist)
gulp.task 'copy:miscellaneous', () ->
gulp.src("#{paths.src}/miscellaneous/**/*",
{base: "#{paths.src}/miscellaneous"})
.pipe gulp.dest(paths.dist)
gulp.task 'copy', ['copy:assets', 'copy:miscellaneous']
gulp.task 'clean', del.bind(null, [paths.dist])
gulp.task 'server', () ->
config =
contentBase: paths.dist
stats:
colors: true
timings: true
assets: true
hash: true
chunks: false
proxy: require './proxy'
wds = new WebpackDevServer webpack_dev_runner, config
# reload browser when changes detected
wds.app.get '/reload', (req, res) ->
wds.sockWrite wds.sockets, 'ok'
res.sendStatus 200
wds.listen 5000, 'localhost', (err) ->
throw new $.util.PluginError('webpack-dev-server', err) if err
reload = () ->
http.get 'http://localhost:5000/reload', () ->
$.util.log 'Reloading...'
gulp.watch ['src/jade/**/*'], ['jade', reload]
gulp.watch ['src/jade/data.coffee'], ['jade', reload]
gulp.watch ['src/assets/**/*'], ['copy:assets', reload]
gulp.watch ['src/miscellaneous/**'], ['copy:miscellaneous', reload]
gulp.task 'build', () ->
runSequence 'clean', ['jade', 'copy', 'webpack']
gulp.task 'serve', () ->
runSequence 'clean', ['jade', 'copy', 'server']
############################################
# dist
############################################
gulp.task 'dist:webpack', () ->
gulp.src "#{paths.src}/coffee/main.js"
.pipe webpack_stream(webpack_dist_config)
.pipe gulp.dest(paths.dist)
gulp.task 'dist:jade', () ->
jade_data = require "#{paths.src}/jade/data"
manifest_data = require "#{paths.dist}/manifest.json"
jade_data.manifest = {}
jade_data.manifest[key] = v for key, v of manifest_data
gulp.src("#{paths.src}/jade/index.jade")
.pipe $.plumber()
.pipe $.jade
data: jade_data
.pipe gulp.dest(paths.dist)
gulp.task 'dist:copy:assets', () ->
gulp.src("#{paths.src}/assets/**/*", { base: paths.src })
.pipe gulp.dest(paths.dist)
gulp.task 'dist:copy:miscellaneous', () ->
gulp.src("#{paths.src}/miscellaneous/**/*",
{base: "#{paths.src}/miscellaneous"})
.pipe gulp.dest(paths.dist)
gulp.task 'dist:copy', ['dist:copy:assets', 'dist:copy:miscellaneous']
gulp.task 'dist:build', () ->
runSequence 'clean', ['dist:webpack', 'dist:copy'], 'dist:jade'
gulp.task 'dist', ['dist:build']
gulp.task 'default', ['dist:build']