forked from andrewminer/crafting-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
319 lines (266 loc) · 11.8 KB
/
Gruntfile.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#
# Crafting Guide - Gruntfile.coffee
#
# Copyright © 2014-2016 by Redwood Labs
# All rights reserved.
#
fs = require 'fs'
EXTERNAL_LIBS = [
'backbone'
'jquery'
'marked'
'underscore'
'underscore.inflections'
'when'
'./vendor/email.js:emailjs'
]
PUBLISHED_FILES = [
'./client/models/base_model.coffee'
'./client/models/game/inventory.coffee'
'./client/models/game/item.coffee'
'./client/models/game/item_slug.coffee'
'./client/models/game/mod.coffee'
'./client/models/game/mod_version.coffee'
'./client/models/game/multiblock.coffee'
'./client/models/game/recipe.coffee'
'./client/models/game/stack.coffee'
'./client/models/game/simple_stack.coffee'
'./client/models/parsing/command_parser_version_base.coffee'
'./client/models/parsing/mod_parser.coffee'
'./client/models/parsing/mod_parser_v1.coffee'
'./client/models/parsing/mod_version_parser.coffee'
'./client/models/parsing/mod_version_parser_v1.coffee'
'./client/models/parsing/versioned_parser_base.coffee'
'./client/models/site/tutorial.coffee'
'./common/constants.coffee'
'./common/underscore.coffee'
'./index.coffee'
]
########################################################################################################################
module.exports = (grunt)->
grunt.loadTasks tasks for tasks in grunt.file.expand './node_modules/grunt-*/tasks'
grunt.config.init
compress:
static:
options:
mode: 'gzip'
files: [
{expand: true, cwd:'./build/static', src:'**/*.css', dest:'./dist/'}
{expand: true, cwd:'./build/static', src:['**/*.html', '!**/index.html'], dest:'./dist/'}
{expand: true, cwd:'./build/static', src:'**/*.ugly.js', dest:'./dist/', ext: '.js'}
{expand: true, cwd:'./build/static', src:'**/*.json', dest:'./dist/'}
{expand: true, cwd:'./build/static', src:'**/*.ttf', dest:'./dist/'}
{expand: true, cwd:'./build/static', src:'**/*.txt', dest:'./dist/'}
]
coffee:
npm_package:
options: {
bare: true
}
files: [
{expand:true, cwd:'./src', src:PUBLISHED_FILES, dest:'./dist', ext:'.js'}
]
copy:
assets_build:
files: [
{expand:true, cwd:'./assets/', src:'**/*', dest:'./build/static'}
]
env_build:
files: [
{expand:true, cwd:'.', src:'.env', dest:'./build'}
]
build_to_dist:
files: [
expand: true
cwd: './build/static/'
src: ['**/*', '!**/*.map', '!**/*.js', '!index.html']
dest: './dist'
]
common_source:
files: [
{expand:true, cwd:'./src/common', src:'**/*.coffee', dest:'./build', ext:'.coffee'}
]
server_source:
files: [
{expand:true, cwd:'./src/server', src:'**/*.coffee', dest:'./build', ext:'.coffee'}
]
clean:
assets: ['./build/static/data', './build/static/images']
build: ['./build']
dist: ['./dist']
templates: ['./src/client/site/templates.js']
jade:
pages:
options:
pretty: true
files: [
expand: true
cwd: './src/client/site'
src: '**/index.jade'
dest: './build/static'
ext: '.html'
]
templates:
options:
client: true
node: true
processName: (path)->
pathElements = path.split '\/'
while true
element = pathElements.shift()
break if element is 'site'
pathElements.pop()
name = pathElements.join '/'
name = name.replace '.jade', ''
return name
files:
'./src/client/site/templates.js': ['./src/client/site/**/!(index)*.jade']
mochaTest:
options:
bail: true
color: true
reporter: 'dot'
require: [
'coffee-script/register'
'./src/test_helper.coffee'
]
verbose: true
src: ['./src/**/*.test.coffee']
sass:
all:
options:
sourcemap: 'none'
files:
'./build/static/main.css': [ './build/imports.scss' ]
sass_globbing:
all:
files:
'./build/imports.scss': [
'./src/client/styles/main.scss'
'./src/client/site/**/*.scss'
]
uglify:
scripts:
options:
maxLineLen: 20
files: [
expand: true
cwd: './build/static'
src: '**/*.js'
dest: './build/static'
ext: '.ugly.js'
]
watch:
assets:
files: ['./assets/**/*']
tasks: ['copy:assets_build']
client_source:
files: ['./src/{client,common}/**/*.coffee']
tasks: ['browserify:internal']
server_source:
files: ['./src/{common,server}/**/*.coffee']
tasks: ['copy:server_source']
jade_pages:
files: ['./src/**/index.jade']
tasks: ['jade:pages']
jade_templates:
files: ['./src/**/!(index).jade']
tasks: ['jade:templates', 'browserify:internal']
sass:
files: ['./src/**/*.scss']
tasks: ['sass']
test:
files: ['./src/**/*.coffee', './src/**/*.js', './test/**/*.coffee']
tasks: ['script:clear', 'test']
# Compound Tasks ###################################################################################################
grunt.registerTask 'build', 'build the project to be run from a local server',
['jade', 'build:copy', 'build:css', 'browserify:external', 'browserify:internal']
grunt.registerTask 'build:copy', 'helper task for build',
['copy:assets_build', 'copy:env_build', 'copy:common_source', 'copy:server_source']
grunt.registerTask 'build:css', 'helper task for build',
['sass_globbing', 'sass']
grunt.registerTask 'default', 'rebuild the project from scratch and start a local HTTP server',
['clean', 'start']
grunt.registerTask 'deploy', 'deploy to both staging and production via CircleCI',
['deploy:staging', 'deploy:prod']
grunt.registerTask 'deploy:prod', 'deploy the project to production via CircleCI',
['script:deploy:prod']
grunt.registerTask 'deploy:staging', 'deploy the project to staging via CircleCI',
['script:deploy:staging']
grunt.registerTask 'dist', 'build the project to be run from Amazon S3',
['build', 'copy:build_to_dist', 'uglify', 'compress']
grunt.registerTask 'prepublish', 'build the project to be published to NPM as shared code',
['clean', 'coffee']
grunt.registerTask 'publish', 'publish the project to NPM',
['prepublish', 'script:publish', 'clean', 'build']
grunt.registerTask 'start', 'build the project and start a local HTTP server',
['build', 'script:start']
grunt.registerTask 'test', 'run unit tests',
['mochaTest']
grunt.registerTask 'upload:prod', 'upload the project to the production Amazon S3 environment',
['dist', 'script:s3_upload:prod']
grunt.registerTask 'upload:staging', 'upload the project the staging Amazon S3 environment',
['dist', 'script:s3_upload:staging']
grunt.registerTask 'use-local-deps', 'use local dependencies instead of NPM dependencies',
['script:use_local_deps']
# Code Tasks #######################################################################################################
grunt.registerTask 'browserify:external', "Bundle 3rd-party libraries used in the app", ->
grunt.file.mkdir './build/static'
done = this.async()
args = [].concat ("--require=#{lib}" for lib in EXTERNAL_LIBS), [
'--outfile=./build/static/external.js'
]
options = cmd:'browserify', args:args
grunt.util.spawn options, (error)->
console.log error if error?
done()
grunt.registerTask 'browserify:internal', "Bundle source files needed in the browser", ->
grunt.file.mkdir './build/static'
done = this.async()
libs = []
for lib in EXTERNAL_LIBS
parts = lib.split ':'
libs.push parts[parts.length-1]
args = [].concat ("--external=#{lib}" for lib in libs), [
'--extension=.coffee'
'--outfile=./build/static/internal.js'
'--transform=coffeeify'
'./src/client/client.coffee'
]
options = cmd:'browserify', args:args
grunt.util.spawn options, (error)->
console.log error if error?
done()
# Script Tasks #####################################################################################################
grunt.registerTask 'script:clear', "clear the current terminal buffer", ->
done = this.async()
grunt.util.spawn cmd:'clear', opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:deploy:prod', "deploy code by copying to the production branch", ->
done = this.async()
grunt.util.spawn cmd:'./scripts/deploy', args:['--prod'], opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:deploy:staging', "deploy code by copying to the staging branch", ->
done = this.async()
grunt.util.spawn cmd:'./scripts/deploy', args:['--staging'], opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:publish', 'publishes this package to NPM', ->
done = this.async()
grunt.util.spawn cmd:'./scripts/publish', opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:s3_upload:prod', 'uploads all static content to S3', ->
done = this.async()
grunt.util.spawn cmd:'./scripts/s3_upload', args:['--prod'], opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:s3_upload:staging', 'uploads all static content to S3', ->
done = this.async()
grunt.util.spawn cmd:'./scripts/s3_upload', args:['--staging'], opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:start', "start a local HTTP server on port 8080", ->
done = this.async()
grunt.util.spawn cmd:'./scripts/start', opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:use_local_deps', "use local dependencies instead of NPM dependencies", ->
done = this.async()
grunt.util.spawn cmd:'./scripts/use_local_deps', opts:{stdio:'inherit'}, (error)-> done(error)
# Command-Line Argument Processing #################################################################################
args = process.argv[..]
while args.length > 0
switch args[0]
when '--grep'
args.shift()
grunt.config.merge mochaTest:options:grep:args[0]
args.shift()