forked from browserquest/BrowserQuest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.coffee
142 lines (123 loc) · 3.69 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
###
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
###
# return a function that prints colored prefixed lines
printer = (prefix, color) ->
pre = (prefix + "> ")[color]
(data) ->
console.log(data.trimRight().split("\n").map((l) -> pre + l).join("\n"))
module.exports = (grunt) ->
# Project configuration.
grunt.initConfig
# Metadata.
pkg: grunt.file.readJSON("package.json")
#banner: "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " + "<%= grunt.template.today(\"yyyy-mm-dd\") %>\n" + "<%= pkg.homepage ? \"* \" + pkg.homepage + \"\\n\" : \"\" %>" + "* Copyright (c) <%= grunt.template.today(\"yyyy\") %> <%= pkg.author.name %>;" + " Licensed <%= _.pluck(pkg.licenses, \"type\").join(\", \") %> */\n"
coffeelint:
gruntfile: "Gruntfile.coffee"
client: ["client/**.coffee"]
server: ["server/**.coffee"]
common: ["common/**.coffee"]
test: ["test/**.coffee"]
options:
arrow_spacing:
level: "error"
no_trailing_whitespace:
level: "error"
max_line_length:
level: "ignore"
space_operators:
level: "warn"
mochaTest:
client:
options:
#reporter: "spec"
require: "coffee-script/register"
src: ["test/**/*.coffee"]
browserify:
client:
src: "client/main.coffee"
dest: "static/js/bundle.js"
#TODO: should replace with workerify?
mapworker:
src: "client/mapworker.coffee"
dest: "static/js/mapworker.js"
options:
transform: [
"coffeeify"
"brfs"
#"workerify"
]
extension: ".coffee"
debug: true
ignoreGlobals: true
shell:
redis:
command: "redis-server"
options:
async: true
stdout: printer("redis", "blue")
stderr: printer("redis", "red")
callback: (code, out, err, done) ->
switch code
when 0
done()
when 1
grunt.log.writeln(">> Redis is probably already running...".yellow)
done()
else
grunt.fail.warn("There was something wrong with redis.")
done(false)
server:
command: "coffee server/main.coffee"
options:
async: true
stdout: printer("server", "cyan")
stderr: printer("server", "red")
stopIfStarted: true
watch:
config:
files: [
"Gruntfile.coffee"
"package.json"
]
options:
reload: true
client:
files: [
"<%= coffeelint.client %>"
"<%= coffeelint.common %>"
]
#TODO: livereload maybe?
tasks: ["browserify"]
server:
files: [
"<%= coffeelint.server %>"
"<%= coffeelint.common %>"
]
tasks: ["shell:server"]
options:
spawn: false
# These plugins provide necessary tasks.
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-browserify"
grunt.loadNpmTasks "grunt-mocha-test"
grunt.loadNpmTasks "grunt-coffeelint"
grunt.loadNpmTasks "grunt-shell-spawn"
# Default task.
grunt.registerTask "test", ["mochaTest"]
grunt.registerTask "lint", ["coffeelint"]
grunt.registerTask "compile", ["browserify"]
grunt.registerTask "run", [
#TODO: option to disable running redis in development
"shell:redis"
"shell:server"
"watch"
]
grunt.registerTask "default", [
"lint"
"test"
"compile"
"run"
]