-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.coffee
185 lines (162 loc) · 5.36 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
#global module:false
karma = require 'karma'
module.exports = (grunt) ->
grunt.loadNpmTasks "grunt-contrib-uglify"
grunt.loadNpmTasks "grunt-contrib-concat"
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-contrib-jshint"
grunt.loadNpmTasks "grunt-contrib-coffee"
# Project configuration.
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
meta:
# Build the JS banner based on pkg file data
banner: do ->
banner = "/* <%= pkg.name %> - v<%= pkg.version %> - <%= pkg.homepage %>\n"
banner += "* Copyright (c) <%= grunt.template.today('yyyy') %> <%= pkg.author %>. All rights reserved.\n"
banner += "* Licensed <%= _.pluck(pkg.licenses, 'type')[0] %> - <%= _.pluck(pkg.licenses, 'url')[0] %> */\n"
banner
paths:
# Ref common paths so we can use built-in lodash templating.
express: "./express"
routes : "./routes"
coffee : "./public/coffeescripts"
tmp : "./tmp"
js : "./public/javascripts"
concat:
# Concat app into temp dir. So it can be wrapped in a single
# SEAF, since coffee-contrib doesn't have this option.
app:
src: [
"<%= paths.coffee %>/Stor.coffee"
"<%= paths.coffee %>/app.coffee"
"<%= paths.coffee %>/controllers/MainAppCtrl.coffee"
"<%= paths.coffee %>/directives/fadeShow.coffee"
"<%= paths.coffee %>/directives/focusBlur.coffee"
"<%= paths.coffee %>/filters/startFrom.coffee"
]
dest: "<%= paths.tmp %>/app.coffee"
# Build to add banners to JS
build:
options:
banner: "<%= meta.banner %>"
files:
"<%= paths.js %>/app.js": [ "<%= paths.js %>/app.js" ]
"<%= paths.js %>/app.min.js": [ "<%= paths.js %>/app.min.js" ]
coffee:
# Note: concat needs to be run in order to gen tmp directory and file
# for app.
compile:
options:
bare: false
files:
"<%= paths.routes %>/index.js": "<%= paths.routes %>/index.coffee"
"<%= paths.js %>/app.js": "<%= paths.tmp %>/app.coffee"
"<%= paths.express %>/page-info.js": "<%= paths.express %>/page-info.coffee"
"server.js": "<%= paths.express %>/server.coffee"
watch:
coffee:
files: [
"<%= paths.coffee %>/**/*.coffee"
"<%= paths.routes %>/index.coffee"
"<%= paths.express %>/server.coffee"
"<%= paths.express %>/page-info.coffee"
]
tasks: [ "concat:app", "coffee" ]
js:
files: [ "<%= paths.js %>/app.js" ]
tasks: [ "jshint", "uglify", "test" ]
tests:
files: [ "./test/**/*.spec.coffee" ]
tasks: [ "test" ]
uglify:
app:
options:
# Default compress options. Listed for reference.
compress:
conditionals : true
comparisons : true
properties : true
hoist_funs : true
hoist_vars : false
sequences : true
if_return : true
join_vars : true
dead_code : true
evaluate : true
booleans : true
warnings : true
cascade : true
unsafe : true
unused : true
loops : true
mangle:
except: [
"Stor"
"angular"
"amplify"
"jQuery"
"$"
"_"
]
files:
"<%= paths.js %>/app.min.js": [
"<%= paths.js %>/app.js"
"<banner:meta.banner>"
]
jshint:
options:
"sub" : true
"boss" : true
"devel" : true
"curly" : false
"immed" : true
"noarg" : true
"undef" : true
"shadow" : true
"newcap" : false
"eqnull" : true
"eqeqeq" : true
"browser" : true
"latedef" : true
"laxcomma" : true
"laxbreak" : true
"globals":
"angular" : true
"amplify" : true
"jQuery" : true
"$" : true
"_" : true
all: ["<%= paths.js %>/app.js"]
# Default task.
grunt.registerTask "default", [
"concat:app"
"coffee"
"jshint"
"uglify"
"concat:build"
"test"
]
grunt.registerTask "testserver", "start karma server", ->
#Mark the task as async but never call done, so the server stays up
done = @async()
karma.server.start configFile: "test/karma.conf.js"
# Invoke tests on karma server.
grunt.registerTask "test", "run tests (make sure server task is run first)", ->
done = @async()
grunt.util.spawn
cmd: (if process.platform is "win32" then "karma.cmd" else "karma")
args: ["run"]
, (error, result, code) ->
if error
grunt.warn
"Make sure the karma server is online: run `grunt server`.\n" +
"Also make sure you have a browser open to http://localhost:8080/.\n" +
error.stdout + error.stderr
#the karma runner somehow modifies the files if it errors(??).
#this causes grunt's watch task to re-fire itself constantly,
#unless we wait for a sec
setTimeout done, 1000
else
grunt.log.write result.stdout
done()