-
Notifications
You must be signed in to change notification settings - Fork 46
/
Gruntfile.js
726 lines (724 loc) · 31.9 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
var taskName = '';
module.exports = function (grunt) {
var _ = require('lodash');
// Load required Grunt tasks. These are installed based on the versions listed
// * in 'package.json' when you do 'npm install' in this directory.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-ng-annotate');
grunt.loadNpmTasks('grunt-html2js');
grunt.loadNpmTasks('grunt-angular-translate');
grunt.loadNpmTasks('grunt-regex-replace');
grunt.loadNpmTasks('grunt-zip');
grunt.loadNpmTasks('grunt-ssh');
grunt.loadNpmTasks('grunt-parallel');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-ngdocs');
/** ********************************************************************************* */
/** **************************** File Config **************************************** */
var fileConfig = {
build_dir: 'public',
compile_dir: 'public',
/**
* This is a collection of file patterns for our app code (the
* stuff in 'src/'). These paths are used in the configuration of
* build tasks. 'js' is all project javascript, except tests.
* template HTML files, while 'appTemplates' contains the templates for
* our app's code. 'html' is just our main HTML file. 'less' is our main
* stylesheet, and 'unit' contains our app's unit tests.
*/
app_files: {
js: ['./client/src/assets/js/loader_build.js', '/client/src/assets/js/loader.js', 'vendor/jquery/dist/jquery.min.js', '/client/src/assets/js/ag-admin/loader_build.js', '/client/src/assets/js/ag-admin/loader.js'],
copy_js: [
'./client/src/app/App.js',
'client/src/app/Constant.js',
'client/src/app/Common/*.module.js',
'client/src/app/User/*.module.js',
'client/src/app/Wallets/*.module.js',
'client/src/app/Home/*.module.js',
'client/src/app/Message/*.module.js',
'client/src/app/Transactions/*.module.js',
'client/src/app/Common/*.js',
'client/src/app/User/*.js',
'client/src/app/Wallets/*.js',
'client/src/app/Home/*.js',
'client/src/app/Message/*.js',
'client/src/app/Transactions/*.js'
],
appTemplates: [
'client/src/app/Common/*.tpl.html',
'client/src/app/User/*.tpl.html',
'client/src/app/Wallets/*.tpl.html',
'client/src/app/Home/*.tpl.html',
'client/src/app/Message/*.tpl.html',
'client/src/app/Transactions/*.tpl.html'
],
html: ['client/src/index.html'],
less: ['client/src/less/main.less']
},
/**
* This is a collection of files used during admin pages.
*/
admin_files: {
js: ['client/src/ag-admin/js/ng-admin.jwt-auth.js', 'client/src/ag-admin/js/ng-admin.app.js'],
appTemplates: ['client/src/ag-admin/tpl/*.html'],
less: [
'client/src/less/admin/main.less'
]
},
/**
* This is the same as 'app_files', except it contains patterns that
* reference vendor code ('vendor/') that we need to place into the build
* process somewhere. While the 'app_files' property ensures all
* standardized files are collected for compilation, it is the user's job
* to ensure non-standardized (i.e. vendor-related) files are handled
* appropriately in 'vendor_files.js'.
*
* The 'vendor_files.js' property holds files to be automatically
* concatenated and minified with our project source files.
*
* The 'vendor_files.css' property holds any CSS files to be automatically
* included in our app.
*
* The 'vendor_files.assets' property holds any assets to be copied along
* with our app's assets. This structure is flattened, so it is not
* recommended that you use wildcards.
*/
vendor_files: {
js: [
'vendor/moment/min/moment-with-locales.min.js',
'vendor/jquery/dist/jquery.min.js',
'vendor/angular/angular.js',
'vendor/angular-moment/angular-moment.js',
'vendor/angular-sanitize/angular-sanitize.js',
'vendor/angular-resource/angular-resource.js',
'vendor/angular-bootstrap/ui-bootstrap-tpls.min.js',
'vendor/ng-file-upload-shim/angular-file-upload-shim.min.js',
'vendor/ng-file-upload/ng-file-upload.min.js',
'vendor/angular-ui-router/release/angular-ui-router.js',
'vendor/angular-animate/angular-animate.js',
'vendor/angular-translate/angular-translate.min.js',
'vendor/satellizer/satellizer.js',
'vendor/angular-growl-v2/build/angular-growl.js',
'vendor/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js',
'vendor/angular-dynamic-locale/tmhDynamicLocale.min.js',
'vendor/angular-translate-storage-cookie/angular-translate-storage-cookie.js',
'vendor/angular-translate-handler-log/angular-translate-handler-log.js',
'vendor/angular-translate-storage-local/angular-translate-storage-local.min.js',
'vendor/angular-cookies/angular-cookies.js',
'vendor/angular-slugify/angular-slugify.js',
'vendor/bootstrap/dist/js/bootstrap.min.js',
'vendor/angulartics/dist/angulartics.min.js',
'vendor/angulartics-google-analytics/dist/angulartics-google-analytics.min.js',
'vendor/angulartics-facebook-pixel/dist/angulartics-facebook-pixel.min.js',
'vendor/angular-recaptcha/release/angular-recaptcha.min.js',
'vendor/angular-credit-cards/release/angular-credit-cards.js',
'vendor/angular-loading-bar/build/loading-bar.min.js',
'vendor/bootstrap-ui-datetime-picker/dist/datetime-picker.js',
'vendor/accounting/accounting.js',
'vendor/angularjs-slider/dist/rzslider.js',
'vendor/angular-google-places-autocomplete/src/autocomplete.js',
'vendor/angular-bootstrap-calendar/dist/js/angular-bootstrap-calendar-tpls.min.js',
'vendor/angularjs-socialshare/dist/angular-socialshare.js'
],
css: [
'vendor/angular-growl-v2/build/angular-growl.min.css',
'vendor/angular-loading-bar/build/loading-bar.min.css',
'vendor/angularjs-slider/dist/rzslider.css',
'vendor/angular-google-places-autocomplete/src/autocomplete.css',
'vendor/angular-bootstrap-calendar/dist/css/angular-bootstrap-calendar.min.css'
],
assets: ['vendor/angular-i18n/*.*'],
moment_assets: ['vendor/moment/locale/*.*']
},
admin_vendor_files: {
js: [
'vendor/moment/min/moment-with-locales.min.js',
'vendor/jquery/dist/jquery.min.js',
'vendor/ng-admin/build/ng-admin.min.js',
'vendor/angular-google-places-autocomplete/src/autocomplete.js',
'vendor/bootstrap/dist/js/bootstrap.min.js',
'vendor/ng-file-upload/ng-file-upload.min.js',
'vendor/angular-bootstrap-calendar/dist/js/angular-bootstrap-calendar-tpls.min.js'
],
css: [
'client/src/less/admin/ng-admin.min.css',
'client/src/less/admin/timeline.css',
'vendor/angular-google-places-autocomplete/src/autocomplete.css',
'vendor/angular-bootstrap-calendar/dist/css/angular-bootstrap-calendar.min.css'
],
assets: []
}
};
/** ********************************************************************************* */
/** **************************** Task Config **************************************** */
var taskConfig = {
pkg: grunt.file.readJSON("package.json"),
/**
* The banner is the comment that is placed at the top of our compiled
* source files. It is first processed as a Grunt template, where the 'less than percent equals'
* pairs are evaluated based on this very configuration object.
*/
meta: {
banner: '/**\n' +
' * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' *\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' */\n'
},
/**
* The directories to delete when 'grunt clean' is executed.
*/
clean: {
all: [
'<%= build_dir %>/index.html',
'<%= build_dir %>/assets/',
'<%= build_dir %>/api/assets/js/',
'<%= build_dir %>/Plugins/',
'<%= build_dir %>/vendor/',
'<%= build_dir %>/client/',
'<%= build_dir %>/ag-admin/',
'!<%= build_dir %>/api_explorer/**',
'!<%= build_dir %>/.htaccess',
'!<%= build_dir %>/index.php'
],
compile: [
'<%= build_dir %>/ag-admin/js/',
'<%= build_dir %>/ag-admin/css/',
'<%= build_dir %>/vendor/',
'<%= build_dir %>/client/src/app/'
],
vendor: [
'<%= build_dir %>/vendor/'
],
index: ['<%= build_dir %>/index.html']
},
'regex-replace': {
'api-config': {
src: ['public/api_explorer/index.html', 'public/api_explorer/api-docs/*.json', 'client/src/**/*.js'],
actions: [{
name: 'Domain Replace',
search: '/bookorrent/public',
replace: '<%= config.api_url %>',
flags: 'g'
}]
}
},
zip: {
'using-cwd': {
cwd: './',
src: [
'app/**',
'bootstrap/**',
'config/**',
'client/**',
'database/**',
'public/**',
'resources/**',
'storage/**',
'tests/**',
'.env.example',
'artisan',
'composer.json',
'phpunit.xml',
'readme.md'
],
dest: 'bookorrent.zip'
}
},
sftp: {
dev1: {
files: {
"./": 'bookorrent.zip'
},
options: {
path: '<%= config.upload_path %>',
host: '<%= config.host %>',
username: '<%= config.host_username %>',
password: '<%= config.host_password %>'
}
}
},
sshexec: {
dev1: {
command: ['unzip -o -d <%= config.upload_path %> <%= config.upload_path %>/bookorrent.zip', 'rm <%= config.upload_path %>/bookorrent.zip'],
options: {
host: '<%= config.host %>',
username: '<%= config.host_username %>',
password: '<%= config.host_password %>'
}
}
},
/**
* The 'copy' task just copies files from A to B. We use it here to copy
* our project assets (images, fonts, etc.) and javascripts into
* 'build_dir', and then to copy the assets to 'compile_dir'.
*/
copy: {
build_app_assets: {
files: [
{
src: ['**'],
dest: '<%= build_dir %>/assets/',
cwd: 'client/src/assets',
expand: true
}
]
},
build_app_assets_js: {
files: [
{
src: ['<%= app_files.js %>'],
dest: '<%= build_dir %>/assets/js/',
cwd: '.',
expand: true,
flatten: true
}
]
},
build_vendor_assets: {
files: [
{
src: ['<%= vendor_files.assets %>'],
dest: '<%= build_dir %>/assets/js/angular-i18n/',
cwd: '.',
expand: true,
flatten: true
}
]
},
build_vendor_moment: {
files: [
{
src: ['<%= vendor_files.moment_assets %>'],
dest: '<%= build_dir %>/assets/js/moment/locale',
cwd: '.',
expand: true,
flatten: true
}
]
},
build_ngadmin: {
files: [
{
src: ['<%= admin_files.js %>'],
dest: '<%= build_dir %>/ag-admin/js/',
cwd: '.',
expand: true,
flatten: true
}
]
},
build_ngadmin_tpl: {
files: [
{
src: ['<%= admin_files.appTemplates %>'],
dest: '<%= build_dir %>/ag-admin/tpl/',
cwd: '.',
expand: true,
flatten: true
}
]
},
build_appjs: {
files: [
{
src: ['<%= app_files.copy_js %>'],
dest: '<%= build_dir %>/',
cwd: '.',
expand: true
}
]
},
build_vendorjs: {
files: [
{
src: ['<%= vendor_files.js %>', '<%= admin_vendor_files.js %>'],
dest: '<%= build_dir %>/',
cwd: '.',
expand: true
}
]
}
},
/**
* 'grunt concat' concatenates multiple source files into a single file.
*/
concat: {
// The 'build_css' target concatenates compiled CSS and vendor CSS together.
build_css: {
src: [
'<%= build_dir %>/assets/css/<%= pkg.name %>-<%= pkg.version %>.css',
'<%= vendor_files.css %>'
],
dest: '<%= build_dir %>/assets/css/<%= pkg.name %>-<%= pkg.version %>.css'
},
// The 'build_admin_css' target concatenates compiled CSS and vendor CSS together.
build_admin_css: {
src: [
'<%= build_dir %>/assets/css/<%= pkg.name %>-admin-<%= pkg.version %>.css',
'<%= admin_vendor_files.css %>'
],
dest: '<%= build_dir %>/assets/css/<%= pkg.name %>-admin-<%= pkg.version %>.css'
},
// The 'compile_js' target concatenates app and vendor js code together.
compile_js: {
options: {
banner: '<%= meta.banner %>'
},
src: [
'<%= vendor_files.js %>',
'module.prefix',
'<%= build_dir %>/client/src/**/*.module.js',
'<%= build_dir %>/client/src/**/*.js',
'<%= html2js.app.dest %>',
'module.suffix'
],
dest: '<%= compile_dir %>/assets/js/<%= pkg.name %>-<%= pkg.version %>.js'
},
compile_admin_js: {
options: {
banner: '<%= meta.banner %>'
},
src: [
'<%= admin_vendor_files.js %>',
'<%= admin_files.js %>'
],
dest: '<%= compile_dir %>/assets/js/<%= pkg.name %>-admin-<%= pkg.version %>.js'
}
},
/**
* 'ng-annotate' annotates the sources for safe minification. That is, it allows us
* to code without the array syntax.
*/
ngAnnotate: {
options: {
singleQuotes: true
},
build: {
files: [
{
src: ['<%= app_files.copy_js %>'],
cwd: '<%= build_dir %>',
dest: '<%= build_dir %>',
expand: true
}
]
}
},
/**
* Minify the sources!
*/
uglify: {
compile: {
options: {
banner: '<%= meta.banner %>',
mangle: false
},
files: {
'<%= concat.compile_js.dest %>': '<%= concat.compile_js.dest %>'
}
},
admin_compile: {
options: {
banner: '<%= meta.banner %>',
mangle: false //minified JS not working in admin side. So we added this option. (It works for front end compressed js)
},
files: {
'<%= concat.compile_admin_js.dest %>': '<%= concat.compile_admin_js.dest %>'
}
}
},
/**
* `grunt-contrib-less` handles our LESS compilation and uglification automatically.
* Only our 'main.less' file is included in compilation; all other files
* must be imported from this file.
*/
less: {
build: {
files: {
'<%= build_dir %>/assets/css/<%= pkg.name %>-<%= pkg.version %>.css': '<%= app_files.less %>'
}
},
admin_build: {
files: {
'<%= build_dir %>/assets/css/<%= pkg.name %>-admin-<%= pkg.version %>.css': '<%= admin_files.less %>'
}
},
compile: {
files: {
'<%= build_dir %>/assets/css/<%= pkg.name %>-<%= pkg.version %>.css': '<%= app_files.less %>'
},
options: {
cleancss: true,
compress: true
}
},
admin_compile: {
files: {
'<%= build_dir %>/assets/css/<%= pkg.name %>-admin-<%= pkg.version %>.css': '<%= admin_files.less %>'
},
options: {
cleancss: true,
compress: true
}
}
},
/**
* 'jshint' defines the rules of our linter as well as which files we
* should check. This file, all javascript sources, and all our unit tests
* are linted based on the policies listed in 'options'. But we can also
* specify exclusionary patterns by prefixing them with an exclamation
* point (!); this is useful when code comes from a third party but is
* nonetheless inside 'src/'.
*/
jshint: {
src: [
'<%= app_files.copy_js %>'
],
gruntfile: [
'Gruntfile.js'
],
options: {
curly: true,
immed: true,
newcap: true,
noarg: true,
sub: true,
boss: true,
eqnull: true
},
globals: {}
},
/**
* HTML2JS is a Grunt plugin that takes all of your template files and
* places them into JavaScript files as strings that are added to
* AngularJS's template cache. This means that the templates too become
* part of the initial payload as one JavaScript file. Neat!
*/
html2js: {
// These are the templates from 'src/app'.
app: {
options: {
base: 'client/src/app'
},
src: ['<%= app_files.appTemplates %>'],
dest: '<%= build_dir %>/assets/js/templates-app.js'
}
},
/**
* The 'index' task compiles the 'index.html' file as a Grunt template. CSS
* and JS files co-exist here but they get split apart later.
*/
index: {
/**
* During development, we don't want to have wait for compilation,
* concatenation, minification, etc. So to avoid these steps, we simply
* add all script files directly to the '<head>' of 'index.html'. The
* 'src' property contains the list of included files.
*/
build: {
appName: 'BookorRent',
dir: '<%= build_dir %>',
src: [
'<%= build_dir %>/assets/js/jquery.min.js',
'<%= build_dir %>/assets/js/loader_build.js',
'<%= build_dir %>/assets/css/<%= pkg.name %>-<%= pkg.version %>.css'
]
},
/**
* When it is time to have a completely compiled application, we can
* alter the above to include only a single JavaScript and a single CSS
* file. Now we're back!
*/
compile: {
appName: 'BookorRent',
dir: '<%= compile_dir %>',
src: [
'<%= build_dir %>/assets/js/jquery.min.js',
'<%= build_dir %>/assets/js/loader.js',
'<%= build_dir %>/assets/css/<%= pkg.name %>-<%= pkg.version %>.css'
]
}
},
/**
* The ng-admin 'index' task compiles the 'ng-admin/index.html' file as a Grunt template. CSS
* and JS files co-exist here but they get split apart later.
*/
admin_index: {
/**
* During development, we don't want to have wait for compilation,
* concatenation, minification, etc. So to avoid these steps, we simply
* add all script files directly to the '<head>' of 'index.html'. The
* 'src' property contains the list of included files.
*/
build: {
appName: 'BookorRent',
dir: '<%= build_dir %>',
src: [
'<%= build_dir %>/assets/js/jquery.min.js',
'<%= build_dir %>/assets/js/ag-admin/loader_build.js',
'<%= build_dir %>/assets/css/<%= pkg.name %>-admin-<%= pkg.version %>.css'
]
},
compile_admin: {
appName: 'BookorRent',
dir: '<%= compile_dir %>',
src: [
'<%= build_dir %>/assets/js/jquery.min.js',
'<%= build_dir %>/assets/js/ag-admin/loader.js',
'<%= build_dir %>/assets/css/<%= pkg.name %>-admin-<%= pkg.version %>.css'
]
}
},
/**
* i18nextract build json lang files
*/
i18nextract: {
// Getting all translate key to json files
default_language: {
suffix: '.json',
src: ['client/src/index.html', 'client/src/app/**/*.js', 'client/src/app/**/*.html'],
lang: ['en', 'es'],
defaultLang: 'en',
dest: 'client/src/assets/js/l10n'
},
// For filling dafault english value to fr_FR and ja-JP's value
default_exists_i18n: {
suffix: '.json',
nullEmpty: true,
src: ['client/src/index.html', 'client/src/app/**/*.js', 'client/src/app/**/*.html'],
lang: ['es'],
dest: 'client/src/assets/js/l10n/',
source: 'client/src/assets/js/l10n/en.json' // Use to generate different output file
}
},
ngdocs: {
all: ['client/src/app/**/*.js'],
}
};
/** ********************************************************************************* */
/** **************************** Project Configuration ****************************** */
// The following chooses some watch tasks based on whether we're running in mock mode or not.
// Our watch (delta above) needs to run a different index task and copyVendorJs task
// in several places if "grunt watchmock" is run.
taskName = grunt.cli.tasks[0]; // the name of the task from the command line (e.g. "grunt watch" => "watch")
// Take the big config objects we defined above, combine them, and feed them into grunt
grunt.initConfig(_.assign(taskConfig, fileConfig));
grunt.registerTask('build', [
'clean:all',
'html2js',
'jshint',
'less:build', 'less:admin_build', 'concat:build_css', 'concat:build_admin_css',
'copy:build_app_assets', 'copy:build_app_assets_js', 'copy:build_ngadmin', 'copy:build_ngadmin_tpl', 'copy:build_vendor_assets', 'copy:build_vendor_moment', 'copy:build_appjs', 'copy:build_vendorjs',
'ngAnnotate:build',
'index:build',
'admin_index:build'
]);
// 'coffeelint', 'coffee', 'copy:build_vendorcss', 'copy:build_admin_vendorcss',
// The 'compile' task gets your app ready for deployment by concatenating and minifying your code.
// Note - compile builds off of the build dir (look at concat:compile_js), so run grunt build before grunt compile
grunt.registerTask('compile', 'compile task', function (env) {
if (env === undefined) {
grunt.task.run(['clean:all', 'html2js', 'jshint', 'less:compile', 'less:admin_compile', 'concat:build_css', 'concat:build_admin_css',
'copy:build_app_assets', 'copy:build_app_assets_js', 'copy:build_ngadmin', 'copy:build_ngadmin_tpl', 'copy:build_vendor_assets', 'copy:build_vendor_moment', 'copy:build_appjs', 'copy:build_vendorjs',
'ngAnnotate:build', 'concat:compile_js', 'concat:compile_admin_js', 'uglify', 'index:compile',
'admin_index:compile_admin', 'clean:compile']);
} else {
grunt.config.set('config', grunt.file.readJSON('grunt-config/' + env + '.json'));
grunt.task.run(['clean:all', 'html2js', 'jshint', 'less:compile', 'less:admin_compile', 'concat:build_css', 'concat:build_admin_css',
'copy:build_app_assets', 'copy:build_app_assets_js', 'copy:build_ngadmin', 'copy:build_ngadmin_tpl', 'copy:build_vendor_assets', 'copy:build_vendor_moment', 'copy:build_appjs', 'copy:build_vendorjs',
'ngAnnotate:build', 'concat:compile_js', 'concat:compile_admin_js', 'uglify',
'index:compile', 'admin_index:compile_admin', 'clean:compile']);
}
});
grunt.registerTask('upload', 'Upload task', function (env) {
if (env === undefined) {
grunt.warn('Theme must be specified, like default:udemy.');
}
grunt.config.set('config', grunt.file.readJSON('grunt-config/' + env + '.json'));
grunt.task.run(['regex-replace', 'compile:' + env, 'zip', 'sftp', 'sshexec']);
});
// A utility function to get all app JavaScript sources.
function filterForJS(files) {
return files.filter(function (file) {
return file.match(/\.js$/);
});
}
// A utility function to get all app CSS sources.
function filterForCSS(files) {
return files.filter(function (file) {
return file.match(/\.css$/);
});
}
// The index.html template includes the stylesheet and javascript sources
// based on dynamic names calculated in this Gruntfile. This task assembles
// the list into variables for the template to use and then runs the
// compilation.
grunt.registerMultiTask('index', 'Process index.html template', function () {
var dirRE = new RegExp('^(' + grunt.config('build_dir') + '|' + grunt.config('compile_dir') + ')\/', 'g');
// this.fileSrc comes from either build:src, compile:src, or karmaconfig:src in the index config defined above
// see - http://gruntjs.com/api/inside-tasks#this.filessrc for documentation
var jsFiles = filterForJS(this.filesSrc).map(function (file) {
return file.replace(dirRE, '');
});
var cssFiles = filterForCSS(this.filesSrc).map(function (file) {
return file.replace(dirRE, '');
});
var app = this.data.appName;
// this.data.dir comes from either build:dir, compile:dir, or karmaconfig:dir in the index config defined above
// see - http://gruntjs.com/api/inside-tasks#this.data for documentation
grunt.file.copy('client/src/index.html', this.data.dir + '/index.html', {
process: function (contents, path) {
// These are the variables looped over in our index.html exposed as "scripts", "styles", and "version"
return grunt.template.process(contents, {
data: {
appName: app,
scripts: jsFiles,
styles: cssFiles,
version: grunt.config('pkg.version'),
author: grunt.config('pkg.author'),
date: grunt.template.today("yyyy")
}
});
}
});
});
// The index.html template includes the stylesheet and javascript sources
// based on dynamic names calculated in this Gruntfile. This task assembles
// the list into variables for the template to use and then runs the
// compilation.
grunt.registerMultiTask('admin_index', 'Process ag-admin/index.html template', function () {
var dirRE = new RegExp('^(' + grunt.config('build_dir') + '|' + grunt.config('compile_dir') + ')\/', 'g');
// this.fileSrc comes from either build:src, compile:src, or karmaconfig:src in the index config defined above
// see - http://gruntjs.com/api/inside-tasks#this.filessrc for documentation
var jsNgAdminFiles = filterForJS(this.filesSrc).map(function (file) {
return file.replace(dirRE, '');
});
var cssAdminFiles = filterForCSS(this.filesSrc).map(function (file) {
return file.replace(dirRE, '');
});
var app = this.data.appName;
// this.data.dir comes from either build:dir, compile:dir, or karmaconfig:dir in the index config defined above
// see - http://gruntjs.com/api/inside-tasks#this.data for documentation
grunt.file.copy('client/src/ag-admin/index.html', this.data.dir + '/ag-admin/index.html', {
process: function (contents, path) {
// These are the variables looped over in our index.html exposed as "scripts", "styles", and "version"
return grunt.template.process(contents, {
data: {
appName: app,
ngAdminScripts: jsNgAdminFiles,
styles: cssAdminFiles,
version: grunt.config('pkg.version'),
author: grunt.config('pkg.author'),
date: grunt.template.today("yyyy")
}
});
}
});
});
};