forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.cjs
1889 lines (1672 loc) · 53 KB
/
gulpfile.cjs
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
/*eslint-env node*/
"use strict";
var fs = require("fs");
var path = require("path");
var os = require("os");
var child_process = require("child_process");
var crypto = require("crypto");
var zlib = require("zlib");
var readline = require("readline");
var request = require("request");
var globby = require("globby");
var gulpTap = require("gulp-tap");
var gulpUglify = require("gulp-uglify");
var open = require("open");
var rimraf = require("rimraf");
var glslStripComments = require("glsl-strip-comments");
var mkdirp = require("mkdirp");
var mergeStream = require("merge-stream");
var streamToPromise = require("stream-to-promise");
var gulp = require("gulp");
var gulpInsert = require("gulp-insert");
var gulpZip = require("gulp-zip");
var gulpRename = require("gulp-rename");
var gulpReplace = require("gulp-replace");
var Promise = require("bluebird");
var Karma = require("karma");
var yargs = require("yargs");
var AWS = require("aws-sdk");
var mime = require("mime");
var rollup = require("rollup");
var rollupPluginStripPragma = require("rollup-plugin-strip-pragma");
var rollupPluginExternalGlobals = require("rollup-plugin-external-globals");
var rollupPluginUglify = require("rollup-plugin-uglify");
var cleanCSS = require("gulp-clean-css");
var typescript = require("typescript");
var packageJson = require("./package.json");
var version = packageJson.version;
if (/\.0$/.test(version)) {
version = version.substring(0, version.length - 2);
}
var karmaConfigFile = path.join(__dirname, "Specs/karma.conf.cjs");
var travisDeployUrl =
"http://cesium-dev.s3-website-us-east-1.amazonaws.com/cesium/";
//Gulp doesn't seem to have a way to get the currently running tasks for setting
//per-task variables. We use the command line argument here to detect which task is being run.
var taskName = process.argv[2];
var noDevelopmentGallery = taskName === "release" || taskName === "makeZipFile";
var minifyShaders =
taskName === "minify" ||
taskName === "minifyRelease" ||
taskName === "release" ||
taskName === "makeZipFile" ||
taskName === "buildApps";
var verbose = yargs.argv.verbose;
var concurrency = yargs.argv.concurrency;
if (!concurrency) {
concurrency = os.cpus().length;
}
var sourceFiles = [
"Source/**/*.js",
"!Source/*.js",
"!Source/Workers/**",
"!Source/WorkersES6/**",
"Source/WorkersES6/createTaskProcessorWorker.js",
"!Source/ThirdParty/Workers/**",
"!Source/ThirdParty/google-earth-dbroot-parser.js",
"!Source/ThirdParty/pako_inflate.js",
"!Source/ThirdParty/crunch.js",
];
var watchedFiles = [
"Source/**/*.js",
"!Source/Cesium.js",
"!Source/Build/**",
"!Source/Shaders/**/*.js",
"Source/Shaders/**/*.glsl",
"!Source/ThirdParty/Shaders/*.js",
"Source/ThirdParty/Shaders/*.glsl",
"!Source/Workers/**",
"Source/Workers/cesiumWorkerBootstrapper.js",
"Source/Workers/transferTypedArrayTest.js",
"!Specs/SpecList.js",
];
var filesToClean = [
"Source/Cesium.js",
"Source/Shaders/**/*.js",
"Source/Workers/**",
"!Source/Workers/cesiumWorkerBootstrapper.js",
"!Source/Workers/transferTypedArrayTest.js",
"Source/ThirdParty/Shaders/*.js",
"Specs/SpecList.js",
"Apps/Sandcastle/jsHintOptions.js",
"Apps/Sandcastle/gallery/gallery-index.js",
"Apps/Sandcastle/templates/bucket.css",
"Cesium-*.zip",
"cesium-*.tgz",
];
var filesToConvertES6 = [
"Source/**/*.js",
"Specs/**/*.js",
"!Source/ThirdParty/**",
"!Source/Cesium.js",
"!Source/copyrightHeader.js",
"!Source/Shaders/**",
"!Source/Workers/cesiumWorkerBootstrapper.js",
"!Source/Workers/transferTypedArrayTest.js",
"!Specs/karma-main.js",
"!Specs/karma.conf.cjs",
"!Specs/spec-main.js",
"!Specs/SpecList.js",
"!Specs/TestWorkers/**",
];
function rollupWarning(message) {
// Ignore eval warnings in third-party code we don't have control over
if (
message.code === "EVAL" &&
/(protobuf-minimal|crunch)\.js$/.test(message.loc.file)
) {
return;
}
console.log(message);
}
var copyrightHeader = fs.readFileSync(
path.join("Source", "copyrightHeader.js"),
"utf8"
);
function createWorkers() {
rimraf.sync("Build/createWorkers");
globby
.sync([
"Source/Workers/**",
"!Source/Workers/cesiumWorkerBootstrapper.js",
"!Source/Workers/transferTypedArrayTest.js",
])
.forEach(function (file) {
rimraf.sync(file);
});
var workers = globby.sync(["Source/WorkersES6/**"]);
return rollup
.rollup({
input: workers,
onwarn: rollupWarning,
})
.then(function (bundle) {
return bundle.write({
dir: "Build/createWorkers",
banner:
"/* This file is automatically rebuilt by the Cesium build process. */",
format: "amd",
});
})
.then(function () {
return streamToPromise(
gulp.src("Build/createWorkers/**").pipe(gulp.dest("Source/Workers"))
);
})
.then(function () {
rimraf.sync("Build/createWorkers");
});
}
gulp.task("build", function () {
mkdirp.sync("Build");
fs.writeFileSync(
"Build/package.json",
JSON.stringify({
type: "commonjs",
}),
"utf8"
);
glslToJavaScript(minifyShaders, "Build/minifyShaders.state");
createCesiumJs();
createSpecList();
createJsHintOptions();
return Promise.join(createWorkers(), createGalleryList());
});
gulp.task("build-watch", function () {
return gulp.watch(watchedFiles, gulp.series("build"));
});
gulp.task("build-ts", function () {
createTypeScriptDefinitions();
return Promise.resolve();
});
gulp.task("buildApps", function () {
return Promise.join(buildCesiumViewer(), buildSandcastle());
});
gulp.task("build-specs", function buildSpecs() {
var externalCesium = rollupPluginExternalGlobals({
"../Source/Cesium.js": "Cesium",
"../../Source/Cesium.js": "Cesium",
"../../../Source/Cesium.js": "Cesium",
"../../../../Source/Cesium.js": "Cesium",
});
var removePragmas = rollupPluginStripPragma({
pragmas: ["debug"],
});
var promise = Promise.join(
rollup
.rollup({
input: "Specs/SpecList.js",
plugins: [externalCesium],
onwarn: rollupWarning,
})
.then(function (bundle) {
return bundle.write({
file: "Build/Specs/Specs.js",
format: "iife",
});
})
.then(function () {
return rollup
.rollup({
input: "Specs/spec-main.js",
plugins: [removePragmas, externalCesium],
})
.then(function (bundle) {
return bundle.write({
file: "Build/Specs/spec-main.js",
format: "iife",
});
});
})
.then(function () {
return rollup
.rollup({
input: "Specs/karma-main.js",
plugins: [removePragmas, externalCesium],
onwarn: rollupWarning,
})
.then(function (bundle) {
return bundle.write({
file: "Build/Specs/karma-main.js",
name: "karmaMain",
format: "iife",
});
});
})
);
return promise;
});
gulp.task("clean", function (done) {
rimraf.sync("Build");
globby.sync(filesToClean).forEach(function (file) {
rimraf.sync(file);
});
done();
});
function cloc() {
var cmdLine;
//Run cloc on primary Source files only
var source = new Promise(function (resolve, reject) {
cmdLine =
"npx cloc" +
" --quiet --progress-rate=0" +
" Source/ --exclude-dir=Assets,ThirdParty,Workers --not-match-f=copyrightHeader.js";
child_process.exec(cmdLine, function (error, stdout, stderr) {
if (error) {
console.log(stderr);
return reject(error);
}
console.log("Source:");
console.log(stdout);
resolve();
});
});
//If running cloc on source succeeded, also run it on the tests.
return source.then(function () {
return new Promise(function (resolve, reject) {
cmdLine =
"npx cloc" +
" --quiet --progress-rate=0" +
" Specs/ --exclude-dir=Data";
child_process.exec(cmdLine, function (error, stdout, stderr) {
if (error) {
console.log(stderr);
return reject(error);
}
console.log("Specs:");
console.log(stdout);
resolve();
});
});
});
}
gulp.task("cloc", gulp.series("clean", cloc));
function combine() {
var outputDirectory = path.join("Build", "CesiumUnminified");
return combineJavaScript({
removePragmas: false,
optimizer: "none",
outputDirectory: outputDirectory,
});
}
gulp.task("combine", gulp.series("build", combine));
gulp.task("default", gulp.series("combine"));
function combineRelease() {
var outputDirectory = path.join("Build", "CesiumUnminified");
return combineJavaScript({
removePragmas: true,
optimizer: "none",
outputDirectory: outputDirectory,
});
}
gulp.task("combineRelease", gulp.series("build", combineRelease));
//Builds the documentation
function generateDocumentation() {
child_process.execSync("npx jsdoc --configure Tools/jsdoc/conf.json", {
stdio: "inherit",
env: Object.assign({}, process.env, { CESIUM_VERSION: version }),
});
var stream = gulp
.src("Documentation/Images/**")
.pipe(gulp.dest("Build/Documentation/Images"));
return streamToPromise(stream);
}
gulp.task("generateDocumentation", generateDocumentation);
gulp.task("generateDocumentation-watch", function () {
return generateDocumentation().done(function () {
console.log("Listening for changes in documentation...");
return gulp.watch(sourceFiles, gulp.series("generateDocumentation"));
});
});
gulp.task(
"release",
gulp.series(
"build",
"build-ts",
combine,
minifyRelease,
generateDocumentation
)
);
gulp.task(
"makeZipFile",
gulp.series("release", function () {
//For now we regenerate the JS glsl to force it to be unminified in the release zip
//See https://github.com/CesiumGS/cesium/pull/3106#discussion_r42793558 for discussion.
glslToJavaScript(false, "Build/minifyShaders.state");
var builtSrc = gulp.src(
[
"Build/Cesium/**",
"Build/CesiumUnminified/**",
"Build/Documentation/**",
],
{
base: ".",
}
);
var staticSrc = gulp.src(
[
"Apps/**",
"!Apps/Sandcastle/gallery/development/**",
"Source/**",
"Specs/**",
"ThirdParty/**",
"favicon.ico",
"gulpfile.cjs",
"server.cjs",
"package.json",
"LICENSE.md",
"CHANGES.md",
"README.md",
"web.config",
],
{
base: ".",
}
);
var indexSrc = gulp
.src("index.release.html")
.pipe(gulpRename("index.html"));
return mergeStream(builtSrc, staticSrc, indexSrc)
.pipe(
gulpTap(function (file) {
// Work around an issue with gulp-zip where archives generated on Windows do
// not properly have their directory executable mode set.
// see https://github.com/sindresorhus/gulp-zip/issues/64#issuecomment-205324031
if (file.isDirectory()) {
file.stat.mode = parseInt("40777", 8);
}
})
)
.pipe(gulpZip("Cesium-" + version + ".zip"))
.pipe(gulp.dest("."));
})
);
gulp.task(
"minify",
gulp.series("build", function () {
return combineJavaScript({
removePragmas: false,
optimizer: "uglify2",
outputDirectory: path.join("Build", "Cesium"),
});
})
);
function minifyRelease() {
return combineJavaScript({
removePragmas: true,
optimizer: "uglify2",
outputDirectory: path.join("Build", "Cesium"),
});
}
gulp.task("minifyRelease", gulp.series("build", minifyRelease));
function isTravisPullRequest() {
return (
process.env.TRAVIS_PULL_REQUEST !== undefined &&
process.env.TRAVIS_PULL_REQUEST !== "false"
);
}
gulp.task("deploy-s3", function (done) {
if (isTravisPullRequest()) {
console.log("Skipping deployment for non-pull request.");
done();
return;
}
var argv = yargs
.usage("Usage: deploy-s3 -b [Bucket Name] -d [Upload Directory]")
.demand(["b", "d"]).argv;
var uploadDirectory = argv.d;
var bucketName = argv.b;
var cacheControl = argv.c ? argv.c : "max-age=3600";
if (argv.confirm) {
// skip prompt for travis
deployCesium(bucketName, uploadDirectory, cacheControl, done);
return;
}
var iface = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
// prompt for confirmation
iface.question(
"Files from your computer will be published to the " +
bucketName +
" bucket. Continue? [y/n] ",
function (answer) {
iface.close();
if (answer === "y") {
deployCesium(bucketName, uploadDirectory, cacheControl, done);
} else {
console.log("Deploy aborted by user.");
done();
}
}
);
});
// Deploy cesium to s3
function deployCesium(bucketName, uploadDirectory, cacheControl, done) {
var readFile = Promise.promisify(fs.readFile);
var gzip = Promise.promisify(zlib.gzip);
var concurrencyLimit = 2000;
var s3 = new AWS.S3({
maxRetries: 10,
retryDelayOptions: {
base: 500,
},
});
var existingBlobs = [];
var totalFiles = 0;
var uploaded = 0;
var skipped = 0;
var errors = [];
var prefix = uploadDirectory + "/";
return listAll(s3, bucketName, prefix, existingBlobs)
.then(function () {
return globby(
[
"Apps/**",
"Build/**",
"Source/**",
"Specs/**",
"ThirdParty/**",
"*.md",
"favicon.ico",
"gulpfile.cjs",
"index.html",
"package.json",
"server.cjs",
"web.config",
"*.zip",
"*.tgz",
],
{
dot: true, // include hidden files
}
);
})
.then(function (files) {
return Promise.map(
files,
function (file) {
var blobName = uploadDirectory + "/" + file;
var mimeLookup = getMimeType(blobName);
var contentType = mimeLookup.type;
var compress = mimeLookup.compress;
var contentEncoding = compress ? "gzip" : undefined;
var etag;
totalFiles++;
return readFile(file)
.then(function (content) {
if (!compress) {
return content;
}
var alreadyCompressed =
content[0] === 0x1f && content[1] === 0x8b;
if (alreadyCompressed) {
console.log(
"Skipping compressing already compressed file: " + file
);
return content;
}
return gzip(content);
})
.then(function (content) {
// compute hash and etag
var hash = crypto.createHash("md5").update(content).digest("hex");
etag = crypto.createHash("md5").update(content).digest("base64");
var index = existingBlobs.indexOf(blobName);
if (index <= -1) {
return content;
}
// remove files as we find them on disk
existingBlobs.splice(index, 1);
// get file info
return s3
.headObject({
Bucket: bucketName,
Key: blobName,
})
.promise()
.then(function (data) {
if (
data.ETag !== '"' + hash + '"' ||
data.CacheControl !== cacheControl ||
data.ContentType !== contentType ||
data.ContentEncoding !== contentEncoding
) {
return content;
}
// We don't need to upload this file again
skipped++;
return undefined;
})
.catch(function (error) {
errors.push(error);
});
})
.then(function (content) {
if (!content) {
return;
}
if (verbose) {
console.log("Uploading " + blobName + "...");
}
var params = {
Bucket: bucketName,
Key: blobName,
Body: content,
ContentMD5: etag,
ContentType: contentType,
ContentEncoding: contentEncoding,
CacheControl: cacheControl,
};
return s3
.putObject(params)
.promise()
.then(function () {
uploaded++;
})
.catch(function (error) {
errors.push(error);
});
});
},
{ concurrency: concurrencyLimit }
);
})
.then(function () {
console.log(
"Skipped " +
skipped +
" files and successfully uploaded " +
uploaded +
" files of " +
(totalFiles - skipped) +
" files."
);
if (existingBlobs.length === 0) {
return;
}
var objectsToDelete = [];
existingBlobs.forEach(function (file) {
//Don't delete generate zip files.
if (!/\.(zip|tgz)$/.test(file)) {
objectsToDelete.push({ Key: file });
}
});
if (objectsToDelete.length > 0) {
console.log("Cleaning " + objectsToDelete.length + " files...");
// If more than 1000 files, we must issue multiple requests
var batches = [];
while (objectsToDelete.length > 1000) {
batches.push(objectsToDelete.splice(0, 1000));
}
batches.push(objectsToDelete);
return Promise.map(
batches,
function (objects) {
return s3
.deleteObjects({
Bucket: bucketName,
Delete: {
Objects: objects,
},
})
.promise()
.then(function () {
if (verbose) {
console.log("Cleaned " + objects.length + " files.");
}
});
},
{ concurrency: concurrency }
);
}
})
.catch(function (error) {
errors.push(error);
})
.then(function () {
if (errors.length === 0) {
done();
return;
}
console.log("Errors: ");
errors.map(function (e) {
console.log(e);
});
done(1);
});
}
function getMimeType(filename) {
var mimeType = mime.getType(filename);
if (mimeType) {
//Compress everything except zipfiles, binary images, and video
var compress = !/^(image\/|video\/|application\/zip|application\/gzip)/i.test(
mimeType
);
if (mimeType === "image/svg+xml") {
compress = true;
}
return { type: mimeType, compress: compress };
}
//Non-standard mime types not handled by mime
if (/\.(glsl|LICENSE|config|state)$/i.test(filename)) {
return { type: "text/plain", compress: true };
} else if (/\.(czml|topojson)$/i.test(filename)) {
return { type: "application/json", compress: true };
} else if (/\.(crn|tgz)$/i.test(filename)) {
return { type: "application/octet-stream", compress: false };
}
// Handle dotfiles, such as .jshintrc
var baseName = path.basename(filename);
if (baseName[0] === "." || baseName.indexOf(".") === -1) {
return { type: "text/plain", compress: true };
}
// Everything else can be octet-stream compressed but print a warning
// if we introduce a type we aren't specifically handling.
if (!/\.(terrain|b3dm|geom|pnts|vctr|cmpt|i3dm|metadata)$/i.test(filename)) {
console.log("Unknown mime type for " + filename);
}
return { type: "application/octet-stream", compress: true };
}
// get all files currently in bucket asynchronously
function listAll(s3, bucketName, prefix, files, marker) {
return s3
.listObjects({
Bucket: bucketName,
MaxKeys: 1000,
Prefix: prefix,
Marker: marker,
})
.promise()
.then(function (data) {
var items = data.Contents;
for (var i = 0; i < items.length; i++) {
files.push(items[i].Key);
}
if (data.IsTruncated) {
// get next page of results
return listAll(s3, bucketName, prefix, files, files[files.length - 1]);
}
});
}
gulp.task("deploy-set-version", function (done) {
var buildVersion = yargs.argv.buildVersion;
if (buildVersion) {
// NPM versions can only contain alphanumeric and hyphen characters
packageJson.version += "-" + buildVersion.replace(/[^[0-9A-Za-z-]/g, "");
fs.writeFileSync("package.json", JSON.stringify(packageJson, undefined, 2));
}
done();
});
gulp.task("deploy-status", function () {
if (isTravisPullRequest()) {
console.log("Skipping deployment status for non-pull request.");
return Promise.resolve();
}
var status = yargs.argv.status;
var message = yargs.argv.message;
var deployUrl = travisDeployUrl + process.env.TRAVIS_BRANCH + "/";
var zipUrl = deployUrl + "Cesium-" + packageJson.version + ".zip";
var npmUrl = deployUrl + "cesium-" + packageJson.version + ".tgz";
var coverageUrl =
travisDeployUrl + process.env.TRAVIS_BRANCH + "/Build/Coverage/index.html";
return Promise.join(
setStatus(status, deployUrl, message, "deployment"),
setStatus(status, zipUrl, message, "zip file"),
setStatus(status, npmUrl, message, "npm package"),
setStatus(status, coverageUrl, message, "coverage results")
);
});
function setStatus(state, targetUrl, description, context) {
// skip if the environment does not have the token
if (!process.env.TOKEN) {
return;
}
var requestPost = Promise.promisify(request.post);
return requestPost({
url:
"https://api.github.com/repos/" +
process.env.TRAVIS_REPO_SLUG +
"/statuses/" +
process.env.TRAVIS_COMMIT,
json: true,
headers: {
Authorization: "token " + process.env.TOKEN,
"User-Agent": "Cesium",
},
body: {
state: state,
target_url: targetUrl,
description: description,
context: context,
},
});
}
gulp.task("coverage", function (done) {
var argv = yargs.argv;
var webglStub = argv.webglStub ? argv.webglStub : false;
var suppressPassed = argv.suppressPassed ? argv.suppressPassed : false;
var failTaskOnError = argv.failTaskOnError ? argv.failTaskOnError : false;
var folders = [];
var browsers = ["Chrome"];
if (argv.browsers) {
browsers = argv.browsers.split(",");
}
var karma = new Karma.Server(
{
configFile: karmaConfigFile,
browsers: browsers,
specReporter: {
suppressErrorSummary: false,
suppressFailed: false,
suppressPassed: suppressPassed,
suppressSkipped: true,
},
preprocessors: {
"Source/Core/**/*.js": ["karma-coverage-istanbul-instrumenter"],
"Source/DataSources/**/*.js": ["karma-coverage-istanbul-instrumenter"],
"Source/Renderer/**/*.js": ["karma-coverage-istanbul-instrumenter"],
"Source/Scene/**/*.js": ["karma-coverage-istanbul-instrumenter"],
"Source/Shaders/**/*.js": ["karma-coverage-istanbul-instrumenter"],
"Source/Widgets/**/*.js": ["karma-coverage-istanbul-instrumenter"],
"Source/Workers/**/*.js": ["karma-coverage-istanbul-instrumenter"],
},
coverageIstanbulInstrumenter: {
esModules: true,
},
reporters: ["spec", "coverage"],
coverageReporter: {
dir: "Build/Coverage",
subdir: function (browserName) {
folders.push(browserName);
return browserName;
},
includeAllSources: true,
},
client: {
captureConsole: verbose,
args: [undefined, undefined, undefined, webglStub, undefined],
},
},
function (e) {
var html = "<!doctype html><html><body><ul>";
folders.forEach(function (folder) {
html +=
'<li><a href="' +
encodeURIComponent(folder) +
'/index.html">' +
folder +
"</a></li>";
});
html += "</ul></body></html>";
fs.writeFileSync("Build/Coverage/index.html", html);
if (!process.env.TRAVIS) {
folders.forEach(function (dir) {
open("Build/Coverage/" + dir + "/index.html");
});
}
return done(failTaskOnError ? e : undefined);
}
);
karma.start();
});
gulp.task("test", function (done) {
var argv = yargs.argv;
var enableAllBrowsers = argv.all ? true : false;
var includeCategory = argv.include ? argv.include : "";
var excludeCategory = argv.exclude ? argv.exclude : "";
var webglValidation = argv.webglValidation ? argv.webglValidation : false;
var webglStub = argv.webglStub ? argv.webglStub : false;
var release = argv.release ? argv.release : false;
var failTaskOnError = argv.failTaskOnError ? argv.failTaskOnError : false;
var suppressPassed = argv.suppressPassed ? argv.suppressPassed : false;
var browsers = ["Chrome"];
if (argv.browsers) {
browsers = argv.browsers.split(",");
}
var files = [
{ pattern: "Specs/karma-main.js", included: true, type: "module" },
{ pattern: "Source/**", included: false, type: "module" },
{ pattern: "Specs/*.js", included: true, type: "module" },
{ pattern: "Specs/Core/**", included: true, type: "module" },
{ pattern: "Specs/Data/**", included: false },
{ pattern: "Specs/DataSources/**", included: true, type: "module" },
{ pattern: "Specs/Renderer/**", included: true, type: "module" },
{ pattern: "Specs/Scene/**", included: true, type: "module" },
{ pattern: "Specs/ThirdParty/**", included: true, type: "module" },
{ pattern: "Specs/Widgets/**", included: true, type: "module" },
{ pattern: "Specs/TestWorkers/**", included: false },
];
if (release) {
files = [
{ pattern: "Specs/Data/**", included: false },
{ pattern: "Specs/ThirdParty/**", included: true, type: "module" },
{ pattern: "Specs/TestWorkers/**", included: false },
{ pattern: "Build/Cesium/Cesium.js", included: true },
{ pattern: "Build/Cesium/**", included: false },
{ pattern: "Build/Specs/karma-main.js", included: true },
{ pattern: "Build/Specs/Specs.js", included: true },
];
}
var karma = new Karma.Server(
{
configFile: karmaConfigFile,
browsers: browsers,
specReporter: {
suppressErrorSummary: false,
suppressFailed: false,
suppressPassed: suppressPassed,
suppressSkipped: true,
},
detectBrowsers: {
enabled: enableAllBrowsers,
},
logLevel: verbose ? Karma.constants.LOG_INFO : Karma.constants.LOG_ERROR,
files: files,
client: {
captureConsole: verbose,
args: [
includeCategory,
excludeCategory,
webglValidation,
webglStub,
release,
],
},
},
function (e) {
return done(failTaskOnError ? e : undefined);
}
);
karma.start();
});
gulp.task("convertToModules", function () {
var requiresRegex = /([\s\S]*?(define|defineSuite|require)\((?:{[\s\S]*}, )?\[)([\S\s]*?)]([\s\S]*?function\s*)\(([\S\s]*?)\) {([\s\S]*)/;
var noModulesRegex = /([\s\S]*?(define|defineSuite|require)\((?:{[\s\S]*}, )?\[?)([\S\s]*?)]?([\s\S]*?function\s*)\(([\S\s]*?)\) {([\s\S]*)/;
var splitRegex = /,\s*/;
var fsReadFile = Promise.promisify(fs.readFile);
var fsWriteFile = Promise.promisify(fs.writeFile);
var files = globby.sync(filesToConvertES6);
return Promise.map(files, function (file) {
return fsReadFile(file).then(function (contents) {
contents = contents.toString();
if (contents.startsWith("import")) {
return;
}