-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.coffee
196 lines (168 loc) · 4.96 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
module.exports = (grunt) ->
# Output
libName = "are.js"
productionName = "are-prod.js"
productionNameMin = "are-prod.min.js"
productionNameFull = "are-prod-full.js"
productionNameFullMin = "are-prod-full.min.js"
# Directories
buildDir = "build"
libDir = "lib"
testDir = "test"
devDir = "dev"
production = "#{buildDir}/#{productionName}"
productionMin = "#{buildDir}/#{productionNameMin}"
productionFull = "#{buildDir}/#{productionNameFull}"
productionFullMin = "#{buildDir}/#{productionNameFullMin}"
productionConcatFull = [
"#{devDir}/components/underscore/underscore.js"
"#{devDir}/components/chipmunk/cp.min.js"
"#{devDir}/js/EWGL_math.js"
"#{devDir}/js/inkyEWGL.js"
"#{devDir}/are.js"
]
# Intermediate vars
__areOut = {}
__areOut["#{buildDir}/are-concat.coffee"] = [ "#{libDir}/are.coffee" ]
__areOut["#{devDir}/are-concat.coffee"] = [ "#{libDir}/are.coffee" ]
__coffeeConcatFiles = {}
# Build concat output
__coffeeConcatFiles["#{buildDir}/#{libName}"] = "#{buildDir}/are-concat.coffee";
# Dev concat output, used for browser testing
__coffeeConcatFiles["#{devDir}/#{libName}"] = "#{buildDir}/are-concat.coffee";
# 1 to 1 compiled files, for unit tests
__coffeeFiles = [
"#{libDir}/*.coffee"
"#{libDir}/**/*.coffee"
]
__testFiles = {}
__testFiles["#{buildDir}/test/spec.js"] = [ "#{buildDir}/test/spec.coffee" ]
__testOut = {}
__testOut["#{buildDir}/test/spec.coffee"] = ["#{testDir}/tests.coffee"]
_uglify = {}
_uglify[productionMin] = "#{buildDir}/#{libName}"
_uglify[productionFullMin] = productionFull
grunt.initConfig
pkg: grunt.file.readJSON "package.json"
coffee:
concat:
options:
sourceMap: true
bare: true
cwd: buildDir
files: __coffeeConcatFiles
lib:
expand: true
options:
bare: true
src: __coffeeFiles
dest: buildDir
ext: ".js"
libDev:
expand: true
options:
bare: true
src: __coffeeFiles
dest: devDir
ext: ".js"
tests:
expand: true
options:
bare: true
files: __testFiles
coffeelint:
app: __coffeeFiles
concat_in_order:
lib:
files: __areOut
options:
extractRequired: (path, content) ->
workingDir = path.split "/"
workingDir.pop()
workingDir = workingDir.join().replace /,/g, "/"
deps = @getMatches /\#\s\@depend\s(.*\.coffee)/g, content
deps.forEach (dep, i) ->
deps[i] = "#{workingDir}/#{dep}"
return deps
extractDeclared: (path) -> [path]
onlyConcatRequiredFiles: true
tests:
files: __testOut
options:
extractRequired: (path, content) ->
workingDir = path.split "/"
workingDir.pop()
workingDir = workingDir.join().replace /,/g, "/"
deps = @getMatches /\#\s\@depend\s(.*\.coffee)/g, content
deps.forEach (dep, i) ->
deps[i] = "#{workingDir}/#{dep}"
return deps
extractDeclared: (path) -> [path]
onlyConcatRequiredFiles: true
watch:
coffeescript:
files: [
"#{libDir}/**/*.coffee"
"#{libDir}/*.coffee"
"#{testDir}/**/*.coffee"
"#{testDir}/*.coffee"
]
tasks: ["clean", "concat_in_order", "coffee", "mocha", "concat", "uglify"]
connect:
server:
options:
port: 8082
base: "./dev"
mocha:
all:
src: [ "#{buildDir}/#{testDir}/test.html" ]
options:
bail: false
log: true
reporter: "Nyan"
run: true
copy:
test_page:
files: [
expand: true
cwd: "#{testDir}/env"
src: [ "**" ]
dest: "#{buildDir}/#{testDir}"
]
clean: [
buildDir
]
# Production concat
concat:
options:
stripBanners: true
distFull:
src: productionConcatFull
dest: productionFull
uglify:
options:
preserveComments: false
banner: "/* Copyright © 2013 Spectrum IT Solutions Gmbh - All Rights Reserved */\n"
production:
files: _uglify
grunt.loadNpmTasks "grunt-coffeelint"
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-contrib-connect"
grunt.loadNpmTasks "grunt-contrib-clean"
grunt.loadNpmTasks "grunt-concat-in-order"
grunt.loadNpmTasks "grunt-contrib-copy"
grunt.loadNpmTasks "grunt-contrib-concat"
grunt.loadNpmTasks "grunt-contrib-uglify"
grunt.loadNpmTasks "grunt-mocha"
grunt.registerTask "default", ["concat_in_order", "coffee", "mocha"]
grunt.registerTask "full", [
"clean"
"copy:test_page"
"concat_in_order"
"coffee"
"mocha"
"concat"
"uglify"
]
grunt.registerTask "dev", ["connect", "copy:test_page", "watch"]