-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbrowser.js
More file actions
1415 lines (1209 loc) · 59.9 KB
/
browser.js
File metadata and controls
1415 lines (1209 loc) · 59.9 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
// this file should contain functions for:
// - copying repo/samples folder to repo/browser/samples folder
// - generating code-viewer json files
// - generating /src/app/app-routing.module.ts
// - generating routing and modules for each group of controls, e.g.
// /src/samples/charts/charts-routes-data.ts
// /src/samples/charts/charts-routing.module.ts
// /src/samples/charts/charts.module.ts
const gulp = require("gulp");
const chmod = require("gulp-chmod");
const flatten = require("gulp-flatten");
const fs = require("fs");
const path = require("path");
const es = require("event-stream");
const del = require("del");
const utils = require("./utils.js")
const stats = require("./stats.js")
const EOL = '\r\n';
function log(msg) {
console.log("browser.js >> " + msg);
} exports.log = log;
// log("loaded");
const repoName = "igniteui-angular-examples";
const sampleRoot = '../samples/'; // /samples/
const sampleOutput = './src/samples/'; // /browser/src/samples/
// C:\REPOS\GitInternalDocs\igniteui-angular-examples\samples\charts\data-chart\axis-sharing
// returns ../samples/charts/data-chart/axis-sharing
function getSamplePath(dirPath) {
var ret = dirPath.split(repoName)[1];
ret = ".." + ret.split("\\").join("/");
return ret;
}
// C:\REPOS\GitInternalDocs\igniteui-angular-examples\samples\charts\data-chart\axis-sharing
// returns charts
function getSampleGroup(dirPath) {
var ret = getSamplePath(dirPath);
ret = ret.replace("../samples/", "");
ret = ret.split("/")[0];
return ret;
}
// C:\REPOS\GitInternalDocs\igniteui-angular-examples\samples\charts\data-chart\axis-sharing
// returns data-chart
function getSampleControl(dirPath) {
var ret = getSamplePath(dirPath);
ret = ret.replace("../samples/", "");
ret = ret.split("/")[1];
return ret;
}
// C:\REPOS\GitInternalDocs\igniteui-angular-examples\samples\charts\data-chart\axis-sharing/
// returns axis-sharing
function getSampleFolder(dirPath) {
var ret = getSamplePath(dirPath);
ret = ret.replace("../samples/", "");
ret = ret.split("/")[2];
return ret;
}
// C:\REPOS\GitInternalDocs\igniteui-angular-examples\samples\charts\data-chart\axis-sharing/
// returns ../src/samples/charts/data-chart/axis-sharing/
function getOutputPath(dirPath) {
var ret = getSamplePath(dirPath);
ret = ret.replace("../samples/", "./src/samples/")
return ret;
}
// NOTE you can comment out strings in this array to run these function only on a subset of samples
var sampleSourcePaths = [
// include samples for all components
sampleRoot + '**/package.json',
// sampleRoot + 'charts/doughnut-chart/overview/package.json',
// sampleRoot + 'charts/category-chart/area-chart-multiple-sources/package.json',
// sampleRoot + 'gauges/**/measures/package.json',
// sampleRoot + 'charts/sparkline/grid/package.json',
// sampleRoot + 'maps/**/display-heat-imagery/package.json',
// sampleRoot + 'excel/**/operations-on-workbooks/package.json',
// sampleRoot + 'charts/zoomslider/overview/package.json',
// include samples for specific components
// sampleRoot + 'charts/category-chart/**/package.json',
// sampleRoot + 'charts/data-chart/**/package.json',
// sampleRoot + 'charts/doughnut-chart/**/package.json',
// sampleRoot + 'charts/financial-chart/**/package.json',
// sampleRoot + 'charts/pie-chart/**/package.json',
// sampleRoot + 'charts/sparkline/**/package.json',
// sampleRoot + 'charts/tree-map/**/package.json',
// sampleRoot + 'charts/zoomslider/**/package.json',
// sampleRoot + 'maps/**/package.json',
// sampleRoot + 'excel/excel-library/**/package.json',
// sampleRoot + 'excel/spreadsheet/**/package.json',
// sampleRoot + 'gauges/bullet-graph/**/package.json',
// sampleRoot + 'gauges/linear-gauge/**/package.json',
// sampleRoot + 'gauges/radial-gauge/**/package.json',
// sampleRoot + 'grids/**/package.json',
// sampleRoot + 'layouts/**/package.json',
// sampleRoot + 'editors/**/package.json',
// sampleRoot + 'maps/geo-map/type-scatter-bubble-series/package.json',
// sampleRoot + 'maps/geo-map/display-heat-imagery/package.json',
// excluding package.json in node_modules sub folders in case they are installed locally
// "!" + sampleRoot + '**/charts/financial-chart/theming/package.json',
"!" + sampleRoot + '**/node_modules/**/package.json',
'!' + sampleRoot + '**/node_modules/**',
'!' + sampleRoot + '**/node_modules',
];
// stores info about each sample: folder path, file paths, routing path, etc
var samplesDatabase = [];
function getSampleInfo(samplePath, sampleCallback, sampleFile) {
var info = {};
info.SourcePath = getSamplePath(samplePath); // ../samples/charts/data-chart/axis-sharing/
info.OutputPath = getOutputPath(samplePath); // ./src/samples/charts/data-chart/axis-sharing/
info.SampleGroup = getSampleGroup(samplePath); // |charts| |
info.SampleControl = getSampleControl(samplePath); // |data-chart|
info.SampleFolder = getSampleFolder(samplePath); // | |axis-sharing|
// console.log("SamplePath " + samplePath);
// console.log("OutputPath " + info.OutputPath);
// console.log("SourcePath " + info.SourcePath);
// console.log("SampleGroup " + info.SampleGroup);
// console.log("SampleControl " + info.SampleControl);
// console.log("SampleFolder " + info.SampleFolder);
// for backward comparability:
// using old routing that uses "-" between ComponentFolder and sample SampleFolderName
// using new routing that uses "/" between ComponentFolder and sample SampleFolderName
// new routing path matches exactly sample path this makes it easier to use in docs since routing and github source are the same
info.SampleRoutePathOld = info.SampleControl + "-" + info.SampleFolder; // data-chart-axis-sharing
info.SampleRoutePathNew = info.SampleControl + "/" + info.SampleFolder; // data-chart/axis-sharing
info.ControlDisplayName = utils.toTitleCase(utils.replace(info.SampleControl, "-", " ")); // Data Chart
info.ControlName = utils.replace(info.ControlDisplayName, " ", ""); // DataChart
info.SampleDisplayName = utils.toTitleCase(utils.replace(info.SampleFolder, "-", " ")); // Axis Sharing
info.SampleClassName = utils.replace(info.SampleDisplayName, " ", "") + "Component"; // AxisSharingComponent
info.SampleClassName = info.ControlName + info.SampleClassName;
// console.log("ControlDisplayName " + info.ControlDisplayName);
// console.log("SampleDisplayName " + info.SampleDisplayName);
//console.log("SampleClassName " + info.SampleClassName);
// console.log("ComponentName " + info.ComponentName);
// console.log("DisplayName " + info.DisplayName);
// console.log("SourcePath " + info.SourcePath);
// console.log("OutputPath " + info.OutputPath);
// console.log("OutputGroup " + info.OutputGroup);
// console.log("OutputControl " + info.OutputControl);
// console.log("OutputFolder " + info.OutputFolder);
// info.SandboxUrlView = ""; // https://codesandbox.io/embed/github/IgniteUI/igniteui-angular-examples/tree/master/samples/charts/data-chart/axis-sharing
// info.SandboxUrlEdit = ""; // https://codesandbox.io/s/github/IgniteUI/igniteui-angular-examples/tree/master/samples/charts/data-chart/axis-sharing
// info.SandboxUrlShort = "", // https://codesandbox.io/s/github/IgniteUI/igniteui-angular-examples/tree/master/samples/charts/data-chart/axis-sharing
info.SourceComponentHTML = ""; // e.g. ./samples/charts/data-chart/axis-sharing/src/app.component.html
info.SourceComponentSCSS = ""; // e.g. ./samples/charts/data-chart/axis-sharing/src/app.component.scss
info.SourceComponentTS = ""; // e.g. ./samples/charts/data-chart/axis-sharing/src/app.component.ts
info.SourceModuleTS = ""; // e.g. ./samples/charts/data-chart/axis-sharing/src/app.module.ts
info.SourceDataFiles = []; // e.g. ./samples/charts/data-chart/axis-sharing/src/SampleFinancialData.ts
info.SourceFiles = []; // all above
info.ImportsLines = [];
info.ImportsModules = [];
// getting path to files in a given sample's source path:
gulp.src([
info.SourcePath + "/src/*.*",
info.SourcePath + "/src/app/*.*",
"!" + info.SourcePath + "/src/index.html",
"!" + info.SourcePath + "/src/main.ts",
"!" + info.SourcePath + "/src/polyfills.ts",
"!" + info.SourcePath + "/src/styles.scss",
"!" + info.SourcePath + "/src/typings.d.ts",
"!" + info.SourcePath + "/src/config/*.*",
"!" + info.SourcePath + "/node_modules/**",
])
.pipe(es.map(function(file, fileCallback) {
// console.log("getSampleInfo " + file.dirname + "/" + file.basename);
var filePath = getSamplePath(file.dirname + "/" + file.basename);
//log("getSampleInfo " + filePath);
if (filePath.indexOf('/app.module.ts') >= 0) {
info.SourceModuleTS = filePath;
var fileContent = file.contents.toString();
getSampleModules(fileContent, info);
}
else if (filePath.indexOf('/app.component.html') >= 0) {
info.SourceComponentHTML = filePath;
}
else if (filePath.indexOf('/app.component.ts') >= 0) {
info.SourceComponentTS = filePath;
}
else if (filePath.indexOf('/app.component.scss') >= 0) {
info.SourceComponentSCSS = filePath;
}
// else if (filePath.indexOf('.css') < 0) {
else { // data files, .e.g. SampleFinancialData.ts
info.SourceDataFiles.push(filePath);
//console.log("getSampleInfo " + filePath);
}
info.SourceFiles.push(filePath);
fileCallback(null, file);
}))
.on("end", function() {
// saving info about samples in database
samplesDatabase.push(info);
sampleCallback(null, sampleFile);
});
}
function getSampleModules(fileContent, info) {
var content = fileContent.replace(/\r\n/g, '').replace(/\n/g, '');
var lines = content.split(';');
info.ImportsLines = [];
info.ImportsModules = [];
for (const line of lines) {
if (line.indexOf('import ') >= 0 && line.indexOf('Module') >= 0) {
var importLine = line.replace('\r\n', '');
importLine = importLine.split('\'').join('"');
importLine = importLine.split(' ').join(' ');
if (importLine.indexOf(',') >= 0) {
//var importModules = importLine.replace('import {');
var package = importLine.split(' from ')[1];
//console.log( package );
var words = importLine.split(' ');
for (const word of words) {
if (word.indexOf('Module') >= 0) {
var modules = word.split(',');
for (const name of modules) {
var module = utils.replace(name, ' ', '');
module = utils.replace(module, '\t', '');
module = utils.replace(module, '\r\n', '');
module = module.trim();
if (module !== 'NgModule')
info.ImportsModules.push(module);
// console.log(module);
info.ImportsLines.push('import { ' + module + ' } from ' + package + ';');
}
}
}
} else {
importLine += ';';
info.ImportsLines.push(importLine);
var module = importLine.split(' from ')[0].replace('import { ', '').replace(' }', '');
module = module.trim();
if (module !== 'NgModule')
info.ImportsModules.push(module);
}
//console.log(importLine);
}
}
// console.log("importsModules " + info.ImportsModules.length);
// console.log("importsLines " + info.ImportsLines.length);
// for (const line of info.ImportsModules) {
// console.log(line);
// }
// for (const line of info.ImportsLines) {
// console.log(line);
// }
}
function findSamples(cb) {
log("findSamples");
samplesDatabase = [];
gulp.src(sampleSourcePaths, {allowEmpty: true})
.pipe(es.map(function(file, fileCallback) {
//log("getting: " + file.dirname);
// saving info for each samples in samplesDatabase
// log("sample: " + file.dirname);
getSampleInfo(file.dirname, fileCallback, file);
}))
.on("end", function() {
log("findSamples... done = " + samplesDatabase.length);
cb();
});
} exports.findSamples = findSamples;
exports.generateStats = function generateStats(cb) {
var combinedSamples = [];
for (const info of samplesDatabase) {
// console.log(info);
var samplePath = info.SourcePath.replace('samples/', '').replace('../','');
combinedSamples.push(samplePath);
break;
}
combinedSamples.sort();
stats.generate(cb, combinedSamples);
}
// this function is copying source files for individual samples to browser
// generates modules for samples, routing data, and routing modules
function copySamples(cb) {
//log("copySamples");
//log("copySamples = " + samplesDatabase.length);
const outputFolder = "./src/samples/**/";
log("cleaning up: " + outputFolder);
del.sync(outputFolder + "/**");
var controlsModules = {}; // storing modules per each control, e.g. data-chart
var groupModules = {}; // storing modules for multiple controls, e.g. charts
var routingStorage = {}; // storing routing data for all samples
// copying all samples to repo/samples folder based on gathered sample info
for (const info of samplesDatabase) {
//log("copying sample: " + info.SourcePath);
var group = info.SampleGroup;
var control = info.SampleControl;
var importComponent = 'import { ' + info.SampleClassName + ' } from ' + '"./' + info.SampleFolder + '/app.component";';
// log("copySamples " + importComponent);
if (routingStorage[group] === undefined) {
routingStorage[group] = {}
routingStorage[group].Group = info.SampleGroup;
routingStorage[group].Control = info.ControlName;
routingStorage[group].ModuleName = "RoutingDataFor" + utils.toTitleCase(info.SampleGroup);
routingStorage[group].Samples = {};
routingStorage[group].Modules = [];
routingStorage[group].Imports = [];
routingStorage[group].Output = './src/samples/' + info.SampleGroup+ '/';
}
var routing = info.SampleRoutePathNew;
if (routingStorage[group].Samples[routing] === undefined) {
var data = {
showLink: true,
routing: routing,
name: info.SampleDisplayName,
parent: info.ControlName,
componentImport: importComponent.replace('./', './' + info.SampleControl + '/'),
componentName: info.SampleClassName,
};
routingStorage[group].Samples[routing] = data;
}
// TODO remove in 23.2 release
routing = info.SampleRoutePathOld;
if (routingStorage[group].Samples[routing] === undefined) {
var data = {
showLink: false,
routing: routing,
name: info.SampleDisplayName,
parent: info.ControlName,
componentImport: importComponent.replace('./', './' + info.SampleControl + '/'),
componentName: info.SampleClassName,
};
routingStorage[group].Samples[routing] = data;
}
// grouping sample's modules by group of controls, e.g. charts
if (groupModules[group] === undefined) {
groupModules[group] = {}
groupModules[group].Group = info.SampleGroup;
groupModules[group].Control = info.ControlName;
groupModules[group].ModuleName = "SamplesFor" + utils.toTitleCase(info.SampleGroup);
groupModules[group].Modules = [];
groupModules[group].Imports = [];
groupModules[group].Components = [];
groupModules[group].Path = './src/samples/' + info.SampleGroup + '/samples-modules.ts';
}
// grouping sample's modules by the control that is used in samples
if (controlsModules[control] === undefined) {
controlsModules[control] = {}
controlsModules[control].Group = info.SampleGroup;
controlsModules[control].Control = info.ControlName;
controlsModules[control].ModuleName = "SamplesFor" + info.ControlName;
controlsModules[control].Modules = [];
controlsModules[control].Imports = [];
controlsModules[control].Components = [];
controlsModules[control].DataFiles = [];
controlsModules[control].Path = './src/samples/' + info.SampleGroup + '/' + info.SampleControl + '/samples-modules.ts';
// controlsModules[control].Path = './src/samples/' + info.SampleGroup + '/' + info.SampleControl + '/' + info.SampleControl + 'samples-modules.ts';
var controlsModule = controlsModules[control].ModuleName.trim();
var controlsPath = './' + info.SampleControl + '/samples-modules';
var controlsImport = 'import { ' + controlsModule + ' } from "' + controlsPath + '";';
if (groupModules[group].Imports.indexOf(controlsImport) < 0) {
groupModules[group].Imports.push(controlsImport);
}
if (groupModules[group].Modules.indexOf(controlsModule) < 0) {
groupModules[group].Modules.push(controlsModule);
}
var commonModule = 'CommonModule';
var commonImport = 'import { ' + commonModule + ' } from "@angular/common";';
if (groupModules[group].Imports.indexOf(commonImport) < 0) {
groupModules[group].Imports.push(commonImport);
}
if (groupModules[group].Modules.indexOf(commonModule) < 0) {
groupModules[group].Modules.push(commonModule);
}
if (routingStorage[group].Imports.indexOf(controlsImport) < 0) {
routingStorage[group].Imports.push(controlsImport);
}
if (routingStorage[group].Modules.indexOf(controlsModule) < 0) {
routingStorage[group].Modules.push(controlsModule);
}
}
controlsModules[control].Components.push(info.SampleClassName);
for (const module of info.ImportsModules) {
if (module.trim() !== "" &&
module.indexOf('BrowserModule') < 0 &&
module.indexOf('BrowserAnimationsModule') < 0 &&
controlsModules[control].Modules.indexOf(module) < 0) {
controlsModules[control].Modules.push(module);
}
if (module.trim() !== "" &&
module.indexOf('BrowserModule') < 0 &&
module.indexOf('BrowserAnimationsModule') < 0 &&
module.indexOf('Component') < 0 &&
groupModules[group].Modules.indexOf(module) < 0) {
groupModules[group].Modules.push(module);
}
}
for (const line of info.ImportsLines) {
if (line.indexOf('BrowserModule') < 0 &&
line.indexOf('BrowserAnimationsModule') < 0 &&
line.indexOf('import { } from') < 0 &&
controlsModules[control].Imports.indexOf(line) < 0) {
controlsModules[control].Imports.push(line);
}
if (line.indexOf('BrowserModule') < 0 &&
line.indexOf('BrowserAnimationsModule') < 0 &&
line.indexOf('Component') < 0 &&
line.indexOf('import { } from') < 0 &&
groupModules[group].Imports.indexOf(line) < 0) {
groupModules[group].Imports.push(line);
}
}
// adding import for the current sample's component
if (controlsModules[control].Imports.indexOf(importComponent) < 0)
controlsModules[control].Imports.push(importComponent);
for (const filePath of info.SourceFiles) {
if (filePath.indexOf('app.module.ts') > 0) continue;
var fileContent = utils.fileRead(filePath);
var fileName = utils.fileName(filePath);
var fileOutput = info.OutputPath + "/" + fileName;
if (filePath.indexOf('app.component.ts') > 0) {
log("generating sample: " + fileOutput); // + ' from ' + filePath );
fileContent = fileContent.replace('class AppComponent', 'class ' + info.SampleClassName);
}
else if (filePath.indexOf('app.') < 0) {
//var dataPath = fileOutput.replace('.ts', '');
var dataName = fileName.replace('.ts', '');
var dataPath = './' + info.SampleFolder + '/' + dataName;
// if (controlsModules[control].DataFiles[dataPath] === undefined) {
// controlsModules[control].DataFiles[dataPath] = dataName;
if (dataName.indexOf('Worker') < 0 && // HeatmapWorker
dataName.indexOf('.css') < 0 &&
controlsModules[control].DataFiles.indexOf(dataName) < 0) {
controlsModules[control].DataFiles.push(dataName);
var dataImport = 'import { ' + dataName + ' } from "' + dataPath + '";';
if (controlsModules[control].Imports.indexOf(dataImport) < 0)
controlsModules[control].Imports.push(dataImport);
}
//controlsModules[control].DataFiles.push(importComponent);
}
//log("copying: " + filePath);
utils.fileSave(fileOutput, fileContent);
}
}
// console.log(controlsModules);
// generating ./src/samples/GROUP/CONTROL/samples-modules.ts
for(var key in controlsModules) {
var data = controlsModules[key];
data.Modules.sort();
data.Imports.sort();
// log("generating samples' control: " + data.Path + ' ' + data.Modules.length + ' modules ' + data.Imports.length + ' imports');
var ret = "";
ret += "/* tslint:disable */ \r\n\r\n";
for (const line of data.Imports) {
ret += line + "\n";
}
if (data.DataFiles.length > 0) {
ret += 'import { ModuleWithProviders } from "@angular/core";\r\n';
}
ret += "\r\n";
ret += "@NgModule({\r\n";
ret += " declarations: [\r\n";
ret += data.Components.join(',\r\n');
ret += "\r\n ], \r\n";
ret += " imports: [\r\n";
ret += data.Modules.join(',\r\n');
ret += " \r\n ] \r\n";
ret += "}) \r\n\r\n";
ret += "export class " + data.ModuleName + " {";
if (data.DataFiles.length > 0) {
ret += "\r\n";
ret += " public static forRoot(): ModuleWithProviders<" + data.ModuleName + "> {\n";
ret += " return {\r\n";
ret += " ngModule: " + data.ModuleName + ",\r\n";
ret += " providers: [\r\n";
ret += " " + data.DataFiles.join(',\r\n ') + "\r\n";
ret += " ]\r\n";
ret += " };\r\n";
ret += " }\r\n";
}
ret += "} \r\n";
// console.log(ret);
utils.fileSave(data.Path, ret);
}
var appModuleRoutes = [];
// generating ./src/samples/GROUP/samples-modules.ts
for(var key in groupModules) {
var data = groupModules[key];
var routingClass = 'RoutingModulesFor' + utils.toTitleCase(key);
var routingImport = 'import { ' + routingClass + ' } from "./routing-modules";';
data.Imports.push(routingImport);
data.Modules.push(routingClass);
data.Modules.sort();
data.Imports.sort();
// log("generating group module: " + data.Path + ' ' + data.Modules.length + ' modules ' + data.Imports.length + ' imports');
var ret = "/* tslint:disable */ \n\n";
for (const line of data.Imports) {
ret += line + "\r\n";
}
ret += "\r\n";
ret += "@NgModule({\r\n";
ret += " imports: [\r\n";
ret += "" + data.Modules.join(',\r\n');
ret += " \r\n ] \r\n";
ret += "}) \r\n\r\n";
ret += "export class " + data.ModuleName + " {} \r\n";
// console.log(ret);
utils.fileSave(data.Path, ret); // ./src/samples/GROUP/samples-modules.ts
var appRouteImport = 'import("../samples/' + key + '/samples-modules").then(m => m.' + data.ModuleName + ')';
var appRouteInfo = ' { path: "' + key + '", data: ["' + data.ModuleName + '"], loadChildren: () => ' + appRouteImport + ' }';
appModuleRoutes.push(appRouteInfo);
}
var routingDataImports = [];
var routingDataArray = [];
for(var group in routingStorage) {
var data = routingStorage[group];
var routingDataFile = 'routing-data';
var routingData = "/* tslint:disable */ \r\n\r\n";
routingData += "export const " + data.ModuleName + " = { \r\n";
// generating ./src/samples/GROUP/routing-data.ts
var routingOutputPath = data.Output + routingDataFile + '.ts';
// log("generating group routing data: " + routingOutputPath);
var routingSamples = [];
var routingComponents = [];
for(var routing in data.Samples) {
var sample = data.Samples[routing];
var str = ' "' + routing + '": { displayName: ' + '"' + sample.name + '", parentName: "' + sample.parent + '", showLink: ' + sample.showLink + ' }';
routingSamples.push(str);
var strRouting = '"' + routing + '"';
var strData = data.ModuleName + '[' + strRouting + ']';
var strComp = ' { component: ' + sample.componentName + ', path: ' + strRouting + ', data: ' + strData + ' }';
routingComponents.push(strComp);
if (sample.showLink) {
data.Imports.push(sample.componentImport);
}
}
routingData += routingSamples.join(',\r\n');
routingData += "\r\n";
routingData += "}; \r\n";
//console.log(ret);
utils.fileSave(routingOutputPath, routingData);
var routingDataImport = "import { " + data.ModuleName + ' } from "../../samples/' + group + '/' + routingDataFile + '";';
routingDataImports.push(routingDataImport);
var routingDataItem = ' { path: "' + group + '", routesData: ' + data.ModuleName + ' }'
routingDataArray.push(routingDataItem);
// generating ./src/samples/GROUP/routing-modules.ts
var routingModulePath = data.Output + 'routing-modules.ts';
// log("generating group routing module: " + routingModulePath);
var routingExportName = 'RoutesFor' + utils.toTitleCase(group);
var routingModules = "/* tslint:disable */ \r\n\r\n";
routingModules += 'import { NgModule } from "@angular/core";\r\n';
routingModules += 'import { RouterModule, Routes } from "@angular/router";\r\n';
routingModules += "\r\n";
routingModules += "import { " + data.ModuleName + ' } from "./' + routingDataFile + '"; \r\n';;
routingModules += "\r\n";
routingModules += data.Imports.join('\r\n');
routingModules += "\r\n\r\n";
routingModules += 'export const ' + routingExportName + ': Routes = [\r\n'
routingModules += routingComponents.join(',\r\n');
routingModules += "\r\n];\r\n\r\n";
var routingClassName = 'RoutingModulesFor' + utils.toTitleCase(group);
routingModules += "@NgModule({\r\n";
routingModules += " exports: [\r\n";
routingModules += 'RouterModule \r\n';
routingModules += " ], \r\n";
routingModules += " imports: [\r\n";
routingModules += data.Modules.join(',\r\n') + ",\r\n";
routingModules += 'RouterModule.forChild(' + routingExportName + ') \r\n'
routingModules += " ] \r\n";
routingModules += "}) \r\n\r\n";
routingModules += 'export class ' + routingClassName + ' { }\r\n'
utils.fileSave(data.Output + 'routing-modules.ts', routingModules);
//console.log(routingModules);
}
// console.log(routingStorage);
// updating ./src/app.routing.module.ts
var appModuleFile = './src/app/app-routing.module.ts';
var appModuleContent = utils.fileRead(appModuleFile);
var appModuleLines = appModuleContent.split('\r\n');
//console.log('appModuleLines ' + appModuleLines.length);
let autoInsertStart = -1;
let autoInsertEnd = -1;
// log('updating ' + appModuleFile)
for (let i = 0; i < appModuleLines.length; i++) {
let line = appModuleLines[i];
if (line.indexOf("Auto-Insert-Modules-Start") > 0) {
autoInsertStart = i;
}
else if (line.indexOf("Auto-Insert-Modules-End") > 0) {
autoInsertEnd = i;
}
}
if (autoInsertStart < 0 ) {
throw new Exception("File " + appModuleFile + "\r\n is missing: 'Auto-Insert-Modules-Start' ");
}
else if (autoInsertEnd < 0 ) {
throw new Exception("File " + appModuleFile + "\r\n is missing: 'Auto-Insert-Modules-End' ");
}
else if (autoInsertStart > 0 && autoInsertEnd > 0) {
for (let i = autoInsertStart+1; i < autoInsertEnd; i++) {
appModuleLines[i] = ""; // clearing previously auto-generated inserts
}
appModuleRoutes = appModuleRoutes.sort();
// adding latest auto-generated inserts for JS files
appModuleLines[autoInsertStart + 1] = appModuleRoutes.join(',\r\n');
appModuleContent = appModuleLines.join('\r\n');
utils.fileSave(appModuleFile, appModuleContent, true);
}
// updating ./src/app/index/index.component.ts
var appIndexFile = './src/app/index/index.component.ts';
var appIndexContent = utils.fileRead(appIndexFile);
var appIndexLines = appIndexContent.split('\r\n');
let appIndexRoutingImportStart = -1;
let appIndexRoutingImportEnd = -1;
// log('updating ' + appIndexFile)
let appIndexRoutingArrayStart = -1;
let appIndexRoutingArrayEnd = -1;
for (let i = 0; i < appIndexLines.length; i++) {
let line = appIndexLines[i];
if (line.indexOf("Auto-Insert-Imports-RoutingData-Start") > 0) {
appIndexRoutingImportStart = i;
}
else if (line.indexOf("Auto-Insert-Imports-RoutingData-End") > 0) {
appIndexRoutingImportEnd = i;
}
if (line.indexOf("Auto-Insert-SamplesRoutingArray-Start") > 0) {
appIndexRoutingArrayStart = i;
}
else if (line.indexOf("Auto-Insert-SamplesRoutingArray-End") > 0) {
appIndexRoutingArrayEnd = i;
}
}
var appIndexChanged = false;
if (appIndexRoutingImportStart > 0 && appIndexRoutingImportEnd > 0) {
for (let i = appIndexRoutingImportStart+1; i < appIndexRoutingImportEnd; i++) {
appIndexLines[i] = ""; // clearing previously auto-generated inserts
}
routingDataImports = routingDataImports.sort();
// adding latest auto-generated inserts for JS files
appIndexLines[appIndexRoutingImportStart + 1] = routingDataImports.join('\r\n');
appIndexChanged = true;
}
if (appIndexRoutingArrayStart > 0 && appIndexRoutingArrayEnd > 0) {
for (let i = appIndexRoutingArrayStart+1; i < appIndexRoutingArrayEnd; i++) {
appIndexLines[i] = ""; // clearing previously auto-generated inserts
}
routingDataArray = routingDataArray.sort();
// adding latest auto-generated inserts for JS files
appIndexLines[appIndexRoutingArrayStart + 1] = routingDataArray.join(',\r\n');
appIndexChanged = true;
}
if (appIndexChanged) {
appIndexContent = appIndexLines.join('\r\n');
utils.fileSave(appIndexFile, appIndexContent, true);
}
// console.log('appIndexLines ' + appIndexRoutingArrayStart + ' ' + appIndexRoutingImportStart);
if (cb) cb();
} exports.copySamples = copySamples;
function updateCodeViewer(cb) {
const outputFolder = "./src/assets/code-viewer/";
log("cleaning up: " + outputFolder);
del.sync(outputFolder + "/**");
// generating code viewer files (.json) for each sample
for (const info of samplesDatabase) {
var sampleFiles = [];
// console.log(info);
// https://staging.infragistics.com/angular-demos-dv/assets/code-viewer/
// zoomslider-overview.json OLD format
// zoomslider/overview.json NEW format
var codeViewPath = outputFolder + info.SampleRoutePathNew + ".json";
log("generating: " + codeViewPath);
for (const filePath of info.SourceFiles) {
var codeViewItem = {
hasRelativeAssetsUrls: false,
isMain: true,
};
if (filePath.indexOf(".scss") > 0) {
codeViewItem.fileExtension = 'scss';
codeViewItem.fileHeader = 'scss';
}
else if (filePath.indexOf(".module.ts") > 0) {
codeViewItem.fileExtension = 'ts';
codeViewItem.fileHeader = 'modules';
}
else if (filePath.indexOf(".component.ts") > 0) {
codeViewItem.fileExtension = 'ts';
codeViewItem.fileHeader = 'ts';
}
else if (filePath.indexOf(".ts") > 0) {
codeViewItem.fileExtension = 'ts';
codeViewItem.fileHeader = "DATA";
}
else if (filePath.indexOf(".html") > 0) {
codeViewItem.fileExtension = 'html';
codeViewItem.fileHeader = 'html';
}
codeViewItem.path = filePath;
codeViewItem.content = utils.fileRead(filePath);
sampleFiles.push(codeViewItem);
}
var packageInfo = {};
packageInfo.hasRelativeAssetsUrls = false;
packageInfo.path = "package.json";
packageInfo.content = utils.fileRead(info.SourcePath + "/package.json");
sampleFiles.push(packageInfo);
var codeViewContent = '{\r\n';
codeViewContent += '"addTsConfig": false,\r\n';
codeViewContent += '"sampleFiles":\r\n';
codeViewContent += JSON.stringify(sampleFiles, null, ' ');
codeViewContent += '\r\n}';
utils.fileSave(codeViewPath, codeViewContent);
// backward compatible format with sample group to match Blazor/React/WC browsers
codeViewPath = outputFolder + info.SampleGroup + "/" + info.SampleRoutePathNew + ".json";
utils.fileSave(codeViewPath, codeViewContent);
}
if (cb) cb();
} exports.updateCodeViewer = updateCodeViewer;
function cleanSamples() {
log("cleaning up ../samples folder and ./browser/src/samples folder");
return del([
sampleOutput + "**/*.*",
sampleOutput,
"../samples/**/.angular/**/*.*",
"../samples/**/.angular",
"../samples/**/.git/**/*.*",
"../samples/**/.git",
"../samples/**/build/**/*.*",
"../samples/**/dist/**/*.*",
"../samples/**/node_modules/**/*.*",
"../samples/**/node_modules",
"../samples/**/package-lock.json"
],{force: true});
} exports.cleanSamples = cleanSamples;
function skipSamples(cb) {
if (cb) cb();
} exports.skipSamples = skipSamples;
function listSamples(cb) {
var fileFormat = "package.json";
var fileSources = [
// including these samples:
sampleRoot + 'charts/**/' + fileFormat,
// sampleRoot + 'charts/doughnut-chart/**/' + fileFormat,
// sampleRoot + 'charts/sparkline/**/' + fileFormat,
// sampleRoot + 'charts/tree-map/**/' + fileFormat,
// sampleRoot + 'charts/pie-chart/**/' + fileFormat,
// sampleRoot + 'charts/category-chart/**/' + fileFormat,
// sampleRoot + 'charts/financial-chart/**/' + fileFormat,
sampleRoot + 'maps/**/' + fileFormat,
sampleRoot + 'gauges/**/' + fileFormat,
sampleRoot + 'spreadsheet/**/' + fileFormat,
// excluding these samples:
'!'+sampleRoot + '**/excel-library/**/' + fileFormat,
'!'+sampleRoot + '**/zoomslider/**/' + fileFormat,
'!'+sampleRoot + '**/node_modules/**/' + fileFormat, // excluding node_modules sub-folders
];
gulp.src(fileSources, {allowEmpty: true})
.pipe(es.map(function(file, fileCallback) {
// let filePath = getRelativePath(file);
// let fileContent = file.contents.toString();
// let fileLines = fileContent.split('\r\n');
// let fileStart = fileLines[0];
// if (fileStart.indexOf("container sample") < 0) {
// console.log("'" + JSON.stringify(fileStart) + "' " + filePath);
// }
log(" " + file.dirname + "/" + file.basename);
fileCallback(null, file);
}))
.on("end", function() {
if (cb) cb();
});
} exports.listSamples = listSamples;
// C:\REPOS\igniteui-angular-examples/samples\charts\data-chart-axis-sharing/
// returns ../samples/charts/data-chart-axis-sharing/
// function getRelativePath(filePath) {
// var relativePath = filePath.split(repoName)[1];
// relativePath = relativePath.split("\\").join("/");
// if (relativePath.indexOf("/samples/") > 0)
// relativePath = ".." + relativePath; // relative samples ../samples/charts/data-chart-axis-sharing/
// else
// relativePath = "." + relativePath; // relative browser ./browser/src/samples/charts/data-chart-axis-sharing/
// return relativePath;
// }
function testFileParsing(cb) {
const repoPath = "../../igniteui-live-editing-samples/angular-demos-dv/";
var filePath = repoPath + "charts/category-chart-highlighting/src/app.module.ts"
var endLine = '\r\n';
//var filePath = "./src/samples/charts/samples-n-line.ts";
var fileContent = utils.fileRead(filePath);
var fileLinesR = fileContent.split('\r\n');
var fileLinesN = fileContent.split('\n');
var fileLinesS = utils.split(fileContent);
console.log('fileLinesR=' + fileLinesR.length);
console.log('fileLinesN=' + fileLinesN.length);
console.log('fileLinesS=' + fileLinesS.length);
var fileOutput = "./src/samples/charts/";
var r = fileLinesR.join('\r\n');
var n = fileLinesN.join('\n');
utils.fileSave(fileOutput + 'samples-r.ts', r );
utils.fileSave(fileOutput + 'samples-n.ts', n );
if (cb) cb();
} exports.testFileParsing = testFileParsing;
function logRoutes(cb) {
let routes = [];
for (const sample of samplesDatabase) {
routes.push("/" + sample.SampleGroup + "/" + sample.SampleRoutePathNew)
}
routes.sort();
for (const route of routes) {
console.log(route);
}
cb();
} exports.logRoutes = logRoutes;
function logSandboxUrls (cb) {
let content = "";
var sandboxRoot = "https://codesandbox.io/s/github/IgniteUI/igniteui-angular-examples/tree/master/samples/"
for (const sample of samplesDatabase) {
let sampleRoute = sample.SampleGroup + '/' + sample.SampleControl + "-" + sample.SampleFolder;
let sandboxURL = sandboxRoot + sample.SampleGroup + '/' + sample.SampleControl + "/" + sample.SampleFolder;
// sandboxURL += "?fontsize=14&hidenavigation=1&theme=dark&view=preview&file=/src/app.component.html"
content += sandboxURL + "\n";
console.log(sandboxURL);
}
let output = "./sandbox-angular.txt";
fs.writeFileSync(output, content);
cb();
} exports.logSandboxUrls = logSandboxUrls ;
function updateReadme(cb) {
log('updating readme files... ');
// var sandboxTemplate = fs.readFileSync("../samples/templates/sandbox.config.json", "utf8");
// for (const sample of samplesDatabase) {
// let sandboxOutput = '../samples/' + sample.SampleGroup + '/' + sample.SampleControl + '/' + sample.SampleFolder + "/sandbox.config.json";
// fs.writeFileSync(sandboxOutput, sandboxTemplate);
// console.log(sandboxOutput)
// }
// "https://codesandbox.io/s/github/IgniteUI/igniteui-angular-examples/tree/master/samples/charts/category-chart/annotations?fontsize=14&hidenavigation=1&theme=dark&view=preview&file=/src/app/app.component.html"
// "https://codesandbox.io/s/github/IgniteUI/igniteui-angular-examples/tree/master/samples/charts/category-chart/annotations"
var changeFilesCount = 0;
var sandboxRoot = "https://codesandbox.io/s/github/IgniteUI/igniteui-angular-examples/tree/master/samples/"
var readmeTemplate = fs.readFileSync("../samples/templates/ReadMe.md", "utf8");
for (const sample of samplesDatabase) {
let sampleRoute = sample.SampleGroup + '/' + sample.SampleControl + "-" + sample.SampleFolder;
let sandboxURL = sandboxRoot + sample.SampleGroup + '/' + sample.SampleControl + "/" + sample.SampleFolder;
sandboxURL += "?fontsize=14&hidenavigation=1&theme=dark&view=preview&file=/src/app.component.html"
let readmePath = '../samples/' + sample.SampleGroup + '/' + sample.SampleControl + "/" + sample.SampleFolder + "/ReadMe.md";
let readmeNewFile = readmeTemplate + "";
readmeNewFile = readmeNewFile.replace("{ComponentName}", sample.ControlName);
readmeNewFile = readmeNewFile.replace("{SandboxUrlEdit}", sandboxURL);
readmeNewFile = readmeNewFile.replace("{SampleDisplayName}", sample.SampleDisplayName);
readmeNewFile = readmeNewFile.replace("{SampleFolderPath}", sample.SourcePath);
readmeNewFile = readmeNewFile.replace("{SampleRoute}", sampleRoute);
let readmeOldFile = "";
if (fs.existsSync(readmePath)) {
readmeOldFile = fs.readFileSync(readmePath).toString();
}
if (readmeNewFile !== readmeOldFile) {
console.log('UPDATED: ' + readmePath)
changeFilesCount++;
fs.writeFileSync(readmePath, readmeNewFile);
}
}
if (changeFilesCount > 0) {
console.log('WARNING: you must commit above ' + changeFilesCount + ' readme files in a pull request')