-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathGulpfile.coffee
169 lines (150 loc) · 4.28 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
_ = require 'lodash'
del = require 'del'
path = require 'path'
gulp = require 'gulp'
karma = require('karma').server
mocha = require 'gulp-mocha'
rename = require 'gulp-rename'
nodemon = require 'gulp-nodemon'
gulpWebpack = require 'gulp-webpack'
coffeelint = require 'gulp-coffeelint'
runSequence = require 'run-sequence'
RewirePlugin = require 'rewire-webpack'
webpack = require 'webpack'
clayLintConfig = require 'clay-coffeescript-style-guide'
karmaConf =
frameworks: ['mocha']
client:
useIframe: true
captureConsole: true
mocha:
timeout: 1000
files: [
'build/test/bundle.js'
]
browsers: ['Chrome', 'Firefox']
paths =
static: './src/static/**/*'
coffee: ['./src/**/*.coffee', './*.coffee', './test/*/**/*.coffee']
root: './src/root.coffee'
rootTests: './test/index.coffee'
rootServerTests: './test/server.coffee'
dist: './dist/'
build: './build/'
# start the dev server, and auto-update
gulp.task 'dev', ['assets:dev'], ->
gulp.start 'server:dev'
# compile sources: src/* -> build/*
gulp.task 'assets:dev', [
'static:dev'
]
# compile sources: src/* -> dist/*
gulp.task 'assets:prod', [
'scripts:prod'
'static:prod'
]
# build for production
gulp.task 'build', (cb) ->
runSequence 'clean:dist', 'assets:prod', cb
# tests
# process.exit is added due to gulp-mocha (test:server) hanging
gulp.task 'test', [
'scripts:test'
'test:server'
'lint'
], (cb) ->
karma.start _.defaults(singleRun: true, karmaConf), process.exit
# start the dev server
gulp.task 'server:dev', ->
# Don't actually watch for changes, just run the server
nodemon {script: 'bin/dev_server.coffee', ext: 'null', ignore: ['**/*.*']}
# gulp-mocha will never exit on its own.
gulp.task 'test:server', ['scripts:test'], ->
gulp.src paths.rootServerTests
.pipe mocha()
gulp.task 'test:phantom', ['scripts:test'], (cb) ->
karma.start _.defaults({
singleRun: true,
browsers: ['PhantomJS']
}, karmaConf), cb
gulp.task 'scripts:test', ->
gulp.src paths.rootTests
.pipe gulpWebpack
module:
postLoaders: [
{ test: /\.coffee$/, loader: 'transform/cacheable?envify' }
]
loaders: [
{ test: /\.coffee$/, loader: 'coffee' }
{ test: /\.json$/, loader: 'json' }
{
test: /\.styl$/
loader: 'style/useable!css!stylus?' +
'paths[]=bower_components&paths[]=node_modules'
}
]
plugins: [
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin(
'bower.json', ['main']
)
)
new RewirePlugin()
]
resolve:
root: [path.join(__dirname, 'bower_components')]
extensions: ['.coffee', '.js', '.json', '']
# browser-builtins is for tests requesting native node modules
modulesDirectories: ['web_modules', 'node_modules', './src',
'./node_modules/browser-builtins/builtin']
.pipe rename 'bundle.js'
.pipe gulp.dest paths.build + '/test/'
# run coffee-lint
gulp.task 'lint', ->
gulp.src paths.coffee
.pipe coffeelint(null, clayLintConfig)
.pipe coffeelint.reporter()
gulp.task 'watch:test', ->
gulp.watch paths.coffee, ['test:phantom']
gulp.task 'static:dev', ->
gulp.src paths.static
.pipe gulp.dest paths.build
#
# Production compilation
#
# rm -r dist
gulp.task 'clean:dist', (cb) ->
del paths.dist, cb
# init.coffee --> dist/js/bundle.min.js
gulp.task 'scripts:prod', ->
gulp.src paths.root
.pipe gulpWebpack
module:
postLoaders: [
{ test: /\.coffee$/, loader: 'transform/cacheable?envify' }
]
loaders: [
{ test: /\.coffee$/, loader: 'coffee' }
{ test: /\.json$/, loader: 'json' }
{
test: /\.styl$/
loader: 'style/useable!css!stylus?' +
'paths[]=bower_components&paths[]=node_modules'
}
]
plugins: [
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin(
'bower.json', ['main']
)
)
new webpack.optimize.UglifyJsPlugin()
]
resolve:
root: [path.join(__dirname, 'bower_components')]
extensions: ['.coffee', '.js', '.json', '']
.pipe rename 'bundle.js'
.pipe gulp.dest paths.dist + '/js/'
gulp.task 'static:prod', ->
gulp.src paths.static
.pipe gulp.dest paths.dist