-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
1874 lines (1646 loc) · 72.1 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var gulp = require('gulp');
var yaml = require('gulp-yaml');
var del = require('del');
var flatten = require('gulp-flatten');
var replace = require('gulp-replace');
var es = require('event-stream');
var through = require('through2');
var path = require('path');
const { buildDocfx } = require('igniteui-docfx-template');
const browserSync = require('browser-sync').create();
const argv = require('yargs').argv;
const fs = require('fs');
var fileRoot = 'c:/work/dev-tools/XPlatform/Main/'
var mt = null; // MarkdownTransformer
var ml = null; // MappingLoader
var rm = null; // RedirectManager
var transformer = null;
var loader = null;
var docsConfig = null;
var docsComponents = null;
let LANG = argv.lang === undefined ? "en" : argv.lang;
let PLAT = argv.plat === undefined ? "React": argv.plat;
let PLAT_API = undefined;
let ENV_TARGET = argv.env || "development";
let DOCFX_BASE = {
en: `./dist/${PLAT}/en`,
jp: `./dist/${PLAT}/jp`,
kr: `./dist/${PLAT}/kr`
};
let DOCFX_PATH = `${DOCFX_BASE[LANG]}`;
let DOCFX_CONF = `${DOCFX_PATH}/docfx.json`;
let DOCFX_TEMPLATE_GLOBAL = path.join(__dirname, `./node_modules/igniteui-docfx-template/template/bundling.global.json`);
let DOCFX_SITE = `${DOCFX_PATH}/_site`;
let DOCFX_FORCE_OUTPUT = false; // this is true when building Angular CI (build-docfx-angular)
var LOG = require("./src/ext/Logger").LOG;
function log(msg) { LOG.action(">> " + msg); }
function ensureEnvironment() {
if (mt == null) {
mt = require('./src/ext/MarkdownTransformer');
ml = require("./src/ext/MappingLoader");
rm = require("./src/ext/RedirectManager");
transformer = new mt.MarkdownTransformer();
loader = new ml.MappingLoader();
docsConfig = require("./docConfig.json");
docsComponents = require("./docComponents.json");
// var platformName = PLAT;
// var platformData = docsConfig[platformName];
// if (platformData !== undefined) {
// throw "docsConfig,json does not have platform: " + platformName;
// }
LOG.action("initialling environment...");
}
if (PLAT === 'Angular') {
PLAT_API = ml.APIPlatform.Angular;
} else if (PLAT === 'Blazor') {
PLAT_API = ml.APIPlatform.Blazor;
} else if (PLAT === 'React') {
PLAT_API = ml.APIPlatform.React;
} else if (PLAT === 'WebComponents') {
PLAT_API = ml.APIPlatform.WebComponents;
}
DOCFX_BASE = {
en: `./dist/${PLAT}/en`,
jp: `./dist/${PLAT}/jp`,
kr: `./dist/${PLAT}/kr`
};
DOCFX_PATH = `${DOCFX_BASE[LANG]}`;
DOCFX_CONF = `${DOCFX_PATH}/docfx.json`;
DOCFX_SITE = `${DOCFX_PATH}/_site`;
DOCFX_ARTICLES = `${DOCFX_PATH}/components`;
}
function readMappings() {
return es.map(function(file, cb) {
//console.log("reading mapping: " + file.path);
let mapping = JSON.parse(file.contents.toString());
loader.import(mapping);
cb(null, file);
});
}
function transformFiles() {
ensureEnvironment();
LOG.action("transforming files: ");
let mapStream = through.obj(function(file, encoding, cb) {
var fileContent = file.contents.toString();
var fileDir = path.dirname(file.path) + "\\";
var typeName = path.basename(path.dirname(file.path))
console.log("- transforming " + file.path);
transformer.transformContent(typeName, fileContent, file.path,
(err, results) => {
if (err) {
cb(err, null);
}
if (results) {
for (let i = 1; i < results.length; i++) {
let newFile = file.clone();
newFile.contents = Buffer.from(results[i].content);
if (results[i].componentOutput) {
newFile.path = newFile.path.replace("_shared", results[i].componentOutput);
}
this.push(newFile);
}
file.contents = Buffer.from(results[0].content);
if (results[0].componentOutput) {
file.path = file.path.replace("_shared", results[0].componentOutput);
}
cb(null, file);
}
});
});
return mapStream;
}
function transformStaticFiles(platformName) {
ensureEnvironment();
return es.map(function(file, cb) {
var fileContent = file.contents.toString();
// var typeName = path.basename(path.dirname(file.path))
var replacements = docsConfig[platformName].replacements;
//console.log(typeName);
for (var i = 0; i < replacements.length; i++) {
var variable = replacements[i];
if (variable.name && variable.value) {
fileContent = fileContent.replace(new RegExp(variable.name, "gm"), variable.value);
}
}
file.contents = Buffer.from(fileContent);
cb(null, file);
});
}
function updateSource() {
del.sync("src/ext/**/*.*");
return gulp.src([
fileRoot + 'Source/APIRemarks/src/**/*.ts'
])
.pipe(gulp.dest("src/ext"))
}
function cleanAngular(cb) {
del.sync("dist/Angular/**/*.*");
cb();
}
exports.cleanAngular = cleanAngular;
function cleanReact(cb) {
del.sync("dist/React/**/*.*");
cb();
}
exports.cleanReact = cleanReact;
function cleanWebComponents(cb) {
del.sync("dist/WebComponents/**/*.*");
cb();
}
exports.cleanWebComponents = cleanWebComponents;
function cleanBlazor(cb) {
del.sync("dist/Blazor/**/*.*");
cb();
}
exports.cleanBlazor = cleanBlazor;
// updates API mapping files in ./apiMap folder for Angular platform
function updateApiAngular() {
return updateApiFor("Angular");
}
exports.updateApiAngular = updateApiAngular;
// updates API mapping files in ./apiMap folder for React platform
function updateApiReact() {
return updateApiFor("React");
}
exports.updateApiReact = updateApiReact;
// updates API mapping files in ./apiMap folder for WebComponents platform
function updateApiWebComponents() {
return updateApiFor("WebComponents");
}
exports.updateApiWebComponents = updateApiWebComponents;
exports.updateApiWC = updateApiWebComponents;
// updates API mapping files in ./apiMap folder for Blazor platform
function updateApiBlazor() {
return updateApiFor("Blazor");
}
exports.updateApiBlazor = updateApiBlazor;
// update API mappings to more human readable format which we use to verify commits and look up mentioned types in metadata
function updateApiFormat(jsonContent) {
let json = JSON.parse(jsonContent);
let fileContent = '{';
// if (json.extraFiles !== undefined) fileContent += ' "extraFiles":' + JSON.stringify(json.extraFiles) + ',\n';
if (json.extraFiles !== undefined && json.extraFiles.length > 0) {
if (json.extraFiles.length === 1) {
fileContent += '\n "extraFiles": ' + JSON.stringify(json.extraFiles) + ',\n';
} else {
let files = [];
for (const item of json.extraFiles) {
files.push(' "' + item + '"');
}
files.sort();
fileContent += '\n "extraFiles": [\n' + files.join(',\n') + '\n ],\n';
}
}
if (json.types === undefined || json.types.length === 0) {
fileContent += ' "types":[]\n';
} else {
let types = [];
for (const t of json.types) {
let typeInfo = '{\n';
typeInfo += ' "originalName":"' + t.originalName + '",\n';
typeInfo += ' "originalNamespace":"' + t.originalNamespace + '",\n';
if (t.originalBaseTypeNamespace !== undefined) typeInfo += ' "originalBaseTypeNamespace":"' + t.originalBaseTypeNamespace + '",\n';
if (t.originalBaseTypeName !== undefined) typeInfo += ' "originalBaseTypeName":"' + t.originalBaseTypeName + '",\n';
if (t.isEnum !== undefined) typeInfo += ' "isEnum":' + t.isEnum + ',\n';
if (!t.packageName) {
t.packageName = "igniteui-core";
}
typeInfo += ' "packageName":"' + t.packageName + '",\n';
if (t.names && t.names.length > 0) {
t.names.sort((a,b) => (a.mappedName < b.mappedName) ? -1 : (a.mappedName > b.mappedName) ? 1 : 0);
typeInfo += ' "names":' + JSON.stringify(t.names);
}
if (t.members && t.members.length > 0) {
t.members.sort((a,b) => (a.originalName < b.originalName) ? -1 : (a.originalName > b.originalName) ? 1 : 0);
typeInfo += ',\n'
typeInfo += ' "members":[\n';
let members = [];
for (const m of t.members) {
members.push(' ' + JSON.stringify(m));
}
typeInfo += members.join(',\n');
typeInfo += ' ]\n'
} else {
typeInfo += '\n'
}
typeInfo += ' }'
types.push(' ' + typeInfo);
}
fileContent += ' "types":[\n';
fileContent += types.join(',\n');
fileContent += ']\n'
}
fileContent += '}'
fileContent = fileContent.split(',"originalName"').join(', "originalName"');
fileContent = fileContent.split(',"mappedType"').join(', "mappedType"');
fileContent = fileContent.split('"mappedType":"IgPoint",').join('"mappedType":"IgPoint", ');
fileContent = fileContent.split('"mappedType":"IgSize",' ).join('"mappedType":"IgSize", ');
fileContent = fileContent.split('"mappedType":"IgRect",' ).join('"mappedType":"IgRect", ');
fileContent = fileContent.split('"mappedType":"method",' ).join('"mappedType":"method", ');
fileContent = fileContent.split('"mappedType":"string",' ).join('"mappedType":"string", ');
fileContent = fileContent.split('"mappedType":"number",' ).join('"mappedType":"number", ');
fileContent = fileContent.split('"mappedType":"boolean",').join('"mappedType":"boolean", ');
fileContent = fileContent.split('"mappedType":"any[]",' ).join('"mappedType":"any[]", ');
fileContent = fileContent.split('"mappedType":"bool",' ).join('"mappedType":"bool", ');
fileContent = fileContent.split('"mappedType":"int",' ).join('"mappedType":"int", ');
fileContent = fileContent.split('"mappedType":"any",' ).join('"mappedType":"any", ');
fileContent = fileContent.split('":"').join('": "');
return fileContent;
}
function testApiFormat(cb) {
var fileName = "DataChart.DOUGHNUTCHART.JS.apiMap"; //"ZoomSlider.JS.apiMap";
var filePath2 = 'C:\\WORK\\igniteui-xplat-docs\\apiMap\\Angular\\' + fileName + '.json';
let jsonContent = fs.readFileSync(filePath2).toString();
let fileContent = updateApiFormat(jsonContent);
var filePath = 'C:\\WORK\\igniteui-xplat-docs\\apiMap\\Angular\\' + fileName + '2.json';
fs.writeFileSync(filePath, fileContent);
console.log(filePath)
cb();
}
exports.testApiFormat = testApiFormat;
var mappedFiles = {};
// updates API mapping files in ./apiMap folder for specified platform
function updateApiFor(platformName) {
// cleanup previous API mapping files
// del.sync("apiMap/" + platformName + "/*apiMap.json");
mappedFiles[platformName] = [];
return gulp.src([
fileRoot + "Source/*.JS/**/bin/**/" + platformName + "/*apiMap.json",
// excluding API mapping files for conflicting components with WebInputs
'!' + fileRoot + "Source/*.JS/**/bin/**/" + platformName + "/Inputs*apiMap.json",
'!' + fileRoot + "Source/*.JS/**/bin/**/" + platformName + "/Calendar*apiMap.json"
])
.pipe(es.map(function(file, fileCallback) {
let jsonContent = file.contents.toString();
let fileContent = updateApiFormat(jsonContent);
file.contents = Buffer.from(fileContent);
let filePath = file.dirname + "\\" + file.basename;
mappedFiles[platformName].push(filePath);
LOG.info('mapping ' + filePath);
// let oldFileContent = fs.readFileSync(filePath).toString();
// if (fileContent.trim() !== oldFileContent.trim()) {
// file.contents = Buffer.from(fileContent);
// fs.writeFileSync(filePath, fileContent);
// }
fileCallback(null, file);
}))
.pipe(flatten())
.pipe(gulp.dest("apiMap/" + platformName))
.on("end", () => {
LOG.action('mapping ... completed with ' + mappedFiles[platformName].length + ' files');
});
}
function updateApiStats(cb) {
var platforms = ['Angular', 'Blazor', 'React', 'WebComponents'];
for (const plat of platforms) {
if (mappedFiles[plat])
LOG.action('mapped ' + mappedFiles[plat].length + ' json files for ' + plat);
}
if (cb) cb();
}
// updates API mapping files in ./apiMap folder for all platforms
exports.updateApiMapping = updateApiMapping = gulp.series(
updateApiAngular,
updateApiBlazor,
updateApiReact,
updateApiWebComponents,
updateApiStats
);
function updateApiSection(cb) {
ensureEnvironment();
gulp.src([
// 'doc/en/**/gantt-chart.md',
// 'doc/en/**/area-chart.md',
// 'doc/en/**/types/*.md',
'doc/en/**/features/chart-*.md',
])
.pipe(es.map(function(file, fileCallback) {
// let markdownContent = file.contents.toString();
// read converted .yml to .json above and simplify TOC structure:
// let newJson = transformer.simplifyJson(orgJson, 'Blazor');
// fs.writeFileSync(tocOutputPath, newJson);
var filePath = file.dirname + "\\" + file.basename
console.log('updating API Section: ' + filePath);
var fileContent = file.contents.toString();
if (transformer) {
// file.contents = Buffer.from(transformer.updateApiSection(fileContent));
var newContent = transformer.updateApiSection(fileContent, filePath);
fs.writeFileSync(filePath, newContent);
}
fileCallback(null, file);
}))
.on("end", () => {
cb();
})
.on("error", (err) => {
console.log("ERROR in updateApiSection()");
cb(err);
});
}
exports.updateApiSection = updateApiSection;
function verifyApiSections(cb) {
// ensureEnvironment();
gulp.src([
'doc/en/**/gantt-chart.md',
'doc/en/**/area-chart.md',
'doc/en/**/types/*.md',
'doc/en/**/features/chart-*.md',
'doc/en/**/geo-*.md',
'doc/en/**/excel-*.md',
'doc/en/**/spreadsheet-*.md',
'doc/en/**/*gauge.md',
'doc/en/**/bullet-*.md',
'doc/en/**/zoomslider-*.md',
'doc/en/**/grids/*.md',
'doc/en/**/editors/*.md',
'doc/en/**/inputs/*.md',
'doc/en/**/layouts/*.md',
'doc/en/**/notifications/*.md',
'doc/en/**/scheduling/*.md',
'doc/en/**/themes/*.md',
'doc/en/**/menus/*.md',
// 'doc/en/**/*.md',
])
.pipe(es.map(function(file, fileCallback) {
var filePath = file.dirname + "\\" + file.basename
var fileContent = file.contents.toString();
var fileHasAPI = fileContent.indexOf("API References") > 0;
if (!fileHasAPI) {
let apiLinks = [];
let words = fileContent.split(' ');
for (const w of words) {
if (!apiLinks.includes(w) && w !== "" && w.indexOf('`') === 0) {
apiLinks.push(w.replace(",","").replace(".","").replace(":",""));
}
}
let lines = fileContent.split("\n");
for (const line of lines) {
if (line.indexOf('mentionedTypes:') >= 0) {
let items = line.replace("mentionedTypes:","").replace("[","").replace("]","").trim().split(",");
for (const item of items) {
if (!apiLinks.includes(item)) {
let link = item.replace('"',"").replace('"',"").replace("'","").replace("'","").trim()
apiLinks.push("`" + link + "`");
}
}
break;
}
}
if (apiLinks.length > 0) {
apiLinks.sort();
console.log('missing API Section: ' + filePath + "\n## API References \n\n - " + apiLinks.join("\n - "));
}
}
fileCallback(null, file);
}))
.on("end", () => {
cb();
})
.on("error", (err) => {
console.log("ERROR in verifyApiSections()");
cb(err);
});
}
exports.verifyApiSections = verifyApiSections;
// this array stores actual topic that are resolved from TOC and optional excludedTopics array
let includedTopics = [];
function buildTOC(cb) {
let excludedTopics = [];
excludedTopics.push('doc/**/obsolete*.md');
// uncomment these lines to build docs without topics:
// excludedTopics.push('doc/**/general*.md');
// excludedTopics.push('doc/**/general-getting-started.md');
// excludedTopics.push('doc/**/general-getting-started-*.md');
// excludedTopics.push('doc/**/general-changelog-dv.md');
// excludedTopics.push('doc/**/general-changelog*.md');
// excludedTopics.push('doc/**/general-nuget-feed.md');
// excludedTopics.push('doc/**/general-installing-blazor.md');
// excludedTopics.push('doc/**/general-cli*.md');
// excludedTopics.push('doc/**/grids/**/*.md');
// excludedTopics.push('doc/**/grids/_shared/*.md');
// excludedTopics.push('doc/**/grids/grid/*.md');
// excludedTopics.push('doc/**/grids/grids-header.md');
// excludedTopics.push('doc/**/grids/data-grid*.md');
// excludedTopics.push('doc/**/grids/data-grid/*.md');
// excludedTopics.push('doc/**/grids/combo/*.md');
// excludedTopics.push('doc/**/grids/pivot-grid/*.md');
// excludedTopics.push('doc/**/grids/tree-grid/*.md');
// excludedTopics.push('doc/**/grids/hierarchical-grid/*.md');
// excludedTopics.push('doc/**/grids/theming.md');
// excludedTopics.push('doc/**/grids/tree.md');
// excludedTopics.push('doc/**/grids/list.md');
// excludedTopics.push('doc/**/charts/**/*.md');
// excludedTopics.push('doc/**/charts/features/*.md');
// excludedTopics.push('doc/**/charts/types/*.md');
// excludedTopics.push('doc/**/charts/chart-features.md');
// excludedTopics.push('doc/**/charts/chart-api.md');
// excludedTopics.push('doc/**/charts/chart-overview.md');
// excludedTopics.push('doc/**/editors/**/*.md');
// excludedTopics.push('doc/**/inputs/**/*.md');
// excludedTopics.push('doc/**/layouts/**/*.md');
// excludedTopics.push('doc/**/layouts/avatar.md');
// excludedTopics.push('doc/**/layouts/card.md');
// excludedTopics.push('doc/**/layouts/dock-manager-*.md');
// excludedTopics.push('doc/**/layouts/expansion-panel.md');
// excludedTopics.push('doc/**/layouts/icon.md');
// excludedTopics.push('doc/**/menus/**/*.md');
// excludedTopics.push('doc/**/*map*.md');
// excludedTopics.push('doc/**/bullet-graph.md');
// excludedTopics.push('doc/**/linear-gauge.md');
// excludedTopics.push('doc/**/radial-gauge.md');
// excludedTopics.push('doc/**/*excel*.md');
// excludedTopics.push('doc/**/spreadsheet*.md');
// excludedTopics.push('doc/**/scheduling/*.md');
// excludedTopics.push('doc/**/notifications/*.md');
// excludedTopics.push('doc/**/themes/*.md');
// excludedTopics.push('doc/**/zoomslider-overview.md');
// uncomment these lines to skip JP and KR topics:
// excludedTopics.push('doc/**/jp/**/*.md');
// excludedTopics.push('doc/**/kr/**/*.md');
LOG.action("excludedTopicPatterns: " + excludedTopics.length);
let platformName = PLAT;
if (platformName === "Angular") {
// excluding grids and shared topics from angular builds
excludedTopics.push('doc/**/grids/**/*.md');
excludedTopics.push('doc/**/grids/_shared/*.md');
}
let excludedFiles = [];
gulp.src(excludedTopics)
.pipe(es.map(function(file, fileCallback) {
var filePath = file.path.split('\\').join('/');
var fileLocal = 'doc/' + filePath.split('/doc/')[1];
if (excludedFiles.indexOf(fileLocal) < 0) {
excludedFiles.push(fileLocal);
}
fileCallback(null, file);
}))
.on("end", () => {
LOG.info("excludedTopicFiles: " + excludedFiles.length);
let platformName = PLAT;
ensureEnvironment();
// checking if we need to hide NEW and UPDATED labels in TOC for the first release of product, e.g. Blazor
let isFirstRelease = docsConfig[platformName].isFirstRelease;
// generating an array of topic and TOC.yml files from TOC.json files:
let enTopics = generateTocFor(platformName, 'en', isFirstRelease, excludedFiles);
let jpTopics = generateTocFor(platformName, 'jp', isFirstRelease, excludedFiles);
let krTopics = generateTocFor(platformName, 'kr', isFirstRelease, excludedFiles);
var tocTopics = [];
tocTopics = tocTopics.concat(enTopics); // including EN topics
tocTopics = tocTopics.concat(jpTopics); // including JP topics
tocTopics = tocTopics.concat(krTopics); // including KR topics
tocTopics.sort();
LOG.action("TOC generated topics: " + tocTopics.length);
// fs.writeFileSync("file-toc.txt", "file-toc \n" + tocTopics.join("\n"));
// for (const topic of tocTopics) {
// LOG.info(topic);
// }
var sharedComponents = []; // "grid", "hierarchical-grid", "pivot-grid", "tree-grid"];
for (let component of Object.values(docsComponents)) {
if (component.output) {
sharedComponents.push(component.output);
}
}
includedTopics = [];
// processing all markdown files to check if they are included in TOC and are not part of excluded files
gulp.src(['doc/**/*.md'])
.pipe(es.map(function(topicFile, topicCallback) {
var filePath = topicFile.path.split('\\').join('/');
var fileLocal = 'doc/' + filePath.split('/doc/')[1];
var isFileExcluded = excludedFiles.indexOf(fileLocal) >= 0;
var isFileShared = filePath.indexOf("/_shared/") > 0;
// check if file is included in TOC
var isFileIncludedInTOC = tocTopics.indexOf(fileLocal) >= 0;
if (!isFileIncludedInTOC && isFileShared) {
// check if resolved path of shared file is included in TOC
for (const component of sharedComponents) {
var resolvedPath = fileLocal.replace("_shared", component);
var resolvedInTOC = tocTopics.indexOf(resolvedPath) >= 0;
if (resolvedInTOC) {
isFileIncludedInTOC = true; break;
}
}
}
// skip topics that are explicitly excluded and include only topics that are in TOC
if (!isFileExcluded && isFileIncludedInTOC) {
includedTopics.push(fileLocal);
}
topicCallback(null, topicFile);
}))
.on("end", () => {
includedTopics.sort();
LOG.info("includedTopics: " + includedTopics.length);
// console.log(includedTopics);
// fs.writeFileSync("file-included.txt", "file-included \n" + includedTopics.join("\n"));
// for (const topic of includedTopics) {
// LOG.info(topic);
// }
cb();
})
});
}
exports.buildTOC = buildTOC;
// function buildPlatform(cb, platformName, apiPlatform) {
function buildPlatform(cb) {
let platformName = PLAT;
let apiPlatform = PLAT_API;
LOG.info("=========================================================");
LOG.action("building '" + PLAT + "' docs for '" + ENV_TARGET + "' environment and force docFX output is " + DOCFX_FORCE_OUTPUT );
ensureEnvironment();
LOG.action("building with " + includedTopics.length + " topics");
// for (const topic of includedTopics) {
// LOG.action("act Topic " + topic);
// }
let apiSourcePath = './apiMap/' + platformName + '/**/*apiMap.json';
LOG.action("building with API mapping: " + apiSourcePath);
gulp.src([
apiSourcePath
],)
.pipe(flatten())
.pipe(readMappings())
.on("end", () => {
transformer.configure(loader, apiPlatform, docsConfig[platformName], ENV_TARGET);
// the includedTopics array is generated in buildTOC task
let sources = includedTopics;
// uncomment to force building specific set of topics
// let sources = [
// 'doc/en/components/grids/grid/overview.md',
// 'doc/en/components/grids/_shared/editing.md',
// 'doc/en/components/grids/data-grid.md',
// // 'doc/en/**/*.md',
// // 'doc/jp/**/*.md',
// // 'doc/kr/**/*.md',
// ];
gulp.src(sources, { base: "./doc/" })
.pipe(transformFiles())
.pipe(gulp.dest("dist/" + platformName))
.on("end", function() {
gulp.src([
'doc/**/images/**/*.*'
])
.pipe(gulp.dest("dist/" + platformName))
.on("end", function () {
if (platformName == "Angular" && !DOCFX_FORCE_OUTPUT) {
LOG.action("copying " + PLAT + " .md and /images... done. Docfx build not executed.");
LOG.info("=========================================================");
cb();
} else {
gulp.src([
'docfx/**/*.*'
])
.pipe(transformStaticFiles(platformName))
.pipe(gulp.dest("dist/" + platformName))
.on("end", function () {
LOG.action("building " + PLAT + " ... done ");
LOG.info("=========================================================");
cb();
});
}
});
})
.on("error", (err) => {
console.log("ERROR building platform: " + platformName.toString());
cb(err);
});
})
.on("error", (err) => {
console.log("ERROR building platform: " + platformName.toString());
cb(err);
});
}
function replaceEnvironmentVariables(cb) {
const environment = ENV_TARGET ? ENV_TARGET.trim() : 'development';
const config = require(`./docfx/${LANG}/environment.json`);
return gulp.src(`${DOCFX_SITE}/**/*.html`)
.pipe(replace(/(\{|\%7B)environment:([a-zA-Z]+)(\}|\%7D)/g, function (match, brace1, envVariable, brace2) {
const value = config[environment][envVariable];
return value || match;
}))
.pipe(gulp.dest(DOCFX_SITE));
}
let tocLanguage = 'en';
// let tocLanguage = 'jp';
// let tocLanguage = 'kr';
// converts "toc.yml" to "toc.json" file - this is only for testing
function generateTocJson(cb) {
ensureEnvironment();
let tocInputPath = './docfx/' + tocLanguage + '/components/toc.yml';
let tocOutputPath = './docfx/' + tocLanguage + '/components/toc.json';
console.log("convertYmlToJson :");
console.log(" " + tocInputPath + " to");
console.log(" " + tocOutputPath);
gulp.src(tocInputPath)
.pipe(yaml({ schema: 'DEFAULT_FULL_SCHEMA', space: 2 }))
.pipe(es.map(function(file, fileCallback) {
let orgJson = file.contents.toString();
// read converted .yml to .json above and simplify TOC structure:
let newJson = transformer.simplifyJson(orgJson, 'Blazor');
fs.writeFileSync(tocOutputPath, newJson);
fileCallback(null, file);
}))
// .pipe(gulp.dest('./test'))
.on("end", () => {
if (cb !== undefined){
cb();
}
});
}
exports.generateTocJson = generateTocJson;
// converts "toc.json" to "toc.yml" file - this is called before building docs
function generateTocYML(cb) {
console.log('generateTocYML PLAT=' + PLAT + ' LANG=' + LANG);
// PLAT defaults to "React" if --plat argument is not specified
// LANG defaults to "en" if --lang argument is not specified
generateTocFor(PLAT, LANG);
// generateTocFor(PLAT, 'en');
// generateTocFor(PLAT, 'jp');
// generateTocFor(PLAT, 'kr');
cb();
}
exports.generateTocYML = generateTocYML;
// generate "toc.yml" file from "toc.json" by filtering its nodes for specified platform name
// e.g. generateTocFor('All', 'en');
// e.g. generateTocFor('Angular', 'en');
// e.g. generateTocFor('React', 'en');
// e.g. generateTocFor('Blazor', 'en');
function generateTocFor(platform, language, isFirstRelease, excludedFiles) {
ensureEnvironment();
transformer.docsLanguage = language;
let tocPath = './docfx/' + language + '/components/toc.json';
let tocTopics = transformer.generateTOC(tocPath, platform, language, isFirstRelease, excludedFiles);
for (let i = 0; i < tocTopics.length; i++) {
tocTopics[i] = 'doc/' + language + '/components/' + tocTopics[i];
// console.log('>> generateTocFor "' + tocTopics[i] + '"');
}
// filter out duplicates toc nodes
tocTopics = tocTopics.filter((c, index) => {
return tocTopics.indexOf(c) === index;
});
tocTopics.sort();
return tocTopics;
}
function copyWebConfig(cb) {
LOG.action("copying ./web.config to ./docfx/en/web.config ...");
LOG.action("copying ./web.config to ./docfx/jp/web.config ...");
LOG.action("copying ./web.config to ./docfx/kr/web.config ...");
gulp.src(['./web.config'])
.pipe(gulp.dest("docfx/en"))
.pipe(gulp.dest("docfx/jp"))
.pipe(gulp.dest("docfx/kr"))
.on("end", () => {
// LOG.action("copying ./web.config to ./docfx/en/web.config ... done");
// LOG.action("copying ./web.config to ./docfx/jp/web.config ... done");
// LOG.action("copying ./web.config to ./docfx/kr/web.config ... done");
if (cb) { cb() };
})
}
exports.copyWebConfig = copyWebConfig
function updateSiteMap(cb) {
if (cb) {
ensureEnvironment();
};
var sitemapPath = DOCFX_SITE + "/sitemap.xml";
LOG.action("updating " + sitemapPath);
let oldContent = fs.readFileSync(sitemapPath).toString();
let newContent = oldContent.split('.html').join('');
fs.writeFileSync(sitemapPath, newContent);
if (cb) { cb() };
}
exports.updateSiteMap = updateSiteMap
// generates JSON files with stats about samples used in xplatform docs that
// you can use to lookup samples used in each topic or find which topics uses samples
// these files are saved in output folder ./dist/[PLATFORM]/end/_site/stats.json
// as well as in the stats folder:
// ./stats/docsStats-Angular.json
// ./stats/docsStats-Blazor.json
// ./stats/docsStats-React.json
// ./stats/docsStats-WC.json
function buildStats(cb) {
var config = docsConfig[PLAT];
var docStats = {}
docStats.note = "this auto-generated file provides stats about samples used in " + PLAT + " documentation";
docStats.info = "you can lookup samples in 'samplesUsage' or lookup topics in 'topicsWithSamples' ";
docStats.platform = PLAT;
// docStats.samplesEnv = ENV_TARGET;
// docStats.samplesBrowsers = config.samplesBrowsers;
docStats.samplesCount = 0
docStats.samplesHost = config.samplesBrowsers.staging + '/samples'; //[docStats.samplesEnv];
docStats.samplesNote = "the 'samplesUsage' provides lookup of samples usage in topics"
docStats.samplesUsage = {}
docStats.topicsCount = 0
if (PLAT === "Angular") {
docStats.topicsHost = 'https://staging.infragistics.com/products/ignite-ui-angular/angular/components';
} else if (PLAT === "Blazor") {
docStats.topicsHost = 'https://staging.infragistics.com/products/ignite-ui-blazor/blazor/components';
} else if (PLAT === "React") {
docStats.topicsHost = 'https://staging.infragistics.com/products/ignite-ui-react/react/components';
} else if (PLAT === "WebComponents") {
docStats.topicsHost = 'https://staging.infragistics.com/products/ignite-ui-web-components/web-components/components';
}
docStats.topicsNote = "the 'topicsWithSamples' provides lookup of topics that used at least 1 sample"
docStats.topicsWithSamples = {}
if (!fs.existsSync(DOCFX_SITE)) {
fs.mkdirSync(DOCFX_SITE);
}
gulp.src([
DOCFX_PATH + '/components/**/*.md',
])
.pipe(es.map(function(file, fileCallback) {
docStats.topicsCount++;
var fileContent = file.contents.toString();
var filePath = file.dirname + "\\" + file.basename.replace('.md', '');
// console.log("stats " + filePath);
var topic = '/' + filePath.split('\\components\\')[1];
if (topic.indexOf('\\') > 0) {
topic = topic.split('\\').join('/');
}
topic = docStats.topicsHost + topic;
var fileLines = fileContent.split("\n");
var lineIndex = 0;
for (const line of fileLines) {
if (line.indexOf('iframe-src="') >= 0) {
var link = line.replace('iframe-src="', '');
link = link.trim();
link = link.replace('"', '');
link = link.replace('`', '');
link = link.replace('{environment:dvDemosBaseUrl}', '');
link = link.replace('{environment:demosBaseUrl}', '');
link = link.replace(config.samplesBrowsers.development, '');
link = link.replace(config.samplesBrowsers.staging, '');
link = link.replace(config.samplesBrowsers.production, '');
link = docStats.samplesHost + '/samples' + link;
// if (docStats.samplesHost) {
// link = link.replace(docStats.samplesHost, '');
// }
// creating lookup of samples
if (docStats.samplesUsage[link] === undefined) {
docStats.samplesUsage[link] = [];
docStats.samplesCount++;
}
if (docStats.samplesUsage[link].indexOf(topic) < 0) {
docStats.samplesUsage[link].push(topic);
}
// creating lookup of topics with samples
if (docStats.topicsWithSamples[topic] === undefined) {
docStats.topicsWithSamples[topic] = [];
}
if (docStats.topicsWithSamples[topic].indexOf(link) < 0) {
docStats.topicsWithSamples[topic].push(link);
}
}
lineIndex++;
}
fileCallback(null, file);
}))
.on("end", () => {
if (docStats.samplesCount > 0) {
// sort usage of sample links alphabetically
var sampleMappings = {};
var sampleLinks = Object.keys(docStats.samplesUsage);
sampleLinks.sort();
for (const link of sampleLinks) {
var topicsArray = docStats.samplesUsage[link];
topicsArray.sort();
// compact json - temporary replacing [] with <> in short arrays
// if (topicsArray.length === 1) {
// topicsArray = '<' + topicsArray[0] + '>'
// }
sampleMappings[link] = topicsArray; //docStats.samplesUsage[link]; //.join(',');
}
docStats.samplesUsage = sampleMappings;
// sorting usage of topics links alphabetically
var topicMappings = {};
var topicNames = Object.keys(docStats.topicsWithSamples);
topicNames.sort();
for (const topic of topicNames) {
var samplesArray = docStats.topicsWithSamples[topic];
samplesArray.sort();
// compact json - temporary replacing [] with <> in short arrays
// if (samplesArray.length === 1) {
// samplesArray = '<' + samplesArray[0] + '>'
// }
topicMappings[topic] = samplesArray;
}
docStats.topicsWithSamples = topicMappings;
var statsPlatform = docStats.platform.replace('WebComponents','WC');
var statsPath = DOCFX_SITE + "/stats.json";
var statsData = JSON.stringify(docStats, null, ' ');
// compact json - replacing <> with [] in short arrays
statsData = statsData.replace(/\"\</g,'[ "');
statsData = statsData.replace(/\>\"/g,'" ]');
console.log('extracted stats for docs and samples to: ' + statsPath);
fs.writeFileSync(statsPath, statsData);
if (LANG === 'en') {
fs.writeFileSync('./stats/docStats-' + statsPlatform + '.json', statsData);
}
}
if (cb) cb();
})
}
exports.buildStats = buildStats
var verifyFiles = gulp.series(verifyMarkdown);
function buildCore(cb) {
// clean output files
LOG.action("cleaning ...");
del.sync("dist/" + PLAT + "/**/*.*");
del.sync("dist/" + PLAT + "/**");
ensureEnvironment();
copyWebConfig();
buildPlatform(cb);
}
exports.buildCoreAndTOC = buildCoreAndTOC = gulp.series(buildTOC, buildCore, buildStats)
// functions for building each platform:
function buildAngularDocFX(cb) { PLAT = "Angular"; DOCFX_FORCE_OUTPUT = true; buildCoreAndTOC(cb); }
function buildAngular(cb) { PLAT = "Angular"; DOCFX_FORCE_OUTPUT = false; buildCoreAndTOC(cb); }
function buildBlazor(cb) { PLAT = "Blazor"; buildCoreAndTOC(cb); }
function buildReact(cb) { PLAT = "React"; buildCoreAndTOC(cb); }
function buildWC(cb) { PLAT = "WebComponents"; buildCoreAndTOC(cb); }
// function for building output of a platform specified in arguments, e.g. --plat=React
function buildWithArgs(cb) { buildCoreAndTOC(cb); }
// exporting build functions for each platform:
exports['buildOutputAngular'] = gulp.series(verifyFiles, buildAngular)
exports['buildOutputBlazor'] = gulp.series(verifyFiles, buildBlazor)
exports['buildOutputReact'] = gulp.series(verifyFiles, buildReact)
exports['buildOutputWC'] = gulp.series(verifyFiles, buildWC)
exports['buildWithArgs'] = gulp.series(verifyFiles, buildWithArgs)
// function for building all platforms:
exports.buildAll = buildAll = gulp.series(buildAngular, buildReact, buildWC, buildBlazor);
function serveCore(cb) {
browserSync.init({
server: {
baseDir: `${DOCFX_SITE}`
},
notify: {
styles: {
top: 'auto',
bottom: '0',
margin: '0px',
padding: '5px',
position: 'fixed',
fontSize: '10px',