-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathgulpfile.js
More file actions
563 lines (519 loc) · 22.2 KB
/
Copy pathgulpfile.js
File metadata and controls
563 lines (519 loc) · 22.2 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
var gulp = require("gulp");
module.exports = gulp;
const glob = require('glob');
var window = {};
var fs = require('fs');
var elasticlunr = require('elasticlunr');
var config = require('./wwwroot/scripts/samplelist.js');
var beautify = require('json-beautify');
var configJson = JSON.parse(fs.readFileSync('./config.json'));
var fsPath = require('path');
var shelljs = require('shelljs');
const { title } = require("process");
require("@syncfusion/ej2-staging");
const table = require("table");
const fetch = require("node-fetch").default
gulp.task('generate-searchlist', function (done) {
console.log(config);
generateSearchIndex(config.window.samplesList);
done();
});
gulp.task('createLocale', function (done) {
var localeJson = glob.sync('./Views/**/locale.json', {
silent: true
});
if (localeJson.length) {
var obj = [];
for (var i = 0; i < localeJson.length; i++) {
var compentLocale = JSON.parse(fs.readFileSync(localeJson[i]));
obj.push(compentLocale);
fs.writeFileSync('./wwwroot/scripts/locale-string.js', 'window.Locale = ' + JSON.stringify(obj));
}
}
else {
fs.writeFileSync('./wwwroot/scripts/locale-string.js', 'window.Locale = {}');
}
done();
});
function generateSearchIndex(data) {
var result = [];
var updatedList;
var subCategory = [];
var intId = 0;
var addUID = function (pid, dt) {
for (var i = 0; i < dt.length; i++) {
dt[i].uid = pid + i;
if (dt[i].hasOwnProperty('samples')) {
curDirectory = dt[i].directory;
subCategory = [];
addUID('00' + intId + i, dt[i].samples);
intId++;
var isLast = intId === dt.length - 1;
} else {
var index = subCategory.indexOf(dt[i].category);
if (index !== -1) {
dt[i].order = index;
} else {
subCategory.push(dt[i].category);
dt[i].order = subCategory.length - 1;
}
}
}
updatedList = dt;
if (isLast) {
fs.writeFileSync('./wwwroot/scripts/samplelist.js', JSON.stringify(updatedList), null, '\t');
}
}
var sampleOrder = JSON.parse(fs.readFileSync('./wwwroot/scripts/sampleOrder.json', 'utf8'));
var orderKeys = Object.keys(sampleOrder);
for (var i = 0; i < orderKeys.length; i++) {
var components = sampleOrder[orderKeys[i]];
for (var j = 0; j < components.length; j++) {
var currentData = getSamples(data, components[j]);
currentData['order'] = i;
result.push(currentData);
}
}
addUID("0", result);
// generateSearchIndex(result);
// return new Buffer('window.samplesList =' + JSON.stringify(result) + ';\n\n' + 'window.apiList =' + JSON.stringify(apiReference));
elasticlunr.clearStopWords();
var instance = elasticlunr(function () {
this.addField('component');
this.addField('name');
this.setRef('uid');
});
for (sampleCollection of data) {
var component = sampleCollection.name;
var directory = sampleCollection.directory;
var puid = sampleCollection.uid;
var hideOnDevice = sampleCollection.hideOnDevice;
for (sample of sampleCollection.samples) {
sample.component = component;
sample.dir = directory;
sample.parentId = puid;
sample.hideOnDevice = hideOnDevice;
instance.addDoc(sample);
}
}
var string = `if (!window) {
var window = exports.window = {};
}
window.samplesList =`;
fs.writeFileSync('./wwwroot/scripts/samplelist.js', string + beautify(updatedList, null, 2, 100));
fs.writeFileSync('./wwwroot/scripts/search-index.js', 'window.searchIndex = ' + JSON.stringify(instance.toJSON()));
}
function getSamples(data, component) {
for (var i = 0; i < data.length; i++) {
if (component === data[i].directory) {
return data[i];
}
}
}
gulp.task('desValidation', function (done) {
var files = glob.sync('./Views/*/*', {
silent: true,
ignore: [
'./Views/Shared/*', './Views/**/locale.json', './Views/**/fonts', './Views/**/icons', './Views/**/Index.cshtml', './Views/Grid/_DialogAddPartial.cshtml', './Views/Grid/_DialogEditPartial.cshtml'
]
});
var reg = /.*meta name([\S\s]*?)\/.*/g;
var reg1 = /\"([^"]+)\"/g;
var error = "";
var des = "";
for (var i = 573; i < files.length; i++) {
var url = files[i].split('/')[2] + '/' + files[i].split('/')[3];
var cshtml = fs.readFileSync(files[i], 'utf8');
if (reg.test(cshtml)) {
cshtml = cshtml.match(reg)[0].match(reg1)[1].replace(/"/g, "");
if (!(cshtml.length >= 100) && (cshtml.length <= 160)) {
error = error + url + ' description length should be between 100 to 160 characters\n';
}
} else {
des = des + url + ' description needed\n';
}
}
if (error || des) {
if (!fs.existsSync('./cireports/logs')) {
fs.mkdirSync('./cireports/logs', { recursive: true });
}
fs.writeFileSync('./cireports/logs/descriptionValidation.txt', error + des, 'utf-8');
done();
}
done();
});
gulp.task('testing', function(done){
var title = adjustTitle('MultiColumn ComboBox', 'data-binding support');
console.log(title);
done();
})
function adjustTitle(componentName, featureName) {
const shortTemplates = [
`Learn about ${featureName} in ASP.NET Core ${componentName} - Syncfusion Demos`,
`${featureName} feature in ASP.NET Core ${componentName} - Try it now!`
];
const longTemplates = [
`ASP.NET Core ${componentName} ${featureName} - Syncfusion`,
`${featureName} Example using ASP.NET Core ${componentName} - Syncfusion`
];
const base = `ASP.NET Core ${componentName} ${featureName} Example - Syncfusion Demos`;
const baseLength = base.length;
if (baseLength < 50) {
for (let template of shortTemplates) {
if (template.length >= 50 && template.length <= 70) {
return template;
}
}
} else if (baseLength > 70) {
for (let template of longTemplates) {
if (template.length >= 50 && template.length <= 70) {
return template;
}
}
} else {
return base;
}
// If no suitable template found, return the base title with adjustments
return base.length > 70 ? base.substring(0, 67) + '...' : base.padEnd(50, '.');
}
function adjustDescription(featureName, metaControlCategory) {
const shortTemplates = [
`Explore the ${featureName} in ASP.NET Core ${metaControlCategory}. Learn how it helps improve your app's functionality.`,
`This example shows how ${featureName} works in ASP.NET Core ${metaControlCategory}. Understand its purpose and usage.`,
`Discover the ${featureName} feature in ASP.NET Core ${metaControlCategory}. Learn how to use it in real-world scenarios.`,
`Learn how to use ${featureName} in ASP.NET Core ${metaControlCategory}. This guide helps you integrate it effectively.`,
`Understand the ${featureName} in ASP.NET Core ${metaControlCategory}. See how it enhances your development workflow.`,
`Explore ${featureName} in ASP.NET Core ${metaControlCategory}. Learn how to configure and apply it in your projects.`
];
const longTemplates = [
`This example demonstrates the ${featureName} in ASP.NET Core ${metaControlCategory}. Discover its capabilities, integration steps, and customization options.`,
`Explore the ${featureName} feature in ASP.NET Core ${metaControlCategory}. Learn how to use it effectively and integrate it into your application with best practices.`,
`Understand how ${featureName} works in ASP.NET Core ${metaControlCategory}. This guide covers usage, configuration, and advanced customization.`,
`This demo shows how to use ${featureName} in ASP.NET Core ${metaControlCategory}, including setup, configuration, and real-world implementation tips.`,
`Discover the benefits of using ${featureName} in ASP.NET Core ${metaControlCategory}. Learn how to apply it efficiently in your business apps.`,
`Explore ${featureName} in ASP.NET Core ${metaControlCategory}. This example covers integration, customization, and practical usage scenarios.`
];
const base = `This example demonstrates the ${featureName} feature in ASP.NET Core ${metaControlCategory}.Learn how it works and how to integrate it into your application.`
const baseLength = base.length;
if (baseLength < 150) {
for (let template of shortTemplates) {
if (template.length >= 150 && template.length <= 160)
return template;
}
} else if (baseLength > 160) {
for (let template of longTemplates) {
if (template.length >= 150 && template.length <= 160)
return template;
}
}
if(baseLength < 146 && baseLength > 135){
return base + ' Explore here.';
}
if (baseLength < 150 && baseLength > 145) {
return base + 'Check now.';
}
if (baseLength > 160) {
return base.substring(0, 157) + '...';
}
return base;
}
gulp.task('title-section', function (done) {
var samplelists = config.window.samplesList;
var errorFileList = [];
for (let component of samplelists) {
var samples = component.samples;
var category = component.category;
for (let sample of samples) {
let componentName = sample.component;
let controlCategory = componentName + ' Control';
let metaControlCategory = componentName + ' control';
if(category === 'Document Processing Libraries'){
componentName = sample.component + ' library -';
controlCategory = sample.component + ' Library';
metaControlCategory = sample.component + ' library';
}
let featureName = sample.name;
let url = sample.url;
let dir = sample.dir;
let path = `./Pages/${dir}/${url}.cshtml`;
let content;
if (fileExistsWithCaseSync(path)) {
content = fs.readFileSync(path, 'utf8').trim();
}
else {
path = path.replace("Pages", "Views");
if (fileExistsWithCaseSync(path)) {
content = fs.readFileSync(path, 'utf8').trim();
} else {
errorFileList.push(fsPath.basename(path));
}
}
var title = adjustTitle(componentName, featureName);
if(title.length > 70 || title.length < 50) {
throw new Error(`error: The title for ${featureName} in ${componentName} is not within the recommended length. Please adjust it.`);
}
if (typeof content === 'string') {
if ((/@section Title\s?{/).test(content)) {
content = content.replace(/@section Title+{([^}]*)}/g, `@section Title{
<title>${title}</title>
}`).trim();
} else {
content = content + `\n@section Title{
<title>${title}</title>
}`;
}
var description = adjustDescription(featureName, metaControlCategory);
if(description.length > 160 || description.length < 150) {
throw new Error(`error: The description for ${featureName} in ${componentName} is not within the recommended length. Please adjust it.`);
}
if ((/@section Meta\s?{/).test(content)) {
content = content.replace(/@section Meta+{([^}]*)}/g, `@section Meta{
<meta name="description" content="${description}"/>
}`).trim();
} else {
content = content + `\n@section Meta{
<meta name="description" content="${description}"/>
}`;
}
let header = `Example of ${featureName} in ASP.NET Core ${controlCategory}`;
if ((/@section Header\s?{/).test(content)) {
content = content.replace(/@section Header+{([^}]*)}/g, `@section Header{
<h1 class='sb-sample-text'>${header}</h1>
}`).trim();
} else {
content = content + `\n@section Header{
<h1 class='sb-sample-text'>${header}</h1>
}`;
}
fs.writeFileSync(path, content, 'utf-8');
}
}
}
if (errorFileList.length) {
var fileName = '';
var count = 0;
for (var fileList of errorFileList) {
fileName += `${++count}) ${fileList}\n`;
}
console.log(`The below Razor file (cshtml) name and the samplelist URL is mismatching / not equal. Please provide the Razor file (cshtml) name as like in samplelist URL.\n
Expected razor file name:\n\n${fileName}`);
process.exit(1);
}
done();
});
function fileExistsWithCaseSync(filepath) {
var checkPath = (path) => {
var dir = fsPath.dirname(path);
try {
var filenames = fs.readdirSync(dir);
return filenames.indexOf(fsPath.basename(filepath)) !== -1;
} catch (err) {
// If an error occurs (e.g., directory does not exist), return false
return false;
}
};
return checkPath(filepath);
}
const SITEMAP_TEMPLATE =
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">{{:URLS}}
</urlset>`;
const SITE_URL = `
<url>
<loc>{{:DemoPath}}</loc>
<lastmod>{{:Date}}</lastmod>
</url>`;
const LOCAL_SITE_URL = `
<url>
<type>{{:Type}}</type>
<loc>{{:DemoPath}}</loc>
<lastmod>{{:Date}}</lastmod>
</url>`;
gulp.task('sitemap-generate', function (done) {
let siteMapFile = SITEMAP_TEMPLATE;
let date = new Date().toISOString().substring(0, 10);
let link = 'https://ej2.syncfusion.com/aspnetcore/demos';
let xmlstring = '';
let components = config.window.samplesList.map(com => { return { directory: com.directory, type: com.samples.map(list => { return list.type; }), sampleUrls: com.samples.map(samp => { return samp.url; }) }; });
for (let component of components ? components : []) {
let sampleUrls = component.sampleUrls;
let sampleType = component.type;
sampleUrls = sampleUrls ? sampleUrls : [];
sampleType = sampleType ? sampleType : [];
for (let i = 0; i < sampleUrls.length; i++) {
let urls = SITE_URL;
if (process.argv[4] === 'local-sitemap' && sampleType[i] === 'new') {
urls = LOCAL_SITE_URL;
urls = urls.replace(/{{:Type}}/g, 'new');
}
urls = urls.replace(/{{:DemoPath}}/g, `${link}/${component.directory.toLowerCase()}/${sampleUrls[i].toLowerCase()}`);
urls = urls.replace(/{{:Date}}/g, date);
xmlstring += urls;
}
}
siteMapFile = siteMapFile.replace(/{{:URLS}}/g, xmlstring);
if (process.argv[4] === 'local-sitemap') {
fs.writeFileSync('./' + configJson.appName + '-net10/wwwroot/sitemap-demos.xml', siteMapFile, 'utf-8');
} else {
fs.writeFileSync('./sitemap-demos.xml', siteMapFile, 'utf-8');
}
done();
});
gulp.task('code-leaks-analysis', function (done) {
var codeLeaksReport = JSON.parse(fs.readFileSync('GitLeaksReport.json', 'utf-8'));
if (Object(codeLeaksReport).length <= 0) {
console.log("<- No Leaks Found ->");
shelljs.exec('rm GitLeaksReport.json')
}
else {
throw "Please clear the Git Leaks reported issues";
}
done();
});
function getTitleFromHtml(html) {
const match = html.match(/<title[^>]*>([^<]*)<\/title>/i);
return match ? match[1].trim() : '';
}
gulp.task('validate-page-url' , async (done) => {
const linkToFiles = new Map();
const IgnoredLinks = [
'https://www.apple.com/iphone-x/specs/',
'https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(model)}:generateContent?key=${encodeURIComponent(apiKey)}',
'https://example.com/image.jpg',
'https://amazon-service.syncfusion.com/',
'https://services.syncfusion.com/aspnet/production/',
'https://bi.syncfusion.com/olap/msmdpump.dll',
'https://www.googleapis.com/calendar/v3/calendars/',
'https://api.jsonbin.io/v3/b/6912d9ecd0ea881f40e12335',
'https://www.googletagmanager.com/ns.html'
]
const httpsRegex = /https:\/\/[^\s"'<>]+/g;
const filePath = fsPath.resolve(__dirname, 'extractedUrls.txt');
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, '', 'utf8');
} else {
fs.writeFileSync(filePath, '', 'utf8');
}
// validate the the urls
async function validateLinks() {
const redirectedEntries = []
console.log("Validating links.....");
const file = fs.readFileSync("extractedUrls.txt", "utf-8");
const links = (file || '')
.split(/\r?\n/)
.map(l => clean(l.trim()))
.filter(Boolean);
function clean(url) {
if (!url) return '';
url = url.trim().replace(/&/g, '&');
// Case 1: remove trailing `);`
if (url.endsWith(');')) {
return url.slice(0, -2);
}
// Case 2: handle trailing `)`
if (url.endsWith(')')) {
const openIndex = url.lastIndexOf('(');
const closeIndex = url.lastIndexOf(')');
// If there is NO matching '(' before last ')', it's invalid
if (openIndex === -1 || openIndex > closeIndex) {
return url.slice(0, -1);
}
}
return url;
}
for (const link of links) {
if (IgnoredLinks.some(str => link.includes(str))){
continue;
}
try {
let res = await fetch(link);
const html = await res.text();
const title = getTitleFromHtml(html);
// Treat redirects specially: collect them and continue
if(res.redirected){
console.log(`⚠️ The link ${link} is Redirected. Please review and correct it.`);
redirectedEntries.push({ link, files: Array.from(linkToFiles.get(link) || []) });
continue;
}
if (res.status == 404 || /404|error|not found/i.test(title) && !res.status==200) {
TableFormat();
console.log(`❌ The link ${link} is invalid. Please review and correct it.`);
console.log("File Paths: " + Array.from(linkToFiles.get(link)))
process.exit(1);
}
} catch (err) {
TableFormat();
console.log(`${link} → ERROR: ${err.message}`);
process.exit(1);
}
}
TableFormat();
console.log(" ✅ Validation successfully completed");
function TableFormat(){
// If only redirects were found, print a table with folder name and file path
if (redirectedEntries.length) {
console.log('\nRedirected URLs found (folder / file where link appears):');
const tableData = [["Folder", "File Path", "URL"]];
redirectedEntries.forEach(entry => {
entry.files.forEach(file => {
const parts = file.replace(/\\/g, '/').split('/');
// derive folder as second/third segment when possible: Common/Pages/Category
let folder = parts.length > 2 ? `${parts[1]}` : parts.slice(1, 2).join('/');
tableData.push([folder, file, entry.link]);
});
});
const config = { columns: { 0: { width: 30 }, 1: { width: 60 }, 2: { width: 60 } } };
console.log(table.table(tableData, config));
}
}
}
async function main() {
let folderNames = (() => {
try {
const diff = shelljs.exec(`git diff --name-only origin/${process.env.githubTargetBranch}...origin/${process.env.githubSourceBranch}`, { silent: true });
const files = diff.stdout.split(/\r?\n/).map(s => s.trim()).filter(Boolean);
const result = [...new Set(
files
.map(p => p.replace(/\\/g, '/'))
.filter(p => !p.toLowerCase().endsWith('.css'))
.map(p => p.split('/'))
.filter(parts =>
parts.length > 2 &&
(parts[0].toLowerCase() === 'pages')
)
.map(parts => `${parts[1]}`)
)].sort();
return result;
} catch (e) {
return ["Grid"];
}
})();
let changedDir;
if(folderNames!= 0){
console.log(folderNames);
folderNames.forEach(folderName => {
if (folderName != null) {
changedDir = glob.sync(`Pages/${folderName}/*.cshtml`);
const httpsLinks = new Set();
changedDir.forEach(file => {
const content = fs.readFileSync(file, 'utf8');
const matches = content.match(httpsRegex);
if (!matches) return;
matches.forEach(rawLink => {
const link = rawLink.trim();
httpsLinks.add(`\n`);
httpsLinks.add(link);
// record origin file for this link
const existing = linkToFiles.get(link) || new Set();
existing.add(file);
linkToFiles.set(link, existing);
});
});
fs.appendFileSync('extractedUrls.txt', [...httpsLinks].join('\n'));
}
})
await validateLinks();
}
}
await main();
done();
});