-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathgulpfile.js
More file actions
394 lines (369 loc) · 16.1 KB
/
Copy pathgulpfile.js
File metadata and controls
394 lines (369 loc) · 16.1 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
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");
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();
});