forked from swarmsim/swarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
1050 lines (998 loc) · 31.7 KB
/
Gruntfile.js
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Generated on 2014-08-02 using generator-angular 0.9.2
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
// https://stackoverflow.com/questions/31846665/grunt-contrib-connect-undefined-is-not-a-function-for-connect-static
var serveStatic = require('serve-static');
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
//var path = require('path');
//var swPrecache = require('sw-precache');
// Configurable paths for the application
var appConfig = {
app: require('./bower.json').appPath || 'app',
dist: 'dist'
};
var dropboxAppKey = function(configuredKey) {
var KEYS = {
shoelaceDev:'6hagxaf8041upxz',
dev:'q5b8awxy8r3qjus', //account [email protected]
prod:'n2mff9wz6bv0f91' //account [email protected]
};
// `--dropboxAppKey=x` can always override this file's configuration
var key = grunt.option('dropboxAppKey') || configuredKey;
// key can either be a named key configured above (`--dropboxAppKey=dev`) or the key itself (`--dropboxAppKey=q5b8awxy8r3qjus`)
return KEYS[key] || key;
};
var ngconstant = {
options: {
dest: '.tmp/scripts/env.js',
wrap: '"use strict";\n\n{%= __ngModule %}',
name: 'swarmEnv',
constants: {
version: grunt.file.readJSON('package.json').version
},
space: ' '
},
test: {
constants: {
env: {
name: 'test',
isDebugEnabled: true,
isDebugLogged: false,
httpsAllowInsecure: true,
showSkipped: false,
spreadsheetKey: 'v0.2',
saveId: '0',
dropboxAppKey: dropboxAppKey('dev'),
isDropboxEnabled: true,
saveServerUrl: grunt.option('saveServerUrl'),
isKongregateSyncEnabled: true,
autopushIntervalMs: 1000 * 60 * 9999,
googleApiKey: 'AIzaSyArP8wzscVTyD4wBWZrhPnGWwj7W7ROaSI',
isAppcacheEnabled: true,
playfabTitleId: 'F810',
sentryDSN: null,
sentrySampleRate: 0,
isServerBackendEnabled: true,
isServerFrontendEnabled: false,
isPaypalSandbox: true,
gaTrackingID: null
}
}
},
dev: {
constants: {
env: {
name: 'dev',
isDebugEnabled: true,
isDebugLogged: true,
httpsAllowInsecure: true,
showSkipped: true,
spreadsheetKey: 'v0.2',
saveId: 'v0.2',
dropboxAppKey: dropboxAppKey('dev'),
isDropboxEnabled: true,
saveServerUrl: grunt.option('saveServerUrl'),
isKongregateSyncEnabled: true,
autopushIntervalMs: 1000 * 15,
googleApiKey: 'AIzaSyArP8wzscVTyD4wBWZrhPnGWwj7W7ROaSI',
isAppcacheEnabled: true,
sentryDSN: 'https://[email protected]/39317',
sentrySampleRate: 1,
// https://developer.playfab.com/en-us/F810/dashboard
playfabTitleId: 'F810',
// Abandoned server-side account variables.
isServerBackendEnabled: false,
isServerFrontendEnabled: false,
isPaypalSandbox: true,
gaTrackingID: 'UA-53523462-3'
}
}
},
prod: {
constants: {
env: {
name: 'prod',
isDebugEnabled: false,
isDebugLogged: false,
httpsAllowInsecure: false,
//gaTrackingID: 'UA-53523462-2'
showSkipped: false,
spreadsheetKey: 'v0.2',
saveId: 'v0.2',
dropboxAppKey: dropboxAppKey('prod'),
isDropboxEnabled: true,
saveServerUrl: 'https://api.swarmsim.com',
isKongregateSyncEnabled: true,
autopushIntervalMs: 1000 * 60 * 15,
googleApiKey: 'AIzaSyCS8nqXFvhdr0AR-ox-9n_wKP2std_fHHs',
// https://developer.playfab.com/en-us/7487/dashboard
playfabTitleId: '7487',
isAppcacheEnabled: false,
sentryDSN: 'https://[email protected]/39331',
sentrySampleRate: 0.001,
isServerBackendEnabled: false,
isServerFrontendEnabled: false,
isPaypalSandbox: false,
gaTrackingID: 'UA-53523462-1'
}
}
},
};
ngconstant.preprod = JSON.parse(JSON.stringify(ngconstant.prod));
ngconstant.preprod.constants.env.saveServerUrl = 'https://api-preprod.swarmsim.com';
// Define the configuration for all the tasks
grunt.initConfig({
// https://www.npmjs.org/package/grunt-gh-pages
'gh-pages': {
// no-args/default is staging deployment. 'grunt gh-pages:prod' for production.
options: {
base: 'dist'
},
src: ['**'],
default_: {
// default options
options: {},
src: ['**']
},
staging: {
options: {
branch: 'master',
repo: '[email protected]:swarmsim-staging/swarmsim-staging.github.io.git'
},
src: ['**']
},
preprod: {
options: {
user: {
name: grunt.option('user.name') || null,
email: grunt.option('user.email') || null,
},
branch: 'master',
repo: '[email protected]:swarmsim-preprod/swarmsim-preprod.github.io.git'
},
src: ['**']
},
publictest: {
options: {
branch: 'master',
repo: '[email protected]:swarmsim-publictest/swarmsim-publictest.github.io.git'
},
src: ['**']
},
prodDotcom: {
options: {
branch: 'master',
repo: '[email protected]:swarmsim-dotcom/swarmsim-dotcom.github.io.git'
},
src: ['**']
},
prodCoffee: {
options: {
branch: 'master',
repo: '[email protected]:swarmsim-coffee/swarmsim-coffee.github.io.git'
},
src: ['**']
},
prodGithubio: {
options: {
branch: 'master',
repo: '[email protected]:swarmsim/swarmsim.github.io.git'
},
src: ['**']
}
},
// http://hounddog.github.io/blog/using-environment-configuration-with-grunt/
ngconstant: ngconstant,
preloadSpreadsheet: {
'v0.2': 'https://docs.google.com/spreadsheets/d/1ughCy983eK-SPIcDYPsjOitVZzY10WdI2MGGrmxzxF4/pubhtml',
},
// https://github.com/GoogleChrome/sw-precache/blob/master/demo/Gruntfile.js
swPrecache: {
dist: {
handleFetch: true,
//src: '<%= yeoman.app %>',
src: '<%= yeoman.dist %>',
dist: '<%= yeoman.dist %>',
},
dev: {
handleFetch: false,
//src: '<%= yeoman.app %>',
src: '.tmp',
dist: '.tmp',
},
},
manifest: {
options: {
basePath: '<%= yeoman.dist %>',
cache: [],
network: ['*', 'http://*', 'https://*',],
//fallback: ['/ /offline.html'],
exclude: ['js/jquery.min.js'],
preferOnline: true,
verbose: true,
timestamp: true,
hash: true,
master: ['index.html'],
process: function(path) {
return path.substring('app/'.length);
}
},
prod: {
src: [
'views/*.html',
'scripts/*.js',
'styles/*.css'
],
dest: '<%= yeoman.dist %>/manifest.appcache'
},
dev: {
options:{
basePath: '<%= yeoman.app %>',
},
src: [
'views/*.html',
'scripts/*.js',
'styles/*.css'
],
dest: '.tmp/manifest.appcache'
}
},
// added based on https://github.com/yeoman/generator-angular/pull/277/files
ngtemplates: {
dist: {
options: {
module: 'swarmApp',
htmlmin: '<%= htmlmin.dist.options %>',
usemin: '<%= yeoman.dist %>/scripts/scripts.js'
},
cwd: '<%= yeoman.app %>',
// '**' not grabbing subdirs for some reason, do it manually
src: ['views/**.html', 'views/playfab/**.html', 'views/desc/unit/**.html', 'views/desc/upgrade/**.html'],
dest: '.tmp/scripts/templateCache.js'
},
// no templates for dev, so they reload properly when changed
dev: {
cwd: 'app',
src: '/dev/null',
dest: '.tmp/scripts/app.templates.js',
},
options: {
module: 'swarmApp',
htmlmin: '<%= htmlmin.dist.options %>'
}
},
// Project settings
yeoman: appConfig,
// Watches files for changes and runs tasks based on the changed files
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},
coffee: {
files: ['<%= yeoman.app %>/scripts/{,*/}*.{coffee,litcoffee,coffee.md}'],
//tasks: ['newer:coffee:dist', 'newer:coffee:test', 'karma:unit']
tasks: ['coffeelint','newer:coffee:dist']
},
coffeeTest: {
files: ['test/spec/{,*/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffeelint','newer:coffee:test', 'karma:unit']
},
integrationTest: {
files: ['test/integration/{,*/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffeelint','newer:coffee:integrationTest', 'karma:integration']
},
compass: {
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
},
gruntfile: {
files: ['Gruntfile.js']
},
manifest: {
files: [ '<%= yeoman.app %>/{,*/}*.html',],
tasks: [ 'manifest', 'swPrecache' ]
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'.tmp/styles/{,*/}*.css',
'.tmp/scripts/{,*/}*.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
// The actual grunt server settings
connect: {
options: {
port: process.env.PORT || 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '0.0.0.0',
//livereload: 55728 // ngrok won't bind remote ports below 50000
livereload: 35728
},
livereload: {
options: {
//open: true,
middleware: function (connect) {
return [
serveStatic('.tmp'),
connect().use(
'/bower_components',
serveStatic('./bower_components')
),
serveStatic(appConfig.app)
];
}
}
},
test: {
options: {
port: 9001,
middleware: function (connect) {
return [
serveStatic('.tmp'),
serveStatic('test'),
connect().use(
'/bower_components',
serveStatic('./bower_components')
),
serveStatic(appConfig.app)
];
}
}
},
dist: {
options: {
//open: true,
base: '<%= yeoman.dist %>'
}
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: {
src: [
'Gruntfile.js'
]
}
},
coffeelint: {
options: {
configFile: 'coffeelint.json'
},
app: ['<%= yeoman.app %>/**/*.coffee']
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/{,*/}*',
'!<%= yeoman.dist %>/.git*'
]
}]
},
spreadsheetpreload: 'app/scripts/spreadsheetpreload',
server: '.tmp'
},
// Add vendor prefixed styles
autoprefixer: {
options: {
browsers: ['last 1 version']
},
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
}
},
// Automatically inject Bower components into the app
wiredep: {
options: {
//cwd: '<%= yeoman.app %>'
},
app: {
src: ['<%= yeoman.app %>/index.html'],
overrides: {
'lz-string': {
main: 'libs/lz-string.js'
},
'konami-js': {
main: 'konami.js'
},
'mathjs': {
// default math.min.js breaks uglify? https://github.com/gruntjs/grunt-contrib-uglify/issues/233
main: 'dist/math.js'
},
'decimal.js': {
main: 'decimal.js'
},
'playfab-sdk': {
main: 'PlayFabSdk/src/PlayFab/PlayFabClientApi.js'
},
},
ignorePath: /\.\.\//
},
sass: {
src: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
ignorePath: /(\.\.\/){1,2}bower_components\//
}
},
// Compiles CoffeeScript to JavaScript
coffee: {
options: {
sourceMap: true,
sourceRoot: ''
},
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/scripts',
src: '{,*/}*.coffee',
dest: '.tmp/scripts',
ext: '.js'
}]
},
test: {
files: [{
expand: true,
cwd: 'test/spec',
src: '{,*/}*.coffee',
dest: '.tmp/spec',
ext: '.js'
}]
},
integrationTest: {
files: [{
expand: true,
cwd: 'test/integration',
src: '{,*/}*.coffee',
dest: '.tmp/integration',
ext: '.js'
}]
}
},
// Compiles Sass to CSS and generates necessary files if requested
compass: {
options: {
sassDir: '<%= yeoman.app %>/styles',
cssDir: '.tmp/styles',
generatedImagesDir: '.tmp/images/generated',
imagesDir: '<%= yeoman.app %>/images',
javascriptsDir: '<%= yeoman.app %>/scripts',
fontsDir: '<%= yeoman.app %>/styles/fonts',
importPath: './bower_components',
httpImagesPath: '/images',
httpGeneratedImagesPath: '/images/generated',
httpFontsPath: '/styles/fonts',
relativeAssets: false,
assetCacheBuster: false,
raw: 'Sass::Script::Number.precision = 10\n'
},
dist: {
options: {
generatedImagesDir: '<%= yeoman.dist %>/images/generated'
}
},
server: {
options: {
debugInfo: true
}
}
},
// Renames files for browser caching purposes
filerev: {
dist: {
src: [
'<%= yeoman.dist %>/scripts/{,*/}*.js',
'<%= yeoman.dist %>/styles/{,*/}*.css',
'<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
'<%= yeoman.dist %>/styles/fonts/*'
]
}
},
// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
html: '<%= yeoman.app %>/index.html',
options: {
dest: '<%= yeoman.dist %>',
flow: {
html: {
steps: {
js: ['concat', 'uglifyjs'],
css: ['cssmin']
},
post: {}
}
}
}
},
// Performs rewrites based on filerev and the useminPrepare configuration
// js/pattern changes based on https://github.com/yeoman/generator-angular/pull/277/files
usemin: {
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
manifest: ['<%= yeoman.dist %>/manifest.appcache'],
swPrecache: ['<%= yeoman.dist %>/service-worker.js'],
js: ['<%= yeoman.dist %>/scripts/{,*/}*.js'],
options: {
assetsDirs: ['<%= yeoman.dist %>','<%= yeoman.dist %>/images'],
patterns: {
js: [[/(images\/[^''""]*\.(png|jpg|jpeg|gif|webp|svg))/g, 'Replacing references to images']],
manifest: [
//[/(scripts/vendor.js)/, 'Replacing reference to vendor.js'],
//[/(scripts/main.js)/, 'Replacing reference to main.js'],
//[/(styles/vendor.css)/, 'Replacing reference to vendor.css'],
//[/(styles/main.css)/, 'Replacing reference to main.css']
]
}
}
},
// The following *-min tasks will produce minified files in the dist folder
// By default, your `index.html`'s <!-- Usemin block --> will take care of
// minification. These next options are pre-configured if you do not wish
// to use the Usemin blocks.
// cssmin: {
// dist: {
// files: {
// '<%= yeoman.dist %>/styles/main.css': [
// '.tmp/styles/{,*/}*.css'
// ]
// }
// }
// },
// uglify: {
// dist: {
// files: {
// '<%= yeoman.dist %>/scripts/scripts.js': [
// '<%= yeoman.dist %>/scripts/scripts.js'
// ]
// }
// }
// },
// concat: {
// dist: {}
// },
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.{png,jpg,jpeg,gif}',
dest: '<%= yeoman.dist %>/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.svg',
dest: '<%= yeoman.dist %>/images'
}]
}
},
htmlmin: {
dist: {
options: {
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeCommentsFromCDATA: true,
removeOptionalTags: true
},
files: [{
expand: true,
cwd: '<%= yeoman.dist %>',
src: ['*.html', 'views/{,*/}*.html'],
dest: '<%= yeoman.dist %>'
}]
}
},
// ngmin tries to make the code safe for minification automatically by
// using the Angular long form for dependency injection. It doesn't work on
// things like resolve or inject so those have to be done manually.
ngmin: {
dist: {
files: [{
expand: true,
cwd: '.tmp/concat/scripts',
src: '*.js',
dest: '.tmp/concat/scripts'
}]
}
},
// Replace Google CDN references
cdnify: {
dist: {
html: ['<%= yeoman.dist %>/*.html']
}
},
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'static/**/*',
'repair/**/*',
'releasewatch/**/*',
'*.{ico,png,txt}',
'.htaccess',
'*.html',
'*.svg',
'views/{,*/}*.html',//'views/desc/unit/{,*/}*.html','views/desc/upgrade/{,*/}*.html',
'images/{,*/}*.{webp}',
'fonts/*',
'storage.swf',
'service-worker.js', // this is the failsafe clear-cache-and-quit service worker. swPrecache works now, so no need for this. OH WAIT yes there is because it's still broken, ugh.
'manifest.json',
]
}, {
expand: true,
cwd: '.tmp/images',
dest: '<%= yeoman.dist %>/images',
src: ['generated/*']
}, {
//for font-awesome: http://stackoverflow.com/questions/21310382/fontawesome-is-not-working-when-project-is-built-with-grunt
expand: true,
dot: true,
cwd: 'bower_components/font-awesome',
src: ['fonts/*.*'],
dest: '<%= yeoman.dist %>'
}, {
expand: true,
cwd: '.',
src: [
'archive/**/*',
'bower_components/bootstrap-sass/assets/fonts/bootstrap/*',
'bower_components/font-awesome/fonts/*',
'bower_components/bootswatch/fonts/*',
'bower_components/bootswatch/*/bootstrap.min.css',
'bower_components/bootswatch/*/bootstrap.min.css',
'bower_components/bootswatch/*/thumbnail.png',
'bower_components/ravenjs/dist/raven.min.js'
],
dest: '<%= yeoman.dist %>'
}]
},
phonegap: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: '*.xml'
}, {
dest: '<%= yeoman.dist %>/icon.png',
src: '<%= yeoman.app %>/images/swarmsim-icon.png'
}, {
dest: '<%= yeoman.dist %>/splash.png',
src: '<%= yeoman.app %>/images/swarmsim-icon.png'
}]
},
styles: {
expand: true,
cwd: '<%= yeoman.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
// Run some tasks in parallel to speed up the build process
concurrent: {
server: [
'coffee:dist',
'compass:server'
],
test: [
'coffee',
'compass'
],
dist: [
'coffee',
'compass:dist',
'imagemin',
'svgmin'
]
},
// Test settings
karma: {
// singleRun is needed or else livereload stops working. boo.
unit: {
configFile: 'test/karma-unit.conf.coffee',
singleRun: true
},
integration: {
configFile: 'test/karma-integration.conf.coffee',
singleRun: true
},
unitCi: {
configFile: 'test/karma-unit.conf.coffee',
singleRun: true
},
integrationCi: {
configFile: 'test/karma-integration.conf.coffee',
singleRun: true
}
},
githash: {
main: {}
},
});
// Kongregate mtx changed? https://docs.google.com/spreadsheets/d/1ughCy983eK-SPIcDYPsjOitVZzY10WdI2MGGrmxzxF4/export?gid=1404187062&format=csv
grunt.registerMultiTask('preloadSpreadsheet', 'Update spreadsheet data', function () {
var Tabletop = require('tabletop');
var stringify = require('json-stable-stringify');
var _ = require('lodash');
var directory = 'app/scripts/spreadsheetpreload/';
var url = this.data;
var key = this.target;
var done = this.async();
Tabletop.init({
key: url,
parseNumbers: true,
debug: true,
callback: function (data) {
data = _.pick(data, ['unittypes', 'upgrades', 'achievements', 'tutorial', 'mtx', 'mtx.playfabUpload']);
data = _.mapValues(data, function(sheet) {
return _.omit(sheet, ['raw']);
});
//var text = JSON.stringify(data, null, 2);
// built-in stringify puts sheets in a random order. Use a consistent
// order with json-stable-stringify for cleaner diffs.
for (var sheetname in data) {
data[sheetname] = _.pick(data[sheetname], ['column_names', 'elements', 'name']);
}
// special case playfab uploads. Two files: main and free (zero-cost, for testing)
var playfab = {
CatalogVersion: 'main',
Catalog: data['mtx.playfabUpload'].elements,
};
delete data['mtx.playfabUpload'];
for (var i=0; i < playfab.Catalog.length; i++) {
var row = playfab.Catalog[i];
// this part's messy
//row.VirtualCurrencyPrices = {RM: 0}
row.VirtualCurrencyPrices = {RM: row['VirtualCurrencyPrices.RM']};
delete row['VirtualCurrencyPrices.RM'];
}
var playfabFile = directory + key + '.playfabUpload.main.json';
grunt.file.write(playfabFile, stringify(playfab, {space:' '}));
console.log('Wrote '+playfabFile);
playfab.CatalogVersion = 'free';
for (var j=0; j < playfab.Catalog.length; j++) {
playfab.Catalog[j].DisplayName += ' (free)';
playfab.Catalog[j].VirtualCurrencyPrices.RM = 0;
}
playfabFile = directory + key + '.playfabUpload.free.json';
grunt.file.write(playfabFile, stringify(playfab, {space:' '}));
console.log('Wrote '+playfabFile);
// end playfab; back to everything else
var text = stringify(data, {space:' '});
text = '// This is an automatically generated file! Do not edit!\n// Edit the source at: '+url+'\n// Generated by Gruntfile.js:preloadSpreadsheet\n// key: '+key+'\n\'use strict\';\n\ntry {\n angular.module(\'swarmSpreadsheetPreload\');\n //console.log(\'second'+key+'\');\n}\ncatch (e) {\n // module not yet initialized by some other module, we\'re the first\n angular.module(\'swarmSpreadsheetPreload\', []);\n //console.log(\'first'+key+'\');\n}\nangular.module(\'swarmSpreadsheetPreload\').value(\'spreadsheetPreload-'+key+'\', '+text+');';
var filename = directory + key + '.js';
grunt.file.write(filename, text);
console.log('Wrote '+filename);
done();
}
});
});
grunt.registerTask('writeVersionJson', 'write version info to a json file', ['githash', '_writeVersionJson', 'preloadSpreadsheet']);
grunt.registerTask('_writeVersionJson', 'write version info to a json file', function() {
var version = grunt.file.readJSON('package.json').version;
var data = {
version: version,
updated: new Date(),
githash: grunt.config('githash.main'),
};
// Workaround for screwy service-worker update issues. The old updater detects a version change and is now refreshing before service-worker reloads and clears the cache, reviving our old friend the infinite-refresh bug. Workaround: fake out the version so we don't detect an update right away.
if (version === '1.1.5') {
data.version = '1.1.4';
}
var text = JSON.stringify(data, undefined, 2);
grunt.file.write('.tmp/version.json', text);
grunt.file.write('dist/version.json', text);
});
grunt.registerTask('buildCname', 'build swarmsim.com cname file', function () {
grunt.file.write('dist/CNAME', 'www.swarmsim.com');
});
grunt.registerTask('coffeeCname', 'build coffee.swarmsim.com cname file', function () {
grunt.file.write('dist/CNAME', 'coffee.swarmsim.com');
});
grunt.registerTask('stagingCname', 'build staging.swarmsim.com cname file', function () {
grunt.file.write('dist/CNAME', 'staging.swarmsim.com');
});
grunt.registerTask('preprodCname', 'build preprod.swarmsim.com cname file', function () {
grunt.file.write('dist/CNAME', 'preprod.swarmsim.com');
});
grunt.registerTask('publictestCname', 'build beta.swarmsim.com cname file', function () {
grunt.file.write('dist/CNAME', 'beta.swarmsim.com');
});
grunt.registerTask('cleanCname', 'build swarmsim.com cname file', function () {
grunt.file.delete('dist/CNAME');
});
grunt.registerTask('ss', 'Preload spreadsheet data and save to .tmp', function () {
grunt.task.run(['preloadSpreadsheet']);
});
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
if (target === 'prod') {
grunt.task.run([
'clean:server',
//'mxmlc:prod',
'ngconstant:prod','writeVersionJson', 'ngtemplates:dist',
'wiredep',
'concurrent:server',
'swPrecache:dist',
//'manifest:prod',
'autoprefixer',
'connect:livereload',
'watch'
]);
}
grunt.task.run([
'clean:server',
//'mxmlc:dev',
'ngconstant:dev','writeVersionJson', 'ngtemplates:dev',
'wiredep',
'concurrent:server',
'swPrecache:dev',
//'manifest:dev',
'autoprefixer',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('server', 'DEPRECATED TASK. Use the "serve" task instead', function (target) {
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
grunt.task.run(['serve:' + target]);
});
grunt.registerTask('test', [
'clean:server',
'ngconstant:test','writeVersionJson', 'ngtemplates:dev',
'concurrent:test',
'autoprefixer',
'connect:test',
'coffeelint',
'karma:unitCi',
'karma:integrationCi'
]);
grunt.registerTask('build', function(envname) {
envname = envname || 'prod';
if (envname !== 'prod' && envname !== 'preprod') {
throw new Error('invalid build envname: '+envname);
}
console.log('building envname '+envname);
grunt.task.run([
'clean:dist',
'ngconstant:'+envname,'writeVersionJson',
'wiredep',
'useminPrepare',
'concurrent:dist',
'ngtemplates:dist',
'autoprefixer',
'concat',
'ngmin',
'copy:dist',
//'cdnify',
'cssmin',
'uglify',
'filerev',
// no need for both manifest.appcache and service-worker caching - similar result, but service-workers are newer
//'manifest',
'swPrecache:dist',
'usemin',
'htmlmin',
// mxmlc stopped working at some point, but I can't be bothered to fix it properly.
// The compiled version is now saved in git, so we'll just use that and remove all
// flash deps from the build.
//'mxmlc:prod'
]);
});
grunt.registerTask('default', [
'newer:jshint',
'test',
'build'
]);
grunt.registerTask('deploy-staging', [
'build',
'stagingCname','gh-pages:staging','cleanCname'
]);
grunt.registerTask('deploy-preprod', [
'build:preprod',
'preprodCname','gh-pages:preprod','cleanCname'
]);
grunt.registerTask('deploy-publictest', [
'build',
'publictestCname','gh-pages:publictest','cleanCname'
]);
grunt.registerTask('phonegap-staging', [
'build',
'copy:phonegap',
'stagingCname','gh-pages:staging','cleanCname'
]);
grunt.registerTask('deploy-prod-dotcom', [
'build',
'buildCname','gh-pages:prodDotcom','cleanCname'
]);
grunt.registerTask('deploy-prod-githubio', [
'build',
'cleanCname','gh-pages:prodGithubio',