-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgulp-samples.js
More file actions
1182 lines (1029 loc) · 48.4 KB
/
gulp-samples.js
File metadata and controls
1182 lines (1029 loc) · 48.4 KB
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-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unused-vars */
let gulp = require('gulp');
var gulpChangeMod = require('gulp-chmod');
let gulpIgnore = require('gulp-ignore');
let uglify = require('gulp-uglify');
// let gSort = require('gulp-sort');
let rename = require('gulp-rename');
let fs = require('fs.extra');
let path = require('path');
let flatten = require('gulp-flatten');
let del = require('del');
let es = require('event-stream');
var igConfig = require('./gulp-config.js')
eval(require('typescript')
.transpile(require('fs')
.readFileSync("./tasks/Transformer.ts").toString()));
function log(msg) {
console.log('GULP ' + msg);
}
log('loaded gulp scripts');
// NOTE you can comment out strings in this array to run subset of samples
var sampleSource = [
// including specific samples:
// igConfig.SamplesCopyPath + '/charts/category-chart/axis-gap/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/multi-row-dragging/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/action-strip/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/column*/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/editing-events/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/**/App.razor',
// including samples for all components:
igConfig.SamplesCopyPath + '/**/App.razor',
// including samples for specific components:
// igConfig.SamplesCopyPath + '/charts/category-chart/**/App.razor',
// igConfig.SamplesCopyPath + '/charts/data-chart/**/App.razor',
// igConfig.SamplesCopyPath + '/charts/doughnut-chart/**/App.razor',
// igConfig.SamplesCopyPath + '/charts/financial-chart/**/App.razor',
// igConfig.SamplesCopyPath + '/charts/pie-chart/**/App.razor',
// igConfig.SamplesCopyPath + '/charts/sparkline/**/App.razor',
// igConfig.SamplesCopyPath + '/charts/tree-map/**/App.razor',
// igConfig.SamplesCopyPath + '/charts/zoomslider/**/App.razor',
// igConfig.SamplesCopyPath + '/maps/geo-map/**/App.razor',
// igConfig.SamplesCopyPath + '/gauges/bullet-graph/**/App.razor',
// igConfig.SamplesCopyPath + '/gauges/linear-gauge/**/App.razor',
// igConfig.SamplesCopyPath + '/gauges/radial-gauge/**/App.razor',
// igConfig.SamplesCopyPath + '/grids/data-grid/**/App.razor',
// igConfig.SamplesCopyPath + '/grids/list/**/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/**/App.razor',
// igConfig.SamplesCopyPath + '/grids/tree-grid/**/App.razor',
// igConfig.SamplesCopyPath + '/grids/tree/**/App.razor',
// igConfig.SamplesCopyPath + '/grids/pivot-grid/**/App.razor',
// igConfig.SamplesCopyPath + '/editors/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/badge/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/button/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/checkbox/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/chip/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/circular-progress-indicator/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/combo/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/date-time-input/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/dropdown/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/form/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/icon-button/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/input/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/linear-progress-indicator/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/radio/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/ripple/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/select/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/slider/**/App.razor',
// igConfig.SamplesCopyPath + '/inputs/switches/**/App.razor',
// igConfig.SamplesCopyPath + '/layouts/accordion/**/App.razor',
// igConfig.SamplesCopyPath + '/layouts/avatar/**/App.razor',
// igConfig.SamplesCopyPath + '/layouts/card/**/App.razor',
// igConfig.SamplesCopyPath + '/layouts/expansion-panel/**/App.razor',
// igConfig.SamplesCopyPath + '/layouts/dock-manager/**/App.razor',
// igConfig.SamplesCopyPath + '/layouts/icon/**/App.razor',
// igConfig.SamplesCopyPath + '/layouts/stepper/**/App.razor',
// igConfig.SamplesCopyPath + '/layouts/tabs/**/App.razor',
// igConfig.SamplesCopyPath + '/menus/**/App.razor',
// igConfig.SamplesCopyPath + '/scheduling/**/App.razor',
// igConfig.SamplesCopyPath + '/notifications/**/App.razor',
// igConfig.SamplesCopyPath + '/excel/excel-library/**/App.razor',
// igConfig.SamplesCopyPath + '/excel/spreadsheet/**/App.razor',
// igConfig.SamplesCopyPath + '/gauges/bullet-graph/animation/App.razor',
// igConfig.SamplesCopyPath + '/grids/**/binding-live-data/App.razor',
// igConfig.SamplesCopyPath + '/grids/**/overview/App.razor',
// igConfig.SamplesCopyPath + '/grids/**/column-types/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/advanced-filtering-options/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/styling-custom-css/App.razor',
// "!" + igConfig.SamplesCopyPath + '/**/Program.cs',
"!" + igConfig.SamplesCopyPath + '/**/obj/**',
"!" + igConfig.SamplesCopyPath + '/**/bin/**',
// "!" + igConfig.SamplesCopyPath + '/**/_Imports.razor',
// "!" + igConfig.SamplesCopyPath + '/**/wwwroot/index.html',
// "!" + igConfig.SamplesCopyPath + '/**/wwwroot/index.css',
];
// this variable stores detailed information about all samples in ./samples/ folder
var samples = [];
var sampleOutputFolder = '';
function cleanSamples() {
// cleaning up obsolete files in individual samples
// del.sync("../../samples/**/src/sandbox.config.json", {force:true});
// del.sync("../../samples/**/manifest.json", {force:true});
del.sync("../../samples/**/css/open-iconic/README.md", {force:true});
}
// lints all source files in ./samples folder and remove any routing paths (@page)
// since they are auto-generated when samples are copied to browsers
function lintSamples(cb) {
for (const info of samples) {
Transformer.lintSample(info, false)
}
cb();
} exports.lintSamples = lintSamples;
// lints only .razor files in ./samples folder and remove any routing paths (@page)
// since they are auto-generated when samples are copied to browsers
function lintRazorFiles(cb) {
for (const info of samples) {
Transformer.lintRazor(info, false)
}
cb();
} exports.lintRazorFiles = lintRazorFiles;
function saveSamples(cb) {
for (const info of samples) {
if (info.SourceRazorFile &&
info.SourceRazorFile.Path &&
info.SourceRazorFile.Content) {
// log('saving ' + info.SourceRazorFile.Path)
fs.writeFileSync(info.SourceRazorFile.Path, info.SourceRazorFile.Content);
}
}
cb();
} exports.saveSamples = saveSamples;
function getSamples(cb) {
var deferredSamples = [
igConfig.SamplesCopyPath + '/charts/data-chart/itemized-bar-chart/App.razor',
igConfig.SamplesCopyPath + '/charts/data-chart/itemized-column-chart/App.razor',
igConfig.SamplesCopyPath + '/charts/data-chart/itemized-stacked-bar-chart/App.razor',
igConfig.SamplesCopyPath + '/charts/data-chart/itemized-stacked-column-chart/App.razor',
// excluding bugged samples:
igConfig.SamplesCopyPath + '/grids/tree-grid/editing-columns/App.razor', // BUG https://github.com/IgniteUI/igniteui-blazor-examples/issues/423
igConfig.SamplesCopyPath + '/grids/grid/custom-context-menu/App.razor', // BUG https://github.com/IgniteUI/igniteui-blazor-examples/issues/420
// excluding deferred gird samples
igConfig.SamplesCopyPath + '/grids/grid/toolbar-style/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/advanced-filtering-style/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/binding-nested-data-2/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/column-hiding-styles/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/column-moving-styles/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/column-pinning-styles/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/column-resize-styling/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/column-selection-styles/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/conditional-cell-style-2/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/data-exporting-indicator/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/data-performance-infinite-scroll/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/data-performance-operations/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/data-performance-summary/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/data-persistence-state/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/data-summary-custom-selection/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/editing-styles/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/excel-style-filtering-sample-1/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/excel-style-filtering-sample-2/App.razor',
// igConfig.SamplesCopyPath + '/grids/grid/excel-style-filtering-sample-3/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/excel-style-filtering-style/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/external-excel-style-filtering/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/filtering-style/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/filtering-template/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/keyboard-custom-navigation/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/multi-column-headers-styling/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/remote-filtering-data/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/remote-paging-batch-editing/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/remote-paging-custom/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/remote-paging-template/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/row-classes/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/row-drop-indicator/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/row-editing-style/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/row-paging-style/App.razor',
igConfig.SamplesCopyPath + '/grids/grid/row-pinning-style/App.razor/App.razor',
];
samples = [];
console.log(deferredSamples[0]);
gulp.src(sampleSource)
// .pipe(gSort( { asc: false } ))
.pipe(es.map(function(sample, sampleCallback) {
// console.log('Sample: ' + sample.dirname);
let sampleFolder = Transformer.getRelative(sample.dirname);
// console.log('SampleFolder: ' + sampleFolder);
let samplePath = sampleFolder + '/' + sample.basename;
// console.log('SamplePath: ' + samplePath);
// skip samples that were deferred
if (deferredSamples.includes(samplePath)) {
sampleCallback(null, sample);
} else {
// console.log("get " + samplePath);
let sampleFiles = [];
gulp.src([
// sampleFolder + "/Pages/*",
sampleFolder + "/App.razor",
sampleFolder + "/Components/*",
sampleFolder + "/**/*.cs",
sampleFolder + "/*.csproj",
sampleFolder + "/wwwroot/*.js",
sampleFolder + "/wwwroot/*.css",
sampleFolder + "/wwwroot/index.html",
// sampleFolder + "/wwwroot/*",
// '!' + sampleFolder + "/wwwroot/index.html",
// '!' + sampleFolder + "/wwwroot/index.css",
// '!' + sampleFolder + "/Pages/_*.razor",
// '!' + sampleFolder + "/Pages/DataGridBindingLiveData.razor",
'!' + sampleFolder + "/Pages/*.g.cs",
'!' + sampleFolder + "/_Imports.razor",
// '!' + sampleFolder + "/Program.cs", // not excluded b/c we need to get names of IG modules
'!' + sampleFolder + "/obj/**",
'!' + sampleFolder + "/obj/*.*",
'!' + sampleFolder + "/bin/**",
'!' + sampleFolder + "/bin/*.*",])
.pipe(flatten({ "includeParents": -1 }))
.pipe(es.map(function(file, fileCallback) {
let fileDir = Transformer.getRelative(file.dirname);
console.log('PipeFildir: ' + fileDir);
sampleFiles.push(fileDir + "/" + file.basename);
// console.log("get file " + fileDir + "/" + file.basename);
fileCallback(null, file);
}))
.on("end", function() {
// log(sampleFolder);
let sampleInfo = Transformer.getSampleInfo(sample, sampleFiles);
if (sampleInfo !== null) {
samples.push(sampleInfo);
}
sampleCallback(null, sample);
});
}
}))
.on("end", function() {
Transformer.sort(samples);
Transformer.process(samples);
Transformer.verify(samples);
// Transformer.print(samples);
log('getSamples() found ' + samples.length + " samples");
// for (const sample of samples) {
// log(' ' + sample.SampleFolderPath);
// }
// let last = samples[samples.length - 1];
// log('package name ' + last.PackageFileContent.name);
// last.PackageDependencies = Transformer.getDependencies(last);
// log('packages \n' + last.PackageFileContent.dependencies);
// log('dependencies: \n' + last.PackageDependencies);
cb();
});
} exports.getSamples = getSamples;
function makeDirectoryFor(filePath) {
var dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
return true;
}
makeDirectoryFor(dirname);
fs.mkdirSync(dirname);
// fs.mkdir(sampleOutputFolder + 'src', { recursive: true }, (err) => { if (err) throw err; });
}
function makeSamplesWritable(cb) {
gulp.src(sampleSource)
.pipe(gulpChangeMod(666))
.pipe(gulp.dest(sampleSource))
.on("end", function() {
cb();
});
} exports.makeSamplesWritable = makeSamplesWritable;
function exclude(fileWithString) {
return es.map(function(file, cb) {
if (file.basename.indexOf(fileWithString) >= 0 ||
file.dirname.indexOf(fileWithString) >= 0) {
// log('- share data ' + file.basename);
cb(null);
} else {
// log('+ share data ' + file.basename);
cb(null, file);
}
});
}
function cleanupSampleBrowser(outputPath) {
log('cleaning up files in ' + outputPath);
del.sync([
outputPath + "/wwwroot/code-viewer/**/*.json", // auto-generated code-viewer .json files
outputPath + "/wwwroot/sb/*.js", // auto-copied sample's .js files
outputPath + "/Services/*.*", // auto-copied data files
outputPath + "/Components/**", // auto-copied sample's .razor components
outputPath + "/Pages/**/*.*", // auto-copied samples
outputPath + "/Pages/**", // auto-copied folders
"!" + outputPath + "/Pages/_*.razor", // e.g. _Home.razor
"!" + outputPath + "/Pages/_*.cshtml" // e.g. _Host.cshtml
], { force: true });
}
function cleanupSampleBrowsers(cb) {
cleanupSampleBrowser( "../../browser/IgBlazorSamples.Client");
cleanupSampleBrowser( "../../browser/IgBlazorSamples.Server");
cb();
} exports.cleanupSampleBrowsers = cleanupSampleBrowsers;
function saveFile(filePath, fileContent) {
makeDirectoryFor(filePath);
// if (!fs.existsSync(outputClientRazor)) {
fs.writeFileSync(filePath, fileContent);
// console.log("copied " + filePath);
}
function copySamplePages(cb, outputPath) {
log('copying sample to ' + outputPath + '/Pages/*.* from /samples/**/app.razor files:');
for (const sample of samples) {
let sampleFolder = sample.ComponentGroup + '/' + sample.ComponentFolder + '/' + sample.SampleFolderName;
log("copying sample to " + outputPath + '/Pages/' + sampleFolder + '/App.razor');
// lint and force auto-generation of routing paths (@page) in razor files
Transformer.lintSample(sample, true);
// outputFolder = Strings.toTitleCase(outputClient);
// let dataFiles = [];
for (const file of sample.SourceFiles) {
// console.log(" file.Name=" + file.Path);
if (file.isRazorFile()) {
var copyTarget = outputPath + '/Pages/' + sampleFolder + '/' + file.Parent + '/' + file.Name;
// log("copying sample to " + copyTarget);
saveFile(copyTarget, file.Content);
} else if (file.Name.indexOf("Program.cs") >= 0) {
continue;
} else if (file.isCS()) {
saveFile(outputPath + '/Services/' + file.Name, file.Content);
sample.DataFilesCount++;
if (file.Name.indexOf("DataGenerator") >= 0) {
// dataFiles.push('../samples/' + sampleFolder + '/' + file.Parent + '/' + file.Name);
}
} else {
// log("WARNING unknown source file: " + file.Path);
throw new Error("ERROR unknown source file: " + file.Path);
}
}
// if (dataFiles.length > 1) {
// console.log(dataFiles);
// }
}
log('TOC generating with routing paths for samples');
let routingGroups = Transformer.getRoutingGroups(samples);
let routingFile = Transformer.getRoutingFile(routingGroups);
log('TOC generating ' + outputPath + '/wwwroot/toc.json');
saveFile(outputPath + '/wwwroot/toc.json', routingFile);
cb();
}
function copySampleScripts(cb, outputPath, indexName) {
var insertScriptFiles = [];
log('deleting scripts in: ' + outputPath + '/wwwroot/sb/*.js');
del.sync('../IgBlazorSamples.Client/wwwroot/sb/' + "*.js", {force:true});
log('copying scripts to: ' + outputPath + '/wwwroot/sb/*.js');
var copiedScriptFiles = [];
for (const sample of samples) {
//console.log(sample);
var fileIndex = 0;
var fileSuffix = "";
for (const file of sample.PublicFiles_JS) {
var fileName = sample.ComponentFolder + "-" + sample.SampleFolderName + fileSuffix + ".js";
fileIndex = fileIndex + 1;
fileSuffix = fileIndex;
var scriptPath = outputPath + '/wwwroot/sb/' + fileName
// log("-copying scripts to: " + scriptPath);
if (copiedScriptFiles.indexOf(fileName) === -1) {
copiedScriptFiles.push(fileName);
log("copying scripts to: " + scriptPath);
// console.log("copySampleScripts " + scriptName);
saveFile(scriptPath, file.Content);
if (file.Name.indexOf("DockManager") >= 0) {
var fileRequiresLoading = true;
if (file.Name.indexOf("bundle") >= 0) {
// skipping non-entry point bundle files for DockManager
if (file.Name.indexOf("1") >= 0) fileRequiresLoading = false;
if (file.Name.indexOf("2") >= 0) fileRequiresLoading = false;
if (file.Name.indexOf("3") >= 0) fileRequiresLoading = false;
}
if (fileRequiresLoading) {
insertScriptFiles.push('<script src="sb/' + fileName + '"></script>');
}
} else {
insertScriptFiles.push('<script src="sb/' + fileName + '"></script>');
}
}
}
}
// sorting inserts
//insertScriptFiles.sort((a, b) => a > b ? 1 : -1)
// updating index.html with JavaScripts for samples
let indexPath = outputPath + indexName;
log('updating ' + indexPath);
let indexFile = fs.readFileSync(indexPath).toString();
let indexLines = indexFile.split('\n');
let insertStart = -1;
let insertEnd = -1;
for (let i = 0; i < indexLines.length; i++) {
let line = indexLines[i];
if (line.indexOf("<!--AutoInsertJavaScriptsForSamples Start-->") > 0) {
insertStart = i;
}
else if (line.indexOf("<!--AutoInsertJavaScriptsForSamples End-->") > 0) {
insertEnd = i;
}
}
if (insertStart < 0 ) {
throw new Error("File '" + indexPath + "' is missing: '<!--AutoInsertJavaScriptsForSamples Start-->'");
}
else if (insertEnd < 0 ) {
throw new Error("File '" + indexPath + "' is missing: '<!--AutoInsertJavaScriptsForSamples End-->'");
}
else if (insertStart > 0 && insertEnd > 0) {
for (let i = insertStart+1; i < insertEnd; i++) {
if (indexLines[i].indexOf("AutoInsertJavaScriptsForSamples") < 0)
indexLines[i] = ""; // clearing previously auto-generated inserts for JS files
}
// for (let i = insertEnd - 1; i > insertStart+1; i--) {
// indexLines.splice(i, 1);
// }
// adding latest auto-generated inserts for JS files
indexLines[insertStart] += '\n' + insertScriptFiles.join('\n');
}
// indexLines = indexLines.filter((v, i, a) => a.indexOf(v) === i);
var isLocalBuild = __dirname.indexOf('Agent') < 0;
for (let i = 0; i < indexLines.length; i++) {
if (indexLines[i].indexOf('<base href') > 0) {
if (isLocalBuild) {
log('updating <base href="/" /> ');
indexLines[i] = ' <base href="/" />';
} else {
log('updating <base href="/blazor-client/" /> ');
indexLines[i] = ' <base href="/blazor-client/" />';
}
break;
}
}
log('is local build = ' + isLocalBuild + ' ' + __dirname);
index = indexLines.join('\n');
while (index.indexOf('\n\n') >= 0) {
index = index.split('\n\n').join('\n');
}
fs.writeFileSync(indexPath, index);
// cb();
}
// '../../browser/IgBlazorSamples.Server/Pages'
// '../../browser/IgBlazorSamples.Server/Services'
// '../../browser/IgBlazorSamples.Server/wwwroot'
function copySamplesToServer(cb) {
cleanupSampleBrowser( "../../browser/IgBlazorSamples.Server");
copySampleScripts(cb, "../../browser/IgBlazorSamples.Server", "/Pages/_Host.cshtml");
copySamplePages(cb, "../../browser/IgBlazorSamples.Server");
} exports.copySamplesToServer = copySamplesToServer;
// '../../browser/IgBlazorSamples.Client/Pages'
// '../../browser/IgBlazorSamples.Client/Services'
// '../../browser/IgBlazorSamples.Client/wwwroot'
function copySamplesToClient(cb) {
cleanupSampleBrowser( "../../browser/IgBlazorSamples.Client");
copySampleScripts(cb, "../../browser/IgBlazorSamples.Client", "/wwwroot/index.html");
copySamplePages(cb, "../../browser/IgBlazorSamples.Client");
} exports.copySamplesToClient = copySamplesToClient;
function updateReadme(cb) {
// log('updating readme files... ');
var template = fs.readFileSync("../../templates/sample/ReadMe.md", "utf8");
for (const sample of samples) {
if (sample.SourceFiles !== undefined &&
sample.SourceFiles.length > 0) {
// let outputPath = sampleOutputFolder + '/' + sample.SampleFolderPath;
let outputPath = sampleOutputFolder + sample.SampleFolderPath + "/ReadMe.md";
makeDirectoryFor(outputPath);
log("updating " + outputPath);
let readmeFile = Transformer.updateReadme(sample, template);
fs.writeFileSync(outputPath, readmeFile);
// break;
}
}
cb();
} exports.updateReadme = updateReadme;
// updating .csproj files for all samples using a template project
function updateProjects(cb) {
// del.sync("../../samples/**/css/open-iconic/README.md", {force:true});
// del.sync("../../samples/**/css/open-iconic/BlazorClientApp.sln", {force:true});
// del.sync("../../samples/**/css/open-iconic/BlazorClientApp.csproj", {force:true});
// del.sync("../../samples/**/css/open-iconic/_Imports.razor", {force:true});
// del.sync("../../samples/**/css/open-iconic/Program.cs", {force:true});
// del.sync("../../samples/**/css/open-iconic/wwwroot", {force:true});
// del.sync("../../samples/**/css/open-iconic/Properties", {force:true});
// getting content of Project file from templates
let templateProject = fs.readFileSync("../../templates/sample/BlazorClientApp.csproj");
gulp.src(["../../samples/**/*.csproj"])
// .pipe(flatten({ "includeParents": -1 }))
.pipe(es.map(function(file, fileCallback) {
let fileDir = Transformer.getRelative(file.dirname);
if (file.dirname.indexOf("wwwroot") > 0 ||
file.dirname.indexOf("Pages") > 0 ||
file.dirname.indexOf("Services") > 0) {
log("ERROR invalid project location: " + file.dirname)
} else {
let filePath = fileDir + "/" + file.basename;
// let filePath = file.dirname + "/" + file.basename;
let oldContent = file.contents.toString();
var newContent = templateProject + '';
if (newContent !== oldContent) {
fs.writeFileSync(filePath, newContent);
log('updated project: ' + filePath);
// file.contents = new Buffer(newContent);
}
}
// send the updated file down the pipe
fileCallback(null, file);
}))
.on("end", function() {
cb();
});
} exports.updateProjects = updateProjects;
// updating IG blazor versions in .csproj files for all samples
function updateIG(cb) {
// NOTE: change this array with new version of packages
let packageUpgrades = [
// these IG packages are often updated:
{ name: "IgniteUI.Blazor.Trial" , version: "23.1.33" },
{ name: "IgniteUI.Blazor.Documents.Core.Trial", version: "23.1.33" },
{ name: "IgniteUI.Blazor.Documents.Excel.Trial", version: "23.1.33" },
// these IG packages are sometimes updated:
{ name: "Microsoft.AspNetCore.Components", version: "6.0.0" },
{ name: "Microsoft.AspNetCore.Components.Web", version: "6.0.0" },
{ name: "Microsoft.AspNetCore.Components.WebAssembly", version: "6.0.0" },
{ name: "Microsoft.AspNetCore.Components.WebAssembly.DevServer", version: "6.0.0" }, // suffix: 'PrivateAssets="all" ' },
{ name: "Microsoft.AspNetCore.Cors", version: "2.2.0" },
{ name: "Microsoft.AspNetCore.Http.Abstractions", version: "2.2.0" },
{ name: "System.Net.Http.Json", version:"6.0.0" },
];
// creating package mapping for quick lookup
let packageMappings = {};
for (const item of packageUpgrades) {
item.id = item.name;
let name = item.name;
packageMappings[name] = item;
}
let updatedPackages = 0; // NOTE you can comment out strings in this array to run these function only on a subset of samples
var packagePaths = [
'../../browser/**/*.csproj', // browser
'../../samples/**/*.csproj',
// '../../samples/charts/**/*.csproj',
// '../../samples/editors/**/*.csproj',
// '../../samples/excel/**/*.csproj',
// '../../samples/gauges/**/*.csproj',
// '../../samples/grids/**/*.csproj',
// '../../samples/inputs/**/*.csproj',
// '../../samples/layouts/**/*.csproj',
// '../../samples/maps/**/*.csproj',
// '../../samples/menus/**/*.csproj',
// '../../samples/notifications/**/*.csproj',
// '../../samples/scheduling/**/*.csproj',
// '../samples/charts/category-chart/**/*.csproj',
// '../samples/maps/geo-map/type-scatter-bubble-series/*.csproj',
'!../../samples/**/node_modules/**/*.csproj',
];
gulp.src(packagePaths)
// .pipe(flatten({ "includeParents": -1 }))
.pipe(es.map(function(file, fileCallback) {
let filePath = file.dirname + "/" + file.basename;
var fileContent = file.contents.toString();
var fileLines = fileContent.split('\n');
// log("updating: " + filePath);
var fileChanged = false;
for (let i = 0; i < fileLines.length; i++) {
const line = fileLines[i];
// <PackageReference Include="IgniteUI.Blazor.Documents.Excel.Trial" Version="22.1.46" />
let words = line.split("Version=");
if (words.length === 2 && words[0].indexOf('PackageReference') > 0) {
// matching packages
let packageName = words[0].replace("<PackageReference", "").replace("Include=", "").split('"').join('').trim();
let packageInfo = packageMappings[packageName];
if (packageInfo !== undefined) {
let tabString = line.indexOf(' ') >= 0 ? ' ': ' ';
let newLine = tabString + '<PackageReference Include="' + packageInfo.name + '" Version="' + packageInfo.version + '" ';
if (packageInfo.suffix) {
newLine += packageInfo.suffix;
}
newLine += '/>';
if (fileLines[i].trim() !== newLine.trim()) {
fileLines[i] = newLine;
fileChanged = true;
}
}
}
}
if (fileChanged) {
let newContent = fileLines.join('\n'); // newContent !== fileContent
updatedPackages++;
fs.writeFileSync(filePath, newContent);
log("updated: " + filePath);
}
// let filePath = fileDir + "/" + file.basename;
// // let filePath = file.dirname + "/" + file.basename;
// let oldContent = file.contents.toString();
// var newContent = templateProject + '';
// if (newContent !== oldContent) {
// fs.writeFileSync(filePath, newContent);
// log('updated project: ' + filePath);
// // file.contents = new Buffer(newContent);
// }
// cb();
// send the updated file down the pipe
fileCallback(null, file);
}))
.on("end", function() {
log("updateIG... done = " + updatedPackages + " files");
cb();
});
} exports.updateIG = updateIG;
// updates ./public/meta.json with version in ./package.json file
function updateVersion(cb) {
const appPackage = require('../package.json');
const appVersion = appPackage.version;
const jsonData = { version: appVersion, note: "this file is auto-generated" };
const jsonContent = JSON.stringify(jsonData);
const jsonPublicFile = './public/meta.json';
fs.writeFile(jsonPublicFile, jsonContent, 'utf8', function(err) {
if (err) {
console.log('gulp cannot update ' + jsonPublicFile + ' file: \n' + err);
return console.log(err);
}
console.log('gulp updated ' + jsonPublicFile + ' file with latest version number');
});
const jsonSourceFile = './src/CacheApp.json';
fs.writeFile(jsonSourceFile, jsonContent, 'utf8', function(err) {
if (err) {
console.log('gulp cannot update ' + jsonSourceFile + ' file: \n' + err);
return console.log(err);
}
console.log('gulp updated ' + jsonSourceFile + ' file with latest version number');
});
cb();
} exports.updateVersion = updateVersion;
function updateIndex(cb) {
var template = fs.readFileSync("../../templates/sample/src/index.tsx", "utf8");
for (const sample of samples) {
let outputPath = sampleOutputFolder + sample.SampleFolderPath + "/src/index.tsx";
let oldIndexFile = fs.readFileSync(outputPath).toString();
makeDirectoryFor(outputPath);
let newIndexFile = Transformer.updateIndex(sample, template);
if (newIndexFile !== oldIndexFile) {
// log('updated: ' + outputPath);
fs.writeFileSync(outputPath, newIndexFile);
}
// fs.mkdir(sampleOutputFolder + 'src', { recursive: true }, (err) => { if (err) throw err; });
// fs.writeFileSync(outputPath, indexFile);
// break;
}
cb();
} exports.updateIndex = updateIndex;
function updateSharedFiles(cb) {
// always override these shared files
gulp.src([
'../../templates/sample/wwwroot/index.css',
// '../../templates/sample/src/react-app-env.d.ts',
// '../../templates/sample/sandbox.config.json',
// '../../templates/sample/tsconfig.json',
// '../../templates/sample/.gitignore',
// '../../templates/sample/.eslintrc.js',
])
.pipe(flatten({ "includeParents": -1 }))
.pipe(es.map(function(file, fileCallback) {
let sourceContent = file.contents.toString();
let sourcePath = Transformer.getRelative(file.dirname);
sourcePath = sourcePath.replace('../../templates/sample', '');
for (const sample of samples) {
// if (sample.isUsingFileName(file.basename)) {
let samplePath = sampleOutputFolder + sample.SampleFolderPath;
let targetPath = samplePath + sourcePath + '/' + file.basename;
if (fs.existsSync(targetPath)) {
let targetContent = fs.readFileSync(targetPath, "utf8");
if (sourceContent !== targetContent) {
fs.writeFileSync(targetPath , sourceContent);
log('updated ' + targetPath);
}
} else {
fs.writeFileSync(targetPath, sourceContent);
log('added ' + targetPath);
}
}
fileCallback(null, file);
// SourceFiles.push(fileDir + "/" + file.basename);
}))
.on("end", function() {
cb();
});
} exports.updateSharedFiles = updateSharedFiles;
function updateDataFiles(cb) {
// update these shared files if a sample is using them
gulp.src(['../../templates/sample/Services/*.*'])
// gulp.src([
// '../../templates/sample/Services/EnergyRenewableData.cs',
// '../../templates/sample/Services/SharedExcelData.cs',
// ])
.pipe(flatten({ "includeParents": -1 }))
.pipe(es.map(function(file, fileCallback) {
let sourceContent = file.contents.toString();
let sourcePath = Transformer.getRelative(file.dirname);
sourcePath = sourcePath.replace('../../templates/sample', '');
for (const sample of samples) {
if (sample.isUsingFileName(file.basename)) {
let samplePath = sampleOutputFolder + sample.SampleFolderPath;
let targetPath = samplePath + sourcePath + '/' + file.basename;
if (fs.existsSync(targetPath)) {
let targetContent = fs.readFileSync(targetPath, "utf8");
if (sourceContent !== targetContent) {
fs.writeFileSync(targetPath , sourceContent);
log('updated ' + targetPath);
}
} else {
// fs.writeFileSync(targetPath, sourceContent);
// log('added ' + targetPath);
}
// let targetPath = sampleOutputFolder + sample.SampleFolderPath + '/src/' + file.basename;
// let targetContent = fs.readFileSync(targetPath, "utf8");
// if (sourceContent !== targetContent) {
// fs.writeFileSync(targetPath, sourceContent);
// // log('updated ' + file.basename + ' in ' + sample.SampleFilePath)
// log('updated ' + targetPath);
// }
}
}
fileCallback(null, file);
}))
.on("end", function() {
cb();
});
} exports.updateDataFiles = updateDataFiles;
// testing functions
function logRoutes(cb) {
let routes = [];
for (const sample of samples) {
// routes.push("/" + sample.SampleGroup + "/" + sample.SampleRoutePath)
routes.push(sample.SampleRoute)
}
routes.sort();
for (const route of routes) {
console.log(route);
}
cb();
} exports.logRoutes = logRoutes;
function logFile() {
return es.map(function(file, cb) {
let relative = Transformer.getRelative(file.dirname);
log(relative + '/' + file.basename);
// log(path.relative(path.join(file.cwd, file.base), file.path))
cb(null, file);
});
}
function logPublicFiles(cb) {
gulp.src([
'./samples/**/public/*.*',
])
.pipe(logFile())
.on("end", function() { cb(); });
} exports.logPublicFiles = logPublicFiles;
function logSourceFiles(cb) {
gulp.src([
'./samples/**/src/*.ts',
'!./samples/**/src/index.*',
])
.pipe(logFile())
.on("end", function() { cb(); });
} exports.logSourceFiles = logSourceFiles;
function logRootFiles(cb) {
gulp.src([
'./samples/**/*.*',
'!./samples/**/src/*.*',
'!./samples/**/*.tsx',
'!./samples/**/*.ts',
'!./samples/**/*.css',
'!./samples/**/index.*',
'!./samples/**/manifest.json',
'!./samples/**/package.json',
'!./samples/**/tsconfig.json',
])
.pipe(es.map(function(file, cbFile) {
let relative = Transformer.getRelative(file.dirname);
log(file.basename + ' ' + relative + '/' + file.basename);
cbFile(null, file);
}))
.on("end", function() { cb(); });
} exports.logRootFiles = logRootFiles;
function logUniqueFiles(cb) {
let fileNames = [];
gulp.src([
'./samples/**/src/*.ts',
'!./samples/**/src/index.*',
])
.pipe(es.map(function(file, cbFile) {
if (fileNames.indexOf(file.basename) === -1) {
fileNames.push(file.basename);
}
cbFile(null, file);
}))
.on("end", function() {
fileNames.sort();
for (const name of fileNames) {
log(name);
}
cb();
});
} exports.logUniqueFiles = logUniqueFiles;
function logSandboxUrls(cb) {
for (const sample of samples) {
console.log("" + sample.SandboxUrlShort);
}
cb();
} exports.logSandboxUrls = logSandboxUrls;
function copyTemplates(cb) {
// del.sync("../../samples/**/.gitignore", {force:true});
var sampleSource = [
// '../../samples/charts/category-chart/**/*.md',
// '../../samples/charts/data-chart/**/*.md',
// '../../samples/charts/doughnut-chart/**/*.md',
// '../../samples/charts/financial-chart/**/*.md',
// '../../samples/charts/pie-chart/**/*.md',
// '../../samples/charts/sparkline/**/*.md',
// '../../samples/charts/tree-map/**/*.md',
// '../../samples/charts/zoomslider/**/*.md',
// '../../samples/maps/**/*.md',
'../../samples/gauges/bullet-graph/**/*.md',
'../../samples/gauges/linear-gauge/**/*.md',
'../../samples/gauges/radial-gauge/**/*.md',
// '../../samples/grids/**/*.md',
'../../samples/layouts/**/*.md',
// excluding *.md in node_modules sub folders
// '../../samples/excel/excel-library/**/*.md',
// '../../samples/excel/spreadsheet/**/*.md',
"!" + '/**/node_modules/**/*.md',
];
var sampleLocations = [];
// del.sync("./sample-test-files/**/*.*", {force:true});
gulp.src(sampleSource)
// .pipe(gSort( { asc: false } ))
.pipe(es.map(function(sampleFile, sampleCallback) {
// let sampleFolder = '../.' + Transformer.getRelative(sampleFile.dirname);
let sampleFolder = Transformer.getRelative(sampleFile.dirname);
// console.log('copyTemplates ' + sampleFile.dirname + ' ' + sampleFile.basename);
// log('copyTemplates ' + sampleFile.dirname + ' ' + sampleFolder);
// // log(sampleFolder);
sampleLocations.push(sampleFolder);
// let sampleFiles = [];
// gulp.src([sampleFolder + "/**"])
// .pipe(flatten({ "includeParents": -1 }))
// // .pipe(gSort( { asc: false } ))
// .pipe(es.map(function(file, fileCallback) {
// console.log('getSamples ' + file.basename);
// // let fileDir = Transformer.getRelative(file.dirname);
// // sampleFiles.push(fileDir + "/" + file.basename);
// fileCallback(null, file);
// }))
// .on("end", function() {
// // log(sampleFolder);
// // let sampleInfo = Transformer.getSampleInfo(samplePackage, sampleFiles);
// // samples.push(sampleInfo);
// sampleCallback(null, sampleFile);
// });
sampleCallback(null, sampleFile);
}))
.on("end", function() {
// Transformer.sort(samples);
// Transformer.process(samples);
// console.log('copyTemplates found ' + sampleLocations.length + " samples");
// .pipe(gulp.dest('../samples/charts/category-chart/annotations'))
for (const location of sampleLocations) {
console.log('copyTemplates to ' + location);
gulp.src([
// '../../templates/sample/**',
'../../templates/sample/**/*',
// '../../templates/sample/.gitignore',
// '../../templates/sample/.gitignore',
// '../../templates/sample/wwwroot/*.*',
// '../../templates/sample/Properties/*.*'
]) // , { base: 'sample' }
// .pipe(es.map(function(templateFile, templateCallback) {
// let templateFolder = '.' + Transformer.getRelative(templateFile.dirname);
// console.log('updateSamples found ' + templateFolder + " " + templateFile.basename);
// templateCallback(null, templateFile);
// }))
.pipe(gulp.dest(location))
}
console.log('copyTemplates to ' + sampleLocations.length + " samples");
// let last = samples[samples.length - 1];