-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
208 lines (165 loc) · 6.08 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
gulp = require 'gulp'
gutil = require 'gulp-util'
shell = require 'gulp-shell'
notify = require 'gulp-notify'
watch = require 'gulp-watch'
sequence = require 'gulp-watch-sequence'
dirSync = require 'gulp-directory-sync'
notifier = require 'node-notifier'
sass = require 'gulp-sass'
webpack = require 'webpack'
webpackStream = require 'webpack-stream'
webpackConfig = require './webpack.config'
stripAnsi = require 'strip-ansi'
browserSync = require('browser-sync').create()
browserSyncConfig = require './bs-config'
reload = browserSync.reload
# htmlInjector = require 'bs-html-injector'
# reload = htmlInjector
jshint = require 'jshint'
notify.logLevel 0
### ########################### Base Tasks ########################### ###
gulp.task 'default', ['build-dev']
gulp.task 'watch', ['build-dev']
# Production build
gulp.task 'build', ['sass', 'webpack:build', 'jekyll:build']
# Build and watch cycle (another option for development)
gulp.task 'build-dev', ['webpack:build-dev', 'sass:build-dev', 'browser-sync', 'watch']
gulp.task 'watch', ->
queue = sequence(300)
watch './assets/scripts/**/*',
name : 'JS'
emitOnGlob : false
maxListeners: 999
, queue.getHandler 'webpack:build-dev'
watch './assets/styles/**/*.scss',
name : 'CSS'
emitOnGlob : false
maxListeners: 999
, queue.getHandler 'sass:build-dev'
watch 'target/library-management-system-1.0-SNAPSHOT/**/*',
name : 'TARGET'
emitOnGlob : false
maxListeners: 999
, queue.getHandler 'browser-sync:reload'
return
### ####################### Browser Sync Tasks ####################### ###
gulp.task 'browser-sync', ->
# browserSync.use htmlInjector,
# files: "target/epls-1.0-SNAPSHOT/**/*.jsp"
browserSync.init browserSyncConfig
return
gulp.task 'browser-sync:reload', reload
### ########################### SASS Tasks ########################### ###
sassOptions =
includePaths: ['./assets/styles/_sass/']
gulp.task 'sass:build-dev', ->
sassPipeline = sass(sassOptions)
.on 'error', sass.logError
.on 'error', notify.onError (error) ->
browserSync.sockets.emit 'fullscreen:message',
title: "SASS Error:"
body: error.message
title: 'SASS Error'
# subtitle: "<%= error.plugin %>"
message: error.message
onLast: true
gulp.src './assets/styles/main.scss'
.pipe sassPipeline
.pipe gulp.dest './src/main/webapp/styles'
return
### ######################### WebPack Tasks ########################## ###
gulp.task 'webpack:build', (callback) ->
# modify some webpack config options
myConfig = Object.create webpackConfig
myConfig.plugins = myConfig.plugins.concat(
new webpack.DefinePlugin(
'process.env':
# This has effect on the react lib size
'NODE_ENV': JSON.stringify('production')
),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
)
# run webpack
webpack myConfig, (err, stats) ->
throw new gutil.PluginError('webpack:build', err) if(err)
gutil.log '[webpack:build]', stats.toString
colors: true
callback()
return
return
# modify some webpack config options
myDevConfig = Object.create webpackConfig
myDevConfig.devtool = 'sourcemap'
myDevConfig.debug = true
# create a single instance of the compiler to allow caching
devCompiler = webpack(myDevConfig)
# send a fullscreen error message to the browser
devCompiler.plugin 'done', (stats) ->
if stats.hasErrors() || stats.hasWarnings()
notifier.notify
title: 'WebPack Error'
message: """
No. of Errors: #{stats.compilation.errors.length}
stats.compilation.errors[0].message
"""
browserSync.sockets.emit 'fullscreen:message',
title: "Webpack Error:",
body: stripAnsi(stats.toString()),
timeout: 100000
return
# browserSync.reload();
return
gulp.task 'webpack:build-dev', (callback) ->
# run webpack
devCompiler.run (err, stats) ->
throw new gutil.PluginError('webpack:build-dev', err) if err
gutil.log '[webpack:build-dev]', stats.toString
colors: true
callback()
return
# gulp.src webpackConfig.entry
# .pipe webpackStream(webpackConfig).on 'error', notify.onError
# title: 'WebPack Error'
# # subtitle: "<%= error.plugin %>"
# message: "<%= error.message %>"
# onLast: true
# .pipe gulp.dest webpackConfig.output.path
gulp.task 'webpack-dev-server', (callback) ->
# modify some webpack config options
myConfig = Object.create webpackConfig
myConfig.devtool = 'eval'
myConfig.debug = true
# Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig),
publicPath: '/' + myConfig.output.publicPath
stats:
colors: true
).listen 8108, 'localhost', (err) ->
throw new gutil.PluginError('webpack-dev-server', err) if(err)
gutil.log '[webpack-dev-server]', 'http://localhost:8108/webpack-dev-server/'
return
### ########################## Jekyll Tasks ########################## ###
gulp.task 'jekyll:build', shell.task ['bundle exec jekyll build']
gulp.task 'jekyll:build-dev', shell.task ['bundle exec jekyll build --config _config.yml,_config.dev.yml']
gulp.task 'jekyll:watch', shell.task ['bundle exec jekyll build --config _config.yml,_config.dev.yml --watch']
gulp.task 'jekyll', ['jekyll:watch']
### ########################### Lint Tasks ########################### ###
gulp.task 'js:lint', ->
gulp.src '/src/**/*.js'
.pipe jshint()
# Use gulp-notify as jshint reporter
.pipe notify (file) ->
return false if file.jshint.success
errors = file.jshint.results.map (data) ->
"(#{data.error.line}:#{data.error.character}) #{data.error.reason}" if data.error
.join '\n'
"#{file.relative} (#{file.jshint.results.length} errors)\n#{errors}"
return
### ######################## File Sync Tasks ######################### ###
gulp.task 'sync-src-target', ->
gulp.src ''
.pipe dirSync 'src/webapp', 'target/library-management-system-1.0-SNAPSHOT', { printSummary: true, nodelete: true }
.on('error', gutil.log);
return