forked from RallyApps/app-catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
352 lines (308 loc) · 12.6 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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# ALM has trouble deploying wars, unlike Russia
module.exports = (grunt) ->
serverPort = grunt.option('port') || 8892
inlinePort = grunt.option('port') || 8893
path = require 'path'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-less'
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-jshint'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-nexus-artifact'
grunt.loadNpmTasks 'grunt-regex-check'
grunt.loadNpmTasks 'grunt-contrib-copy'
grunt.loadNpmTasks 'grunt-express'
grunt.loadNpmTasks 'grunt-contrib-jasmine'
grunt.loadNpmTasks 'grunt-webdriver-jasmine-runner'
grunt.loadNpmTasks 'grunt-text-replace'
grunt.loadTasks 'grunt/tasks'
grunt.registerTask 'default', ['build']
grunt.registerTask 'sanity', ['check', 'jshint']
grunt.registerTask 'css', ['less', 'copy:images', 'replace:imagepaths']
grunt.registerTask 'build', 'Builds the catalog', ['clean:build', 'nexus:deps', 'coffee', 'sanity', 'css', 'sencha:buildapps', 'assemble', 'copy:apphtml']
grunt.registerTask 'nexus:__createartifact__', 'Internal task to create and publish the nexus artifact', ['version', 'nexus:push:publish', 'clean:target']
grunt.registerTask 'nexus:deploy', 'Deploys to nexus', ['build', 'nexus:__createartifact__']
grunt.registerTask 'check', 'Run convention tests on all files', ['regex-check']
grunt.registerTask 'ci', 'Does a full build, runs tests and deploys to nexus', ['build', 'test:ci', 'nexus:__createartifact__']
grunt.registerTask 'test:__buildjasmineconf__', 'Internal task to build and alter the jasmine conf', ['jasmine:apps:build', 'replace:jasmine']
grunt.registerTask 'test:fast', 'Just configs and runs the tests. Does not do any compiling. grunt && grunt watch should be running.', ['test:__buildjasmineconf__', 'express:inline', 'webdriver_jasmine_runner:chrome']
grunt.registerTask 'test:conf', 'Fetches the deps, compiles coffee and css files, runs jshint and builds the jasmine test config', ['nexus:deps', 'clean:test', 'coffee', 'css', 'test:__buildjasmineconf__']
grunt.registerTask 'test:fastconf', 'Just builds the jasmine test config', ['test:__buildjasmineconf__']
grunt.registerTask 'test', 'Sets up and runs the tests in the default browser. Use --browser=<other> to run in a different browser, and --port=<port> for a different port.', ['sanity', 'test:conf', 'express:inline', 'webdriver_jasmine_runner:apps']
grunt.registerTask 'test:chrome', 'Sets up and runs the tests in Chrome', ['sanity', 'test:conf', 'express:inline', 'webdriver_jasmine_runner:chrome']
grunt.registerTask 'test:firefox', 'Sets up and runs the tests in Firefox', ['sanity', 'test:conf', 'express:inline', 'webdriver_jasmine_runner:firefox']
grunt.registerTask 'test:server', "Starts a Jasmine server at localhost:#{serverPort}, specify a different port with --port=<port>", ['express:server', 'express-keepalive']
grunt.registerTask 'test:ci', 'Runs the tests in both firefox and chrome', ['sanity', 'test:conf', 'express:inline', 'webdriver_jasmine_runner:chrome', 'webdriver_jasmine_runner:firefox']
_ = grunt.util._
spec = (grunt.option('spec') || grunt.option('jsspec') || '*').replace(/(Spec|Test)$/, '')
debug = grunt.option 'verbose' || false
version = grunt.option 'version' || 'dev'
maps = grunt.option 'maps' || false
appsdk_path = 'lib/sdk'
ext_path = 'lib/ext/4.2.2'
served_paths = [path.resolve(__dirname)]
if process.env.APPSDK_PATH
appsdk_path = path.join process.env.APPSDK_PATH, 'rui'
served_paths.unshift path.join(appsdk_path, '../..')
if spec != '*' and grunt.file.expand("test/**/#{spec}+(Spec|Test).+(js|coffee)").length == 0
grunt.warn 'The specified spec or jsspec option does not match any test.'
appFiles = 'src/apps/**/*.js'
specFiles = 'test/spec/**/*Spec.coffee'
cssFiles = 'src/apps/**/*.{css,less}'
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
buildVersion: version
clean:
build: ['build/', 'src/apps/**/*.html', 'temp/']
test: ['test/gen', '_SpecRunner.html', '.webdriver']
dependencies: ['lib/', 'bin/sencha/']
target: ['target/']
jshint:
options:
bitwise: true
curly: true
eqeqeq: true
forin: true
immed: true
latedef: true
noarg: true
noempty: true
nonew: true
trailing: true
browser: true
unused: 'vars'
es3: true
laxbreak: true
tasks:
files:
src: ['grunt/**/*.js']
apps:
files:
src: ['src/apps/**/*.js']
"regex-check":
x4:
src: [appFiles, specFiles, cssFiles]
options:
pattern: /x4-/g
almglobals:
src: [appFiles, specFiles]
options:
pattern: /Rally\.context|Rally\.getScope|Rally\.alm|Rally\.getContextPath/g
sandboxing:
src: [appFiles, specFiles]
options:
pattern: /Ext4\./g
consolelogs:
src: [appFiles, specFiles]
options:
pattern: /console\.log/g
express:
options:
bases: served_paths
server: path.resolve(__dirname, 'test', 'server.js')
debug: debug
server:
options:
port: serverPort
inline:
options:
port: inlinePort
webdriver_jasmine_runner:
options:
seleniumServerArgs: ['-Xmx256M']
testServerPort: inlinePort
apps: {}
chrome:
options:
browser: 'chrome'
firefox:
options:
browser: 'firefox'
jasmine:
apps:
options:
specs: [
"test/gen/**/#{spec}Spec.js"
]
helpers: [
"#{appsdk_path}/test/javascripts/helpers/**/*.js"
]
vendor: (->
if process.env.APPSDK_PATH?
vendorPaths = [
"lib/ext/4.2.2/ext-all-debug.js"
"#{appsdk_path}/builds/sdk-dependencies.js"
"#{appsdk_path}/src/Ext-more.js"
]
else
vendorPaths = ["#{appsdk_path}/builds/sdk.js"]
vendorPaths.concat [
"#{appsdk_path}/builds/lib/analytics/analytics-all.js"
"#{appsdk_path}/builds/lib/closure/closure-all.js"
# Enable Ext Loader
'test/support/ExtLoader.js'
# 3rd party libraries & customizations
"#{appsdk_path}/test/support/sinon/sinon-1.6.0.js"
"#{appsdk_path}/test/support/sinon/jasmine-sinon.js"
"#{appsdk_path}/test/support/sinon/rally-sinon-config.js"
# Setup
'lib/webdriver/webdriver.js'
"#{appsdk_path}/test/support/webdriver/error.js"
# Asserts
"#{appsdk_path}/test/support/helpers/asserts/rally-asserts.js"
"#{appsdk_path}/test/support/helpers/asserts/rally-custom-asserts.js"
# Mocks and helpers
"#{appsdk_path}/test/support/helpers/helpers.js"
"#{appsdk_path}/test/support/helpers/ext4-mocking.js"
"#{appsdk_path}/test/support/helpers/ext4-sinon.js"
"#{appsdk_path}/test/javascripts/support/helpers/**/*.js"
"#{appsdk_path}/test/javascripts/support/mock/**/*.js"
"#{appsdk_path}/test/support/data/types/**/*.js"
# 'btid' CSS classes for Testing
"#{appsdk_path}/browsertest/Test.js"
"#{appsdk_path}/browsertest/Overrides.js"
# Jasmine overrides
"#{appsdk_path}/test/support/jasmine/jasmine-html-overrides.js"
# Deft overrides
"#{appsdk_path}/test/support/deft/deft-overrides.js"
]
)()
styles: [
"#{appsdk_path}/test/support/jasmine/rally-jasmine.css"
"#{appsdk_path}/builds/rui/resources/css/rui-all.css"
"#{appsdk_path}/builds/rui/resources/css/rui-fonts.css"
"#{appsdk_path}/builds/lib/closure/closure-20130117-r2446.css"
"#{appsdk_path}/builds/rui/resources/css/lib-closure.css"
'build/resources/css/catalog-all.css'
]
host: "http://127.0.0.1:#{inlinePort}/"
replace:
jasmine:
src: ['_SpecRunner.html']
overwrite: true
replacements: [
from: '<script src=".grunt/grunt-contrib-jasmine/reporter.js"></script>'
to: '<!--script src=".grunt/grunt-contrib-jasmine/reporter.js"></script> removed because its slow and not used-->'
]
imagepaths:
src: ['build/resources/css/catalog-all.css']
overwrite: true
replacements: [
from: 'url(\''
to: 'url(\'../images/'
]
less:
options:
yuicompress: true
modifyVars:
prefix: 'x4-'
build:
files:
'build/resources/css/catalog-all.css': [cssFiles]
copy:
images:
files: [
{ expand: true, src: ['src/apps/**/*.png', 'src/apps/**/*.gif', 'src/apps/**/*.jpg'], flatten: true, dest: 'build/resources/images/' }
]
apphtml:
files: [
{ expand: true, src: ['apps/**/deploy/*.html'], cwd: 'src', dest: 'build/html/', rename: (dest, src) -> "#{dest}#{src.replace('deploy/', '').replace('apps/', '')}" }
{ expand: true, src: ['src/legacy/*.html', 'src/legacy/*.mp3'], dest: 'build/html/legacy/', flatten: true }
]
coffee:
test:
expand: true
cwd: 'test/spec'
src: ['**/*.coffee']
dest: 'test/gen'
ext: '.js'
options:
sourceMap: maps
watch:
test:
files: 'test/spec/**/*.coffee'
tasks: ['coffee:test']
options:
spawn: false
apps:
files: 'src/apps/**/*.js'
tasks: ['jshint:apps']
options:
spawn: false
tasks:
files: 'grunt/tasks/**/*.js'
tasks: ['jshint:tasks']
options:
spawn: false
styles:
files: cssFiles
tasks: ['css']
nexus:
options:
url: 'http://alm-build.f4tech.com:8080'
repository: 'thirdparty'
deps:
options:
fetch: (->
js_dependencies = grunt.file.readJSON 'js_dependencies.json'
sdk_dependency = _.filter(js_dependencies, (dep) -> dep.id.indexOf('com.rallydev.js:appsdk-src') is 0)[0]
if sdk_dependency and process.env.APPSDK_SRC_VERSION
sdk_dependency.id = sdk_dependency.id.replace(/:[^:]+$/, ":#{process.env.APPSDK_SRC_VERSION}")
js_dependencies
)()
push:
files: [
{ expand: true, src: ['build/**/*'] }
{ expand: true, src: ['src/apps/**/*'] }
]
options:
publish: [{ id: 'com.rallydev.js:app-catalog:tgz', version: '<%= buildVersion %>', path: 'target/' }]
sencha:
options:
cmd: "./bin/sencha/#{if process.platform is 'darwin' then 'mac' else 'linux'}/sencha"
buildapps:
options:
args: [
if debug then '-d' else ''
"-s #{ext_path}"
'compile'
"-classpath=#{appsdk_path}/builds/sdk-dependencies-debug.js,#{appsdk_path}/src,src/apps"
'exclude -all and'
'include -file src/apps and'
'concat build/catalog-all-debug.js and'
'concat -compress build/catalog-all.js'
]
appmanifest:
options:
args:[
"-s #{ext_path}"
'compile'
"-classpath=#{appsdk_path}/builds/sdk-dependencies-debug.js,#{appsdk_path}/src,src/apps"
'exclude -all and'
"union -r -file #{grunt.option('app')} and"
"exclude -file #{appsdk_path}/builds/sdk-dependencies-debug.js and"
"exclude -file #{appsdk_path}/src and"
'exclude -namespace Ext and'
"metadata -f -t {0} -o temp/#{grunt.option('app')}/appManifest -json -b #{grunt.option('app')}"
]
assemble:
options:
apps: 'src/apps/**/config.json'
# Only recompile changed coffee files
changedFiles = {}
onChange = _.debounce ->
specFiles = []
taskFiles = []
appsFiles = []
_.each changedFiles, (action, filepath) ->
specFiles.push(filepath) if _.contains(filepath, 'spec')
taskFiles.push(filepath) if _.contains(filepath, 'tasks')
appsFiles.push(filepath) if _.contains(filepath, 'apps')
grunt.config 'coffee.test.src', _.map specFiles, (path) -> path.replace('test/spec/', '')
grunt.config 'jshint.tasks.files.src', taskFiles
grunt.config 'jshint.apps.files.src', appsFiles
changedFiles = {}
, 200
grunt.event.on 'watch', (action, filepath) ->
changedFiles[filepath] = action
onChange()