forked from mathematicalthinking/encompass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
886 lines (857 loc) · 24.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
/** # Grunt Configuration
* @description We are using [Grunt](http://gruntjs.com/) the Javascript Task Runner
* for building and compiling the app. Below is the configuration.
* @see [Grunt](http://gruntjs.com/)
* @authors Philip Wisner, Dan Kelly & Dave Taylor
* @since 2.0.0
*/
/*
* MAIN GRUNT COMMANDS:
* grunt - this builds the app and runs in 8080
* // deprecated grunt serve-test - this builds and runs the test server env in 8082
* grunt serve-seed - this builds and runs the test server env in 8082
* grunt tests - this runs all tests (run this in another tab after grunt serve-test)
* grunt testEndToEnd - this runs the e2e (selenium) tests
* grunt testApi - runs only the api (backend) tests
*/
/*jshint camelcase: false */
/*global module:false */
module.exports = function (grunt) {
/*
* All initial configurations for grunt tasks needs to be done inside grunt.initConfig()
*/
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
//revision: process.env.SVN_REVISION || '??',
//build: process.env.BUILD_NUMBER || '??',
//
// // Error: Unexpected token: operator (>).
// // Line 265 in build/application-prod.js
// // in _removeElsFromDom(els)
// // at Line 265: els.forEach((el) => {
// uglify: {
// application: {
// options: {
// banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
// '<%= grunt.template.today("yyyy-mm-dd") %>'
// },
// files: {
// // 'dist/application-<%= pkg.version %>-min.js': 'build/application-prod.js'
// 'dist/application-min.js': 'build/application-prod.js'
// }
// }
// },
/*
* Set Node environment using grunt-env
* https://www.npmjs.com/package/grunt-env
*/
env: {
dev: {
NODE_ENV: "development",
},
test: {
NODE_ENV: "test",
},
seed: {
NODE_ENV: "seed",
},
prod: {
NODE_ENV: "production",
},
},
/*
* Set up the Mocha tests
* It then runs the e2e (selenium tests) or the api (mocha/chai)
* see: https://github.com/pghalliday/grunt-mocha-test
*/
mochaTest: {
e2e: {
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: ["test/selenium/*.js"],
},
travis: {
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: [
"test/selenium/base.js",
"test/selenium/comments.js",
"test/selenium/folders.js",
"test/selenium/helpers.js",
"test/selenium/problems.js",
"test/selenium/responses.js",
"test/selenium/sections.js",
"test/selenium/selectors.js",
"test/selenium/workspaces_new.js",
"test/selenium/workspaces.js",
],
},
api: {
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: ["test/mocha/*.js", "test/mocha/unit-tests/*.js"],
},
e2e_xProb: {
// does not run problems and users tests
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: [
"test/selenium/assignments_teacher.js",
"test/selenium/assignments_students.js",
"test/selenium/base.js",
"test/selenium/comments.js",
"test/selenium/confirm_email.js",
"test/selenium/forgot_password",
"test/selenium/folders.js",
"test/selenium/linked_workspaces.js",
"test/selenium/mentoring_approving",
"test/selenium/mentoring",
"test/selenium/parent_workspace",
"test/selenium/responses.js",
"test/selenium/sections.js",
"test/selenium/users.js",
"test/selenium/vmt_import.js",
"test/selenium/workspaces_new.js",
"test/selenium/workspaces.js",
"test/selenium/workspaces_settings",
],
},
e2eProblems: {
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: [
"test/selenium/problems.js",
"test/selenium/problems_info.js",
"test/selenium/problems_new",
],
},
e2eAuth: {
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: [
"test/selenium/confirm_email.js",
"test/selenium/forgot_password.js",
"test/selenium/reset_password.js",
"test/selenium/signup.js",
"test/selenium/users.js",
],
},
e2eWorkspaces: {
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: [
"test/selenium/comments.js",
"test/selenium/folders.js",
"test/selenium/workspace_settings.js",
"test/selenium/workspaces.js",
"test/selenium/workspaces_new.js",
],
},
e2eMentoring: {
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: [
"test/selenium/mentoring_approving.js",
"test/selenium/responses.js",
], // fix and add back in: 'test/selenium/mentoring.js'
},
e2eVmt: {
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: ["test/selenium/vmt_import.js"],
},
e2eGeneral: {
options: {
reporter: "spec",
//captureFile: 'results.txt',
quiet: false,
clearRequireCache: false,
clearCacheFilter: (key) => true,
noFail: false,
},
src: [
"test/selenium/base.js",
"test/selenium/assignments_student.js",
"test/selenium/assignments_teacher.js",
"test/selenium/sections.js",
"test/selenium/linked_workspaces.js",
"test/selenium/parent_workspaces.js",
],
},
},
/*
* Shell task to copy test database at beginning of system tests.
*/
shell: {
restoreTestDb: {
command:
"mongorestore --drop --db=encompass_test ./test/data/encompass_test",
},
restoreSeedDb: {
command: "npm run seed",
},
sleep3: {
command: "echo 'sleep start';sleep 3;echo 'sleep done'",
},
},
/*
* Takes main.scss inside /scss files and converts it to main.css inside /build
* You need to install ruby and `gem install sass` if you want to run grunt sass
*/
sass: {
dist: {
files: [
{
expand: true,
cwd: "scss",
src: "main.scss",
dest: "build",
ext: ".css",
},
],
},
},
/*
* Runs babel to transpile ES6 code to ES5
* It takes all .js files in app/ and places the transpiled code into babel/
*/
babel: {
options: {
sourceMap: true,
presets: ["@babel/preset-env"],
},
dist: {
files: [
{
expand: true,
cwd: "app",
src: ["**/*.js"],
dest: "babel",
ext: ".js",
},
],
},
},
/*
This reads the babel/app.js folder and builds all the
required files into a single application.js file.
Additionally it will wrap them in evals with @ sourceURL statements so errors,
log statements and debugging will reference the source files by line number.
You would set this option to false for production.
*/
neuter: {
dev: {
options: {
includeSourceURL: true,
},
src: "babel/app.js",
dest: "build/application.js",
},
prod: {
src: "babel/app.js",
dest: "build/application-prod.js",
},
},
/*
Browserify is just taking a single .js file
and preparing it for the browser
*/
browserify: {
options: {
browserifyOptions: {
debug: true,
},
},
main: {
src: "common/browser.js",
dest: "build/common_bundle.js",
},
},
/*
Watch files for changes.
Not spawning a new grunt task speeds this up quite a bit
*/
watch: {
common_code: {
files: ["common/**/*.js"],
tasks: ["browserify", "MochaTests", "eslint"], //common code is used on the front and backend
options: {
spawn: false,
},
},
common_files: {
files: ["Gruntfile.js", ".eslintrc.js"],
tasks: ["eslint"], //anything could have changed in the Gruntfile
options: {
spawn: false,
},
},
ember_code: {
files: [
"app/**/*.js",
"dependencies/**/*.js",
"!dependencies/compiled/templates.js",
"!server/datasource/**",
"!server/server.js",
"!server/config.js",
],
tasks: ["neuter:dev", "eslint"], //jqunit
options: {
spawn: false,
},
},
server_code: {
files: [
"server/server.js",
"server/fake_login.js",
"server/config.js",
"server/datasource/**/*.js",
],
tasks: ["eslint"], //nodemon monitors it's own files,
options: {
spawn: false,
},
},
handlebars_templates: {
files: ["app/**/*.hbs"],
tasks: ["emberTemplates", "neuter:dev"], //jqunit
options: {
spawn: false,
},
},
common_tests: {
files: ["test/jasmine/common/**"],
tasks: ["jasmine:common", "eslint"],
options: {
spawn: false,
},
},
ember_qunit: {
files: ["test/qunit/**/*.*", "test/data/fixtures.js"],
tasks: ["eslint"], //jqunit
options: {
spawn: false,
},
},
sass_code: {
files: ["scss/*.scss"],
tasks: ["sass"],
options: {
spawn: false,
},
},
},
/*
These tests need to be rewritten, they are tests for the:
properties_spec.js & workspace_spec.js
*/
jasmine: {
common: {
src: "build/common_bundle.js",
options: {
specs: ["test/jasmine/common/**/*_spec.js"],
junit: {
path: "build/.test",
},
//display: 'short',
summary: false, //https://github.com/gruntjs/grunt-contrib-jasmine/issues/145
keepRunner: true,
},
},
},
/*
Qunit tests are built into ember, they are currently out of date,
Maybe only use for large components & pages
*/
qunit: {
all: ["test/qunit/q*html"],
options: {
console: false, //like to use 0.5.0 https://github.com/gruntjs/grunt-contrib-qunit/issues/68
},
},
/*
Generate junit reports from qunit runs
*/
qunit_junit: {
options: {
dest: "build/.test",
},
},
/*
Reads the projects .jshintrc file and applies coding
standards. Doesn't lint the dependencies or test
support files.
*/
jshint: {
all: [
"Gruntfile.js",
"app/**/*.js",
"server/**/*.js",
"test/**/*.js",
"!dependencies/*.*",
"!test/qunit/support/*.*",
"!test/selenium/*.js",
"!test/data/*.js",
"!server/db_migration/*.js",
"!test/mocha/*.js",
"!server/middleware/access/*.js",
],
options: {
jshintrc: ".jshintrc",
},
},
eslint: {
target: [
"Gruntfile.js",
"app/**/*.js",
"server/**/*.js",
"common/*.js",
"!dependencies/*.*",
"!test/qunit/support/*.*",
"test/selenium/*.js",
"test/data/*.js",
"!server/db_migration/*.js",
"test/mocha/*.js",
"server/middleware/access/*.js",
"!server/fake_login.js",
],
options: {
configFile: ".eslintrc.js",
},
},
/*
Finds Handlebars templates and precompiles them into functions.
The provides two benefits:
1. Templates render much faster
2. We only need to include the handlebars-runtime microlib
and not the entire Handlebars parser.
Files will be written out to dependencies/compiled/templates.js
which is required within the project files so will end up
as part of our application.
The compiled result will be stored in
Ember.TEMPLATES keyed on their file path (with the 'app/templates' stripped)
*/
emberTemplates: {
options: {
templateName: function (sourceFile) {
return sourceFile.replace(/app\/templates\//, "");
},
templateCompilerPath: "dependencies/ember-template-compiler2_14_1.js",
},
"dependencies/compiled/templates.js": ["app/templates/**/*.hbs"],
},
nodemon: {
dev: {
script: "server/server.js",
options: {
watch: [
"server/server.js",
"config.json",
"server/config.js",
"server/datasource",
"Gruntfile.js",
],
},
},
debug: {
script: "server/server.js",
options: {
nodeArgs: ["--debug"],
watch: [
"server/server.js",
"config.json",
"server/config.js",
"server/datasource",
"Gruntfile.js",
],
},
},
},
"node-inspector": {
custom: {
options: {
"web-port": 8081,
},
},
},
/**
* Run nodemon and watch concurrently (in one tab)
*/
concurrent: {
dev: {
tasks: ["nodemon:dev", "eslint", "watch"],
options: {
logConcurrentOutput: true,
},
},
endToEndTasks: {
tasks: ["nodemon:dev", "endToEndTests"],
},
apiTasks: {
tasks: ["nodemon:dev", "apiTests"],
},
waitApiTasks: {
tasks: ["nodemon:dev", "waitApiTests"],
},
test: {
tasks: ["nodemon:dev", "MochaTests", "watch"],
options: {
logConcurrentOutput: true,
},
},
"debug-only": {
tasks: ["nodemon:debug", "node-inspector"],
options: {
logConcurrentOutput: true,
},
},
debug: {
tasks: ["nodemon:debug", "node-inspector", "MochaTests", "watch"],
options: {
logConcurrentOutput: true,
},
},
systemTests: {
tasks: ["nodemon:sysTest", "mochaSelenium"],
options: {
logConcurrentOutput: true,
},
},
},
// Would like to be able to put .env_* files in temp file in concat, and then output to .env filename in zip file.
compress: {
staging: {
options: {
archive: "staging.zip",
},
files: [
{
src: [
"dist/**",
"common/**",
"dependencies/**",
"server/**",
"seeders/**",
"package.json",
"package-lock.json",
".env_staging",
"md-seed-config.js",
"md-seed-generator.json",
],
dest: "./staging/",
expand: true,
cwd: ".",
},
],
},
prod: {
options: {
archive: "prod.zip",
},
files: [
{
src: [
"dist/**",
"common/**",
"dependencies/**",
"server/**",
"package.json",
"package-lock.json",
".env_prod",
],
dest: "./prod/",
expand: true,
cwd: ".",
},
],
},
},
concat: {
staging_env: {
src: [".env", "staging_env"],
dest: "./.env_staging",
},
prod_env: {
src: [".env", "prod_env"],
dest: "./.env_prod",
},
},
// // bump up version number (package and git) - not working
// bump: {
// options: {
// files: ['package.json'],
// updateConfigs: [],
// commit: false,
// commitMessage: 'Release v%VERSION%',
// commitFiles: ['package.json'],
// createTag: false,
// tagName: 'v%VERSION%',
// tagMessage: 'Version %VERSION%',
// push: false,
// pushTo: 'upstream',
// gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
// globalReplace: false,
// prereleaseName: false,
// metadata: '',
// regExp: false
// }
// },
clean: {
dist: {
src: ["dist/", "build/assets.json"],
},
},
// create versioned files in dist directory (from build directory)
assets_versioning: {
dist: {
options: {
versionsMapTrimPath: "dist/",
versionsMapFile: "assets.json",
tag: "date",
},
files: {
"dist/base.css": ["build/base.css"],
"dist/guiders.css": ["build/guiders.css"],
"dist/main.css": ["build/main.css"],
"dist/application.js": ["build/application.js"],
"dist/common_bundle.js": ["build/common_bundle.js"],
"dist/guiders.js": ["build/guiders.js"],
"dist/jquery.sticky.js": ["build/jquery.sticky.js"],
},
},
},
// copy unversioned files to dist directory (from build directory)
copy: {
dist: {
files: [
// copy images folder in build to dist
{
cwd: "build/images",
expand: true,
src: ["**"],
dest: "dist/images",
flatten: true,
},
// copy all html files in build root to dist
{ cwd: "build", expand: true, src: ["license.html"], dest: "dist" },
// copy all png files in build root (bg.png). is this needed ???
{ cwd: "build", expand: true, src: ["*.png", "*.svg"], dest: "dist" },
{
cwd: "build/image_uploads",
expand: true,
src: ["**"],
dest: "dist/image_uploads",
flatten: true,
},
],
},
},
// replace asset filenames in index.html using mapping
"string-replace": {
dist: {
files: [
{
expand: true,
cwd: "build/",
src: "index.html",
dest: "dist/",
},
],
options: {
// replacements: [{
// pattern: '<%= mapping.originalPath.var1 %>',
// replacement: '<%= mapping.versionedPath.var2 %>'
// }]
replacements: [], // <-- Intentionally empty and will be dynamically configured via `configAndRunStringReplace`.
},
},
},
});
/*
LOAD ALL GRUNT TASKS FROM NPM FILES
This loads grunt: babel, browserify, uglify, jshint, jasmine,
qunit, junit, neuter, contrib-watch, ember-templates, nodemon
node-inspector, concurrent, jasmine-node, mocha-casperjs,
mocha-test, casperjs, env, shell
*/
require("load-grunt-tasks")(grunt);
// ALL GRUNT TASKS & COMMANDS
/*
Build the application
- convert all the handlebars templates into compile functions
- convert all ES6 code in app to ES5
- convert the common code into a single bundle
- combine these files + application files in order
*/
grunt.registerTask("build", [
"emberTemplates",
"sass",
"babel",
"browserify",
"neuter",
]);
grunt.registerTask("build-test", [
"emberTemplates",
"babel",
"browserify",
"neuter",
]);
/*
Task for default `grunt` command
This builds the app, runs the server and monitors for changes
*/
grunt.registerTask("default", ["build", "concurrent:dev"]);
// Same as above except server is started in debug
grunt.registerTask("debug", ["build", "concurrent:debug"]);
/*
Tasks for running tests:
- tests - runs all mochaTests - this should be changed to run all tests
- jqunit - runs the qunit tests and the results output
- endToEndTests - runs the e2e MochaTest (Selenium Tests)
- apiTests - runs the api MochaTest (backend mocha/chai tets)
- jasmineTests - NEED TO BE REPLACED
*/
grunt.registerTask("MochaTests", ["endToEndTests", "apiTests"]);
grunt.registerTask("jqunit", ["qunit_junit", "qunit"]);
grunt.registerTask("endToEndTests", ["mochaTest:e2e"]);
grunt.registerTask("travis", ["mochaTest:travis", "apiTests"]);
grunt.registerTask("apiTests", ["mochaTest:api"]);
grunt.registerTask("jasmineTests", ["jasmine"]);
/*
Alternative to 'default' where you want to run your server
and watch tasks/test in two different terminals
grunt serve #terminal 1
grunt dev #terminal 2
*/
grunt.registerTask("serve", ["nodemon:dev"]);
grunt.registerTask("serve-debug", ["concurrent:debug-only"]);
grunt.registerTask("dev", ["env:dev", "build", "MochaTests", "watch"]);
// Task for reseting the TestDB
grunt.registerTask("resetTestDb", ["shell:restoreTestDb"]);
grunt.registerTask("resetSeedDb", ["shell:restoreSeedDb"]);
// Tasks for creating test server, running all tests, or running indiviudal tests
grunt.registerTask("serve-test", [
"env:test",
"resetTestDb",
"build-test",
"nodemon:dev",
]);
grunt.registerTask("serve-seed", [
"env:seed",
"resetSeedDb",
"build-test",
"nodemon:dev",
]);
grunt.registerTask("tests", ["env:test", "build-test", "MochaTests"]);
grunt.registerTask("travisTests", ["env:test", "build-test", "travis"]);
grunt.registerTask("testEndToEnd", [
"env:test",
"resetTestDb",
"concurrent:endToEndTasks",
]);
grunt.registerTask("testApi", [
"env:test",
"resetTestDb",
"concurrent:apiTasks",
]);
// grunt.registerTask('bump', ['bump']);
grunt.registerTask("dist", [
"build",
"concat",
"clean",
"assets_versioning:dist",
"configAndRunStringReplace",
"copy:dist",
"compress",
]);
// grunt.registerTask('map', ['clean:dist', 'assets_versioning:dist', 'configAndRunStringReplace']);
/**
* Helper task to dynamically configure the Array of Objects for the
* `options.replacements` property in the `dist` target of the `string-replace`
* task. Each property name of the `variableToReplace` Object (found in
* `package.json`) is set as the search string, and it's respective value
* is set as the replacement value.
*/
grunt.registerTask("configAndRunStringReplace", function () {
// 1. Read the `originalPath` mapping object from `assets.json` (Created by assets-versioning versionsMapFile option.
var replacements = grunt.file.readJSON("assets.json"),
config = [];
// 2. Dynamically build the `options.replacements` array.
for (var key in replacements) {
if (replacements[key] && replacements[key].originalPath) {
console.log(
`replacement pair= ${key}: ${replacements[key].versionedPath}`
);
// console.log(`pattern: ${new RegExp(key, 'g')}`)
console.log(`pattern: ${replacements[key].originalPath}`);
config.push({
// pattern: new RegExp(key, 'g'),
pattern: replacements[key].originalPath,
// replacement: replacements[key]
replacement: replacements[key].versionedPath,
});
}
}
// 3. Configure the option.replacements values.
grunt.config.set("string-replace.dist.options.replacements", config);
// 4. Run the task.
grunt.task.run("string-replace:dist");
});
// Note: In the `default` Task we add the `configAndRunStringReplace`
// task to the taskList array instead of `string-replace`.
// grunt.registerTask('map2', ['configAndRunStringReplace']);
};