forked from sillsdev/web-languageforge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
1553 lines (1383 loc) · 42.3 KB
/
gulpfile.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
'use strict';
// *************************************
//
// Gulpfile
//
// *************************************
//
// -------------------------------------
// To see available tasks use:
// gulp -T Print the task dependency tree
// gulp --tasks-simple Print a list of gulp task names
// -------------------------------------
//
// -------------------------------------
// Modules
// -------------------------------------
require('es6-shim');
var _execute = require('child_process').exec;
var gulp = require('gulp');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var phpunit = require('gulp-phpunit');
var protractor = require('gulp-protractor').protractor;
var webdriverStandalone = require('gulp-protractor').webdriver_standalone;
var webdriverUpdate = require('gulp-protractor').webdriver_update;
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var _template = require('lodash.template');
var Server = require('karma').Server;
var path = require('path');
var stylish = require('jshint-stylish');
var dotnetPublish = require('gulp-dotnet-cli').publish;
var dotnetTest = require('gulp-dotnet-cli').test;
var fs = require('fs');
var del = require('del');
var data = require('gulp-data');
var ejs = require('gulp-ejs');
var dest = require('gulp-dest');
// Define release stages that will send errors to bugsnag
var notifyReleaseStages = "['live', 'qa']";
// If using a JSON file for the Google API secrets, uncomment the following line and search for
// "Google API" to find other lines to uncomment further below.
// const secrets_google_api_client_id = require('./secrets/google-api-client-id.json');
// -------------------------------------
// Global Variables
// -------------------------------------
var srcPatterns = [
'src/angular-app/**',
'src/Api/**',
'src/Site/**',
'test/**'
];
var phpPatterns = [
'src/angular-app/**/*.php',
'src/Api/**/*.php',
'src/Site/**/*.php',
'test/**/*.php'
];
// -------------------------------------
// Task: Lint
// -------------------------------------
gulp.task('lint', function () {
return gulp.src(srcPatterns)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
// -------------------------------------
// Task: Auto-generate language picker asset files
// -------------------------------------
gulp.task('generate-language-picker-assets', function (cb) {
// Manual prerequisite:
// copy from libpalaso:palaso-trusty64-master/SIL.WritingSystems/Resources/*.txt
// into scripts/language picker/
var options = {
dryRun: false,
silent: false,
cwd: './scripts/language picker/'
};
// auto-generated files written to src/angular-app/bellows/js/assets/
execute(
'./build-json-language-data.py',
options,
cb
);
});
gulp.task('generate-language-picker-assets').description =
'Update asset files used for language picker';
// region sass
var sassCommand = './node_modules/.bin/node-sass';
gulp.task('sass', gulp.parallel(
function buildSiteDir(done) {
execute(sassCommand + ' src/Site/ -o src/Site/ --output-style compressed', null, done);
},
function buildAngularAppDir(done) {
execute(sassCommand + ' src/angular-app/ -o src/angular-app/ --output-style compressed',
null, done);
}
));
gulp.task('sass:watch', function () {
var debug = process.argv.indexOf('--debug') !== -1;
if (!debug) console.info('Tip: run with --debug to generate source comments and source maps.');
var watch = ' --watch --recursive';
var debugArgs = debug ? ' --source-comments --source-map-embed --source-map-contents' : '';
var a = sassCommand + ' src/Site -o src/Site' + debugArgs;
var b = sassCommand + ' src/angular-app -o src/angular-app' + debugArgs;
return new Promise(function (resolve, reject) {
execute(b, null, function () {
execute(b + watch, null, reject);
});
execute(a, null, function () {
execute(a + watch, null, reject);
});
});
});
// endregion
//region webpack
function webpack(applicationName, callback, isProduction, isWatch) {
var watch = isWatch ? ' --watch' : '';
var envApplication = applicationName ? ' --env.applicationName=' + applicationName : '';
var prod = isProduction ? ' -p' : '';
if (!process.env.NOTIFY_RELEASE_STAGES)
process.env.NOTIFY_RELEASE_STAGES = notifyReleaseStages;
execute('$(npm bin)/webpack' + watch + envApplication + prod + ' --colors',
{ cwd: '.', env: process.env },
function (err) {
if (err) throw new gutil.PluginError('webpack', err);
callback();
});
}
// -------------------------------------
// Task: webpack-lf
// -------------------------------------
gulp.task('webpack-lf', function (cb) {
webpack('languageforge', cb);
});
// -------------------------------------
// Task: webpack-lf watch
// -------------------------------------
gulp.task('webpack-lf:watch', function (cb) {
webpack('languageforge', cb, false, true);
});
// -------------------------------------
// Task: webpack-sf
// -------------------------------------
gulp.task('webpack-sf', function (cb) {
webpack('scriptureforge', cb);
});
// -------------------------------------
// Task: webpack-sf watch
// -------------------------------------
gulp.task('webpack-sf:watch', function (cb) {
webpack('scriptureforge', cb, false, true);
});
// endregion
//region MongoDB
// -------------------------------------
// Task: MongoDB: Backup Production
// -------------------------------------
gulp.task('mongodb-backup-prod-db', function (cb) {
execute(
'ssh scriptureforge.org \'bash -s\' < scripts/server/mongodb/backupMongoOnServer.sh',
null,
cb
);
});
// -------------------------------------
// Task: MongoDB: Copy Backup to Local
// -------------------------------------
gulp.task('mongodb-copy-backup-to-local', function (cb) {
var padLeft = function (i, len, ch) {
var val = i.toString();
while (val.length < len)
val = ch + val;
return val;
};
var formatDateYMD = function (date) {
return date.getFullYear() + '-' + padLeft(date.getMonth() + 1, 2, '0') + '-' +
padLeft(date.getDate(), 2, '0');
};
var today = formatDateYMD(new Date());
execute(
'scp scriptureforge.org:mongodb_backup_' + today + '.tgz /tmp/',
null,
cb
);
});
// -------------------------------------
// Task: MongoDB: Clean Backup Production
// -------------------------------------
gulp.task('mongodb-cleanup-backup-prod-db', function (cb) {
// To set the username, edit your ssh config file (~/.ssh/config) and add an entry:
// Host scriptureforge.org
// User jdoe
execute(
'ssh scriptureforge.org \'bash -s\' < scripts/server/mongodb/deleteTarFileOnServer.sh',
null,
cb
);
});
// -------------------------------------
// Task: MongoDB: Restore Mongo on Local
// -------------------------------------
gulp.task('mongodb-restore-local-db', function (cb) {
execute(
'scripts/server/mongodb/restoreMongoOnLocal.sh /tmp',
null,
cb
);
});
gulp.task('mongodb-restore-local-db').description =
'Restore mongodb from a local archive file';
// -------------------------------------
// Task: MongoDB: Copy Production
// -------------------------------------
gulp.task('mongodb-copy-prod-db',
gulp.series(
'mongodb-backup-prod-db',
'mongodb-copy-backup-to-local',
gulp.parallel('mongodb-cleanup-backup-prod-db', 'mongodb-restore-local-db')
)
);
gulp.task('mongodb-copy-prod-db').description =
'Backup MongoDB on server and restore on local machine';
//endregion
//region Test (PHP, JS, .NET, and E2E)
// -------------------------------------
// Task: test-php
// -------------------------------------
gulp.task('test-php', function () {
var src = 'test/php/phpunit.xml';
var options = {
dryRun: false,
debug: false,
logJunit: 'PhpUnitTests.xml'
};
gutil.log("##teamcity[importData type='junit' path='PhpUnitTests.xml']");
return gulp.src(src)
.pipe(phpunit('src/vendor/bin/phpunit', options));
});
// -------------------------------------
// Task: test-php with debugging info
// -------------------------------------
gulp.task('test-php-debug', function () {
var src = 'test/php/phpunit.xml';
var options = {
dryRun: false,
debug: true
};
return gulp.src(src)
.pipe(phpunit('src/vendor/bin/phpunit', options));
});
// -------------------------------------
// Task: test-php-coverage
// -------------------------------------
gulp.task('test-php-coverage', function () {
var src = 'test/php/phpunit.xml';
var options = {
dryRun: false,
debug: false,
logJunit: 'PhpUnitTests.xml',
coverageHtml: 'test/CodeCoverage/php/'
};
gutil.log("##teamcity[importData type='junit' path='PhpUnitTests.xml']");
return gulp.src(src)
.pipe(phpunit('src/vendor/bin/phpunit', options));
});
// -------------------------------------
// Task: test-php:watch
// -------------------------------------
gulp.task('test-php:watch', function () {
gulp.watch(phpPatterns, ['test-php']);
});
// -------------------------------------
// Task: test-php-debug:watch with debugging info
// -------------------------------------
gulp.task('test-php-debug:watch', function () {
gulp.watch(phpPatterns, ['test-php-debug']);
});
function runKarmaTests(applicationName, cb, type) {
var config = {
configFile: __dirname + '/karma.conf.js',
applicationName: applicationName
};
switch (type) {
case 'ci':
config.reporters = 'teamcity';
break;
case 'watch':
config.autoWatch = true;
config.singleRun = false;
break;
case 'debug':
config.autoWatch = true;
config.singleRun = false;
config.browsers = [];
break;
}
new Server(config, function(err) {
if (err === 0) {
cb();
} else {
cb(new gutil.PluginError('karma', { message: 'Karma Tests failed' }));
}
}).start();
}
// -------------------------------------
// Task: test-ts
// -------------------------------------
gulp.task('test-ts', function (cb) {
var params = require('yargs')
.option('applicationName', {
demand: true,
type: 'string' })
.fail(yargFailure)
.argv;
runKarmaTests(params.applicationName, cb, 'ci');
});
// -------------------------------------
// Task: test-ts-lf
// -------------------------------------
gulp.task('test-ts-lf', function (cb) {
runKarmaTests('languageforge', cb);
});
// -------------------------------------
// Task: test-ts-lf:watch
// -------------------------------------
gulp.task('test-ts-lf:watch', function (cb) {
runKarmaTests('languageforge', cb, 'watch');
});
// -------------------------------------
// Task: test-ts-lf:debug
// -------------------------------------
gulp.task('test-ts-lf:debug', function (cb) {
runKarmaTests('languageforge', cb, 'debug');
});
// -------------------------------------
// Task: test-ts-sf
// -------------------------------------
gulp.task('test-ts-sf', function (cb) {
runKarmaTests('scriptureforge', cb);
});
// -------------------------------------
// Task: test-ts-sf:watch
// -------------------------------------
gulp.task('test-ts-sf:watch', function (cb) {
runKarmaTests('scriptureforge', cb, 'watch');
});
// -------------------------------------
// Task: test-ts-sf:debug
// -------------------------------------
gulp.task('test-ts-sf:debug', function (cb) {
runKarmaTests('scriptureforge', cb, 'debug');
});
// -------------------------------------
// Task: E2E Test: Webdriver Update
// -------------------------------------
gulp.task('test-e2e-webdriver_update', webdriverUpdate);
// -------------------------------------
// Task: E2E Test: Webdriver Standalone
// -------------------------------------
gulp.task('test-e2e-webdriver_standalone', webdriverStandalone);
function copy(src, dest) {
return gulp.src(src)
.pipe(rename(dest.file))
.pipe(gulp.dest(dest.path));
}
// -------------------------------------
// Task: E2E Test: Use Test Config
// -------------------------------------
gulp.task('test-e2e-useTestConfig', function () {
var src = 'src/config.php.fortest';
var dest = {
file: 'config.php',
path: 'src/' };
return copy(src, dest);
});
// -------------------------------------
// Task: E2E Test: Use Live Config
// -------------------------------------
gulp.task('test-e2e-useLiveConfig', function () {
var src = 'src/config.php.live';
var dest = {
file: 'config.php',
path: 'src/' };
return copy(src, dest);
});
// -------------------------------------
// Task: E2E Test: Setup Test Environment
// -------------------------------------
gulp.task('test-e2e-setupTestEnvironment', function (cb) {
var params = require('yargs')
.option('webserverHost', {
demand: true,
describe: 'hostname (without the protocol) for E2E testing',
type: 'string' })
.option('dest', {
demand: false,
describe: 'destination of test environment',
type: 'string' })
.fail(yargFailure)
.argv;
var options = {
dryRun: false,
silent: false,
cwd: getTestCwd(params.dest)
};
execute(
'sudo -u www-data php setupTestEnvironment.php ' + params.webserverHost,
options,
cb
);
});
// -------------------------------------
// Task: E2E Test: Teardown Test Environment
// -------------------------------------
gulp.task('test-e2e-teardownTestEnvironment', function (cb) {
var params = require('yargs')
.option('dest', {
demand: false,
describe: 'destination of test environment',
type: 'string' })
.fail(yargFailure)
.argv;
var options = {
dryRun: false,
silent: false,
cwd: getTestCwd(params.dest)
};
execute(
'sudo -u www-data php teardownTestEnvironment.php',
options,
cb
);
});
// -------------------------------------
// Task: Test Restart Webserver
// -------------------------------------
gulp.task('test-restart-webserver', function (cb) {
execute(
'sudo service apache2 restart',
null,
cb
);
});
// -------------------------------------
// Task: Remote Restart PHP-FPM
// -------------------------------------
gulp.task('remote-restart-php-fpm', function (cb) {
var params = require('yargs')
.option('dest', {
demand: true,
type: 'string' })
.option('uploadCredentials', {
demand: true,
type: 'string' })
.fail(yargFailure)
.argv;
var options = {
credentials: params.uploadCredentials,
destination: params.dest.slice(0, params.dest.indexOf(':'))
};
execute(
"ssh -i <%= credentials %> <%= destination %> 'service php7.0-fpm restart'",
options,
cb
);
});
// -------------------------------------
// Task: Local Restart xForge Web API
// -------------------------------------
gulp.task('local-restart-xforge-web-api', function (cb) {
var params = require('yargs')
.option('applicationName', {
demand: true,
type: 'string' })
.option('dest', {
demand: true,
type: 'string' })
.fail(yargFailure)
.argv;
var options = {
applicationName: params.applicationName,
suffix: getServiceSuffix(params.dest)
};
execute(
'sudo systemctl restart <%= applicationName %>-web-api<%= suffix %>',
options,
cb
);
});
// -------------------------------------
// Task: Remote Restart xForge Web API
// -------------------------------------
gulp.task('remote-restart-xforge-web-api', function (cb) {
var params = require('yargs')
.option('applicationName', {
demand: true,
type: 'string' })
.option('dest', {
demand: true,
type: 'string' })
.option('uploadCredentials', {
demand: true,
type: 'string' })
.fail(yargFailure)
.argv;
var options = {
applicationName: params.applicationName,
credentials: params.uploadCredentials,
destination: params.dest.slice(0, params.dest.indexOf(':')),
suffix: getServiceSuffix(params.dest)
};
execute(
'ssh -i <%= credentials %> <%= destination %>' +
" 'systemctl restart <%= applicationName %>-web-api<%= suffix %>'",
options,
cb
);
});
// -------------------------------------
// Task: Local Restart Node Server
// -------------------------------------
gulp.task('local-restart-node-server', function (cb) {
var params = require('yargs')
.option('applicationName', {
demand: true,
type: 'string' })
.option('dest', {
demand: true,
type: 'string' })
.fail(yargFailure)
.argv;
if (params.applicationName === 'languageforge') {
cb();
return;
}
var options = {
applicationName: params.applicationName,
suffix: getServiceSuffix(params.dest)
};
execute(
'sudo systemctl restart <%= applicationName %>-sharedb<%= suffix %>',
options,
cb
);
});
// -------------------------------------
// Task: Remote Restart Node Server
// -------------------------------------
gulp.task('remote-restart-node-server', function (cb) {
var params = require('yargs')
.option('applicationName', {
demand: true,
type: 'string' })
.option('dest', {
demand: true,
type: 'string' })
.option('uploadCredentials', {
demand: true,
type: 'string' })
.fail(yargFailure)
.argv;
if (params.applicationName === 'languageforge') {
cb();
return;
}
var options = {
applicationName: params.applicationName,
credentials: params.uploadCredentials,
destination: params.dest.slice(0, params.dest.indexOf(':')),
suffix: getServiceSuffix(params.dest)
};
execute(
'ssh -i <%= credentials %> <%= destination %>' +
" 'systemctl restart <%= applicationName %>-sharedb<%= suffix %>'",
options,
cb
);
});
// -------------------------------------
// Task: E2E Test: Modify Environment
// -------------------------------------
gulp.task('test-e2e-env', function () {
var params = require('yargs')
.option('applicationName', {
demand: true,
type: 'string' })
.option('dest', {
demand: false,
type: 'string' })
.option('webserverHost', {
demand: false,
default: 'languageforge.local',
type: 'string' })
.fail(yargFailure)
.argv;
var cwd = getTestCwd(params.dest);
var src = [
'setupTestEnvironment.php',
'teardownTestEnvironment.php',
'e2eTestConfig.php',
'testConstants.json'];
// noinspection RegExpRedundantEscape
return gulp.src(src, { cwd: cwd })
// e2eTestConfig.php
.pipe(replace('src/', 'htdocs/'))
// testConstants.json
.pipe(replace(
/(\s*\"siteType\"\s*:\s*\").*$/m,
'$1' + params.applicationName + '",'))
.pipe(replace(
/(\s*\"siteHostname\"\s*:\s*\").*$/m,
'$1' + params.webserverHost + '",'))
.pipe(replace(
/(\s*\"baseUrl\"\s*:\s*\").*$/m,
'$1http://' + params.webserverHost + '",'))
.pipe(gulp.dest(cwd));
});
// -------------------------------------
// Task: E2E Test: Do Test
// -------------------------------------
gulp.task('test-e2e-doTest', function (cb) {
var params = require('yargs')
.usage(
'Usage: $0 test-e2e-doTest --webserverHost [hostname] --specs [testSpecs] ' +
'--seleniumAddress [address] --verbosity [bool] --conf [filename]')
.option('webserverHost', {
demand: true,
describe: 'hostname (without the protocol) for E2E testing',
type: 'string' })
.option('specs', {
demand: false,
describe: 'testSpecs are the names of the e2e test specs to run',
type: 'string' })
.option('seleniumAddress', {
demand: false,
describe: 'address of a running selenium server. default http://default.local:4444/wd/hub',
type: 'string' })
.option('verbosity', {
demand: false,
describe: 'bool for jasmine reporter verbosity. true for more detail',
type: 'boolean' })
.option('conf', {
demand: false,
describe: 'filename of a protractor conf file. default is protractorConf.js',
type: 'string' })
.option('browserStackUser', {
demand: false,
describe: 'BrowserStack API username',
type: 'string' })
.option('browserStackKey', {
demand: false,
describe: 'BrowserStack API key',
type: 'string' })
.help('?')
.alias('?', 'help')
.example('$0 test-e2e-run --webserverHost languageforge.local',
'Runs all the E2E tests for languageforge')
.example('$0 test-e2e-run --webserverHost scriptureforge.local --specs projectSettingsPage',
'Runs the scriptureforge E2E test for projectSettingsPage')
.fail(yargFailure)
.argv;
var protocol =
(params.webserverHost === 'jamaicanpsalms.scriptureforge.local') ? 'https://' : 'http://';
var configFile;
var isBrowserStack = false;
var protractorOptions = {
debug: false,
args: []
};
// Get the browser stack user and password
if (params.browserStackUser && params.browserStackUser.length > 0) {
protractorOptions.args.push('--browserstackUser', params.browserStackUser);
isBrowserStack = true;
}
if (params.browserStackKey && params.browserStackKey.length > 0) {
protractorOptions.args.push('--browserstackKey', params.browserStackKey);
}
var webserverHost = params.webserverHost;
if (isBrowserStack) {
webserverHost = webserverHost.replace('.local', '.org');
}
if (params.conf && params.conf.length > 0) {
configFile = './test/app/' + params.conf;
} else {
if (isBrowserStack) {
configFile = './test/app/browserStackLFProtractorConf.js';
} else {
configFile = './test/app/protractorConf.js';
}
}
// vars for configuring protractor
protractorOptions.configFile = configFile;
protractorOptions.args.push('--baseUrl', protocol + webserverHost);
// Generate list of specs to test (glob format so protractor will test whatever files exist)
var specString = (params.specs) ? params.specs : '*';
var specs = ['test/app/allspecs/**/*.e2e-spec.js'];
if (specString === '*') {
specs.push('test/app/bellows/**/*-traversal.e2e-spec.js');
if (params.webserverHost.includes('languageforge')) {
specs.push('test/app/languageforge/**/*-traversal.e2e-spec.js');
} else {
specs.push('test/app/scriptureforge/**/*-traversal.e2e-spec.js');
}
}
specs.push('test/app/bellows/**/' + specString + '.e2e-spec.js');
if (params.webserverHost.includes('languageforge')) {
specs.push('test/app/languageforge/**/' + specString + '.e2e-spec.js');
} else {
specs.push('test/app/scriptureforge/**/' + specString + '.e2e-spec.js');
}
// Get the selenium server address
if (params.seleniumAddress && params.seleniumAddress.length > 0) {
protractorOptions.args.push('--seleniumAddress', params.seleniumAddress);
}
if (params.verbosity) {
protractorOptions.args.push('--params.verbosity', 3);
} else {
protractorOptions.args.push('--params.verbosity', 0);
}
// It's better to pass the specs array of files to test, and not use the --exclude parameter
console.log('specs: ', specs);
return gulp.src(specs)
.pipe(protractor(protractorOptions))
.on('error', function (e) {
console.log(e);
throw e;
})
.on('end', cb);
});
// -------------------------------------
// Task: E2E Test: Clean compiled files
// -------------------------------------
gulp.task('test-e2e-clean', function () {
return del([
'test/app/**/*.e2e-spec.js.map',
'test/app/**/*.e2e-spec.js',
'test/app/**/shared/*.js.map',
'test/app/**/shared/*.js'
]);
});
// -------------------------------------
// Task: E2E Test: Compile TS files
// -------------------------------------
gulp.task('test-e2e-compile', function (cb) {
return execute('node_modules/typescript/bin/tsc -p test/app', null, cb);
});
// -------------------------------------
// Task: E2E Test: Watch and Compile TS files
// -------------------------------------
gulp.task('test-e2e-compile:watch', function (cb) {
return execute('node_modules/typescript/bin/tsc -p test/app --watch', null, cb);
});
// -------------------------------------
// Task: E2E Test: Run
// -------------------------------------
gulp.task('test-e2e-clean-compile',
gulp.series(
'test-e2e-clean',
'test-e2e-compile')
);
// -------------------------------------
// Task: E2E Test: Teardown for developer
// -------------------------------------
gulp.task('test-e2e-teardownForLocalDev', gulp.series(
'test-e2e-teardownTestEnvironment',
'test-e2e-useLiveConfig',
'test-restart-webserver')
);
// -------------------------------------
// Task: E2E Test: Run
// -------------------------------------
gulp.task('test-e2e-run',
gulp.series(
'test-e2e-clean-compile',
'test-e2e-useTestConfig',
'test-restart-webserver',
'test-e2e-setupTestEnvironment',
'test-e2e-doTest')
);
gulp.task('test-e2e-run').description = 'Run the E2E test on local developer environment';
gulp.task('test-e2e-local-lf', gulp.series(
'test-e2e-clean-compile',
'test-e2e-useTestConfig',
'test-restart-webserver',
'test-e2e-setupTestEnvironment',
'test-e2e-doTest',
'test-e2e-teardownTestEnvironment',
'test-e2e-useLiveConfig',
'test-restart-webserver')
);
// -------------------------------------
// Task: Run .NET Core unit tests
// -------------------------------------
gulp.task('test-dotnet', function () {
return gulp.src('**/*.Tests.csproj', { read: false }).pipe(dotnetTest());
});
//endregion
//region build
// -------------------------------------
// Task: Build Composer
// -------------------------------------
gulp.task('build-composer', function (cb) {
var options = {
dryRun: false,
silent: false,
cwd: './src'
};
execute(
'composer install',
options,
cb
);
});
// -------------------------------------
// Task: Build npm front-end
// -------------------------------------
gulp.task('build-npm-front-end', function (cb) {
var options = {
dryRun: false,
silent: false,
cwd: '.'
};
execute(
'npm install',
options,
cb
);
});
// -------------------------------------
// Task: Build npm back-end
// -------------------------------------
gulp.task('build-npm-back-end', function (cb) {
var options = {
dryRun: false,
silent: false,
cwd: 'src/node'
};
execute(
'npm install',
options,
cb
);
});
// -------------------------------------
// Task: Build Remove test fixtures (directives) in HTML only on live build
// -------------------------------------
gulp.task('build-remove-test-fixtures', function (done) {
var params = require('yargs')
.option('dest', {
demand: false,
default: 'root@localhost:/var/www/virtual/languageforge.org',
type: 'string' })
.fail(yargFailure)
.argv;
var base = './src/angular-app';
var glob = path.join(base, '**/*.html');
// only on live
if (!params.dest.includes('/var/www/virtual/') &&
(params.dest.endsWith('forge.org') || params.dest.endsWith('forge.org/'))) {
return gulp.src(glob)
.pipe(replace(/^.*<pui-mock-upload.*$/m, '\n'))
.pipe(gulp.dest(base));
} else {
done();
}
});
// -------------------------------------
// Task: Build webpack
// -------------------------------------
gulp.task('build-webpack', function (cb) {
var params = require('yargs')
.option('applicationName', {
demand: true,
type: 'string' })
.option('doNoCompression', {
demand: false,
type: 'boolean' })
.fail(yargFailure)
.argv;
webpack(params.applicationName, cb, !params.doNoCompression);
});
// -------------------------------------
// Task: Build (Concat and ) Minify
// -------------------------------------
gulp.task('build-minify', function () {