Skip to content

Commit abbcb30

Browse files
committed
config(EJ2-5374): Modified sample browser layout
1 parent cb08c02 commit abbcb30

File tree

1,561 files changed

+24956
-25246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,561 files changed

+24956
-25246
lines changed

config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"styleDependency":["ej2"],
3+
"ts": ["./src/**/*.tsx","./src/**/*.ts", "!./node_modules/**/*.ts","!./node_modules/**/*.tsx"]
4+
}

favicon.ico

6.42 KB
Binary file not shown.

gulpfile.js

Lines changed: 271 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,292 @@
1-
'use strict';
1+
var gulp = require("gulp");
2+
//var browserSync = require('browser-sync');
3+
var webpackConfig = require("./webpack.config.js");
4+
var webpack = require('webpack');
5+
var gulpWebpack = require('gulp-webpack');
6+
var elasticlunr = require('elasticlunr');
7+
var glob = require('glob');
8+
var fs = require('fs');
9+
var configRegex = /\[(.*)\]/;
10+
var shelljs = require('shelljs');
11+
var runSequence = require('run-sequence')
212

3-
var gulp = require('gulp');
4-
5-
/**
6-
* Build ts and scss files
7-
*/
8-
gulp.task('build', ['scripts', 'styles']);
9-
10-
/**
11-
* Compile ts files
12-
*/
13-
gulp.task('scripts', function(done) {
13+
gulp.task('scripts', function (done) {
1414
var ts = require('gulp-typescript');
1515
var tsProject = ts.createProject('tsconfig.json', { typescript: require('typescript') });
1616

17-
var tsResult = gulp.src(['./**/*.ts','./**/*.tsx', '!./node_modules/**/*.ts','!./node_modules/**/*.tsx'], { base: '.' })
17+
var tsResult = gulp.src(['./**/*.ts', './**/*.tsx', '!./node_modules/**/*.ts', '!./node_modules/**/*.tsx','!./samples/**/*.tsx'], { base: '.' })
1818
.pipe(tsProject());
1919
tsResult.js.pipe(gulp.dest('./'))
20-
.on('end', function() {
20+
.on('end', function () {
2121
done();
2222
});
2323
});
2424

2525
/**
2626
* Compile styles
2727
*/
28-
gulp.task('styles', function() {
28+
gulp.task('styles', function () {
2929
var sass = require('gulp-sass');
3030
return gulp.src(['./**/*.scss', '!./node_modules/**/*.scss'], { base: './' })
3131
.pipe(sass({
3232
outputStyle: 'expanded',
3333
includePaths: './node_modules/@syncfusion/'
3434
}))
3535
.pipe(gulp.dest('.'));
36+
});
37+
38+
gulp.task('generate-router', function (done) {
39+
var imports = '';
40+
var compRoutes = '';
41+
var allconfig = '';
42+
var categories = '{';
43+
var files = glob.sync('./src/**/config.tsx');
44+
elasticlunr.clearStopWords();
45+
var instance = elasticlunr(function () {
46+
this.addField('component');
47+
this.addField('name');
48+
this.setRef('uid');
49+
});
50+
var uid = 0;
51+
for (var file of files) {
52+
var routeconfig = '';
53+
var localimports = '';
54+
var routes = ''
55+
var path = file.slice(0, file.lastIndexOf('/'));
56+
var compName = path.slice(path.lastIndexOf('/') + 1);
57+
var componentName = compName.replace('-', '');
58+
var curfile = JSON.stringify(fs.readFileSync(file, 'utf8'));
59+
var trimmedFile = curfile.replace(/\\n|\\r/g, '');
60+
routeconfig = trimmedFile.match(configRegex)[1];
61+
routeconfig = "{\"value\":[" + routeconfig + "]}";
62+
routeconfig = routeconfig.replace(/'/g, '"');
63+
var configCollection = JSON.parse(routeconfig).value;
64+
var category = {};
65+
for (var configs of configCollection) {
66+
localimports += 'import { ' + configs.component + ' } from \'./' + configs.path.split('/')[1] + '\';\n';
67+
routes += ' <Route path=\'/:theme/' + configs.path + '\' component={ ' + configs.component + ' }/>\n';
68+
category[configs.path.split('/')[1]] = { 'name': configs.name, 'category': configs.category };
69+
var curSearchObject = {name:configs.name,uid:uid,path:configs.path};
70+
curSearchObject.component = configs.path.split('/')[0].replace(/-/g,'');
71+
instance.addDoc(curSearchObject);
72+
uid++;
73+
}
74+
category['defaultSample'] = configCollection[0].path;
75+
var routeContent = fs.readFileSync('./src/common/templates/route-template', 'utf8');
76+
routeContent = routeContent.replace(/{{routerimports}}/, localimports);
77+
routeContent = routeContent.replace(/{{component}}/g,componentName);
78+
routeContent = routeContent.replace(/{{routes}}/, routes);
79+
routeContent = routeContent.replace(/{{category}}/,JSON.stringify(category));
80+
imports += 'import { '+componentName+'Routes } from \'../'+ path.split('/')[2] + '/' + componentName+'-routes\';\n';
81+
categories += '"' + compName + '": ' + JSON.stringify(category) + ',\n';
82+
compRoutes += ' {' +componentName+'Routes}\n';
83+
fs.writeFileSync(path+'/'+componentName+'-routes.tsx', routeContent);
84+
}
85+
categories = categories.slice(0, -2) + '\n}';
86+
var allroutes = fs.readFileSync('./src/common/templates/route-all-template', 'utf8');
87+
allroutes = allroutes.replace(/{{imports}}/,imports);
88+
allroutes = allroutes.replace(/{{routerCollection}}/,compRoutes);
89+
allroutes = allroutes.replace(/{{category}}/, categories);
90+
fs.writeFileSync('./src/common/all-routes.tsx',allroutes);
91+
fs.writeFileSync('./src/common/search-index.json', JSON.stringify(instance.toJSON()));
92+
done();
93+
});
94+
gulp.task('build', function (done) {
95+
runSequence('generate-router','styles','scripts','bundle', 'plnkr-json', done);
96+
});
97+
98+
gulp.task('bundle', function () {
99+
return gulp.src("./src/common/index.js")
100+
.pipe(gulpWebpack(webpackConfig,webpack))
101+
.pipe(gulp.dest('dist/'));
102+
});
103+
104+
gulp.task('plnkr-json', function() {
105+
var files = glob.sync('./src/**/*.tsx', { silent: true, ignore: [
106+
'./src/common/**/*.tsx', './src/**/*-routes.tsx', './src/**/config.tsx'] });
107+
var sys = fs.readFileSync('./src/common/plnk-template/systemjs.config.js','utf8');
108+
var ind = fs.readFileSync('./src/common/plnk-template/index.html', 'utf8');
109+
var sBase = fs.readFileSync('./src/common/plnk-template/sample-base.tsx', 'utf8');
110+
var propPane = fs.readFileSync('./src/common/property-pane.tsx', 'utf8');
111+
var ajaxRegex = /Ajax\(\'\.\/src\//;
112+
var sbRegex = /(import[^;]+sample-base[^;]+;)/;
113+
var gJsonRegex = /import[^;]+\.json[^;]+;/g;
114+
var jsonRegex = /import[^;]+\.json[^;]+;/;
115+
var imgRegex = /(<img[^\/]+\/)|(imageUrl)|(background-image: url\((\'|\"|)(\.\/|)src)|((\'|\")(\.\/|)src\/[^\'\"]+.png(\'|\"))/;
116+
var srcRegex = /(\.\/|)src\//;
117+
var aSrcRegex = /('|")\.\/src[^'"]+('|")/;
118+
var cPathRegex = /..\/common\//g;
119+
var pathRegex = /\'[^\']+\'/;
120+
var quotesRegex = /(\'|\")/g;
121+
var impRegex = /import[^;]+\.\/[^;]+;/g;
122+
var slashRegex = /\.\//;
123+
var impCssRegex = /import[^'"]+('|")[^'"]+css('|")(;|)/;
124+
var impPropRegex = /import[^;]+\/property-pane[^;]+;/
125+
var classRegex = /class [^ ]+/;
126+
var bgRegex = /background-image: url\(\'\.\/src/g;
127+
var render = '\nReactDOM.render(<{{:Comp}} />, document.getElementById(\'sample\'));';
128+
var dSrc = 'demos/src/';
129+
var bucketName = process.env.AWS_STAGING_BUCKET || 'npmci.syncfusion.com';
130+
var link = 'http://' + bucketName + '/';
131+
var sbLink = link;
132+
if (process.env.BRANCH_NAME === "master") {
133+
link += 'packages/production/';
134+
sbLink += 'production/react/';
135+
} else {
136+
link += 'packages/development/';
137+
sbLink += 'development/react/';
138+
}
139+
if(process.env.BRANCH_NAME && process.env.BRANCH_NAME.indexOf('hotfix-') !== -1) {
140+
link = 'http://cdn.syncfusion.com/ej2/';
141+
sbLink = 'http://ej2.syncfusion.com/react/';
142+
}
143+
link = 'http://cdn.syncfusion.com/ej2/'; //Dependency Packages Link
144+
sbLink = 'http://ej2.syncfusion.com/react/'; //Sample Browser support Link
145+
sys = sys.replace(/{{:CDN_LINK}}/g, link);
146+
ind = ind.replace(/{{:CDN_LINK}}/g, link);
147+
var comp;
148+
for(var i = 0; i < files.length; i++) {
149+
var plnkr = { 'index.css': '' };
150+
var name = files[i].slice(files[i].lastIndexOf('/') + 1, files[i].indexOf('.tsx'));
151+
var path = files[i].slice(0, files[i].lastIndexOf('/') + 1);
152+
var tsxFile = fs.readFileSync(files[i], 'utf8');
153+
var className = tsxFile.match(classRegex)[0].slice(6);
154+
//CSS imports processing
155+
if(impCssRegex.test(tsxFile)) {
156+
var styleName = tsxFile.match(impCssRegex)[0].match(/(\'|\")[^\'\"]+(\'|\")/)[0].replace(quotesRegex,'').slice(2);
157+
var cfile = fs.readFileSync(path + styleName, 'utf8');
158+
if(imgRegex.test(cfile)) {
159+
var clines = cfile.split('\n');
160+
for(var x = 0; x < clines.length; x++) {
161+
if(imgRegex.test(clines[x])) {
162+
clines[x] = clines[x].replace(srcRegex, sbLink + dSrc);
163+
}
164+
}
165+
cfile = clines.join('\n');
166+
}
167+
plnkr['index.css'] = cfile;
168+
}
169+
//Sample-Base Processing
170+
tsxFile = tsxFile.replace(sbRegex, 'import { SampleBase } from \'./sample-base\';').replace(impCssRegex, '');
171+
//Property-pane Processing
172+
if(impPropRegex.test(tsxFile)) {
173+
tsxFile = tsxFile.replace(impPropRegex, 'import { PropertyPane } from \'./property-pane\';');
174+
plnkr['app/property-pane.tsx'] = propPane;
175+
}
176+
tsxFile = tsxFile + '\nReactDOM.render(<' + className + ' />, document.getElementById(\'sample\'));';
177+
tsxFile = getStringWithOutDescription(tsxFile, /id(| )=(| )('|")description/);
178+
tsxFile = getStringWithOutDescription(tsxFile, /('|")action-description/);
179+
//Background Image Processing
180+
if(bgRegex.test(tsxFile)) {
181+
var tLines = tsxFile.split('\n');
182+
for (var j = 0; j < tLines.length; j++) {
183+
if(bgRegex.test(tLines[j])) {
184+
tLines[j] = tLines[j].slice(0, tLines[j].indexOf('./src')) +
185+
sbLink + 'demos/' + tLines[j].slice(tLines[j].indexOf('src/'));
186+
}
187+
}
188+
tsxFile = tLines.join('\n');
189+
}
190+
//Imports Processing other than css, sample base, property-pane, json
191+
var imports = tsxFile.match(impRegex);
192+
if(imports.length) {
193+
for(var y = 0; y < imports.length; y++) {
194+
if(!sbRegex.test(imports[y]) && !impPropRegex.test(imports[y]) && !jsonRegex.test(imports[y])) {
195+
var imFile = imports[y].match(pathRegex)[0].replace(quotesRegex,'').slice(2);
196+
plnkr[ imFile ] = fs.readFileSync(path + imFile + '.ts', 'utf8');
197+
tsxFile = tsxFile.replace(imports[y], imports[y].replace(slashRegex, '../'));
198+
}
199+
}
200+
}
201+
//Img processing - sbLink
202+
if(imgRegex.test(tsxFile)) {
203+
var tlines = tsxFile.split('\n');
204+
for(var x = 0; x < tlines.length; x++) {
205+
if(imgRegex.test(tlines[x])) {
206+
tlines[x] = tlines[x].replace(srcRegex, sbLink + dSrc);
207+
}
208+
}
209+
tsxFile = tlines.join('\n');
210+
}
211+
//Ajax online link processing - sbLink
212+
if(ajaxRegex.test(tsxFile)) {
213+
var tslines = tsxFile.split('\n');
214+
for(var z = 0; z < tslines.length; z++) {
215+
if(ajaxRegex.test(tslines[z])) {
216+
var aFile = tslines[z].match(aSrcRegex)[0].replace(/\'/g, '').replace(/\"/g, '');
217+
plnkr[aFile.slice(2)] = fs.readFileSync(aFile, 'utf8');
218+
}
219+
}
220+
tsxFile = tslines.join('\n');
221+
}
222+
//JSON imports processing
223+
if(jsonRegex.test(tsxFile)) {
224+
var jsonImports = tsxFile.match(gJsonRegex);
225+
for(var a = 0; a < jsonImports.length; a++) {
226+
var jFile = jsonImports[a].match(/\'[^\']+\'/)[0].replace(quotesRegex,'');
227+
plnkr['app' + jFile.slice(2)] = fs.readFileSync(path + jFile, 'utf8');
228+
}
229+
}
230+
//JSON imports path processing
231+
if(cPathRegex.test(tsxFile)) {
232+
tsxFile = tsxFile.replace(cPathRegex, './common/');
233+
}
234+
plnkr['systemjs.config.js'] = sys;
235+
plnkr['index.html'] = ind;
236+
plnkr['app/index.tsx'] = tsxFile;
237+
plnkr['app/sample-base.tsx'] = sBase;
238+
fs.writeFileSync(path + name + '-plnkr.json', JSON.stringify(plnkr), 'utf8');
239+
var samplePath = 'samples' + path.slice(5) + name;
240+
shelljs.mkdir('-p', samplePath);
241+
samplePath += '/';
242+
var plFiles = Object.keys(plnkr);
243+
for (var p = 0; p < plFiles.length; p++) {
244+
if (plFiles[p].split('/').length === 1) {
245+
fs.writeFileSync(samplePath + plFiles[p], plnkr[plFiles[p]]);
246+
} else {
247+
var dirPath = plFiles[p].split('/');
248+
shelljs.mkdir('-p', (samplePath + dirPath.splice(0, dirPath.length - 1).join('/')));
249+
fs.writeFileSync(samplePath + plFiles[p], plnkr[plFiles[p]]);
250+
}
251+
}
252+
253+
}
254+
});
255+
function getStringWithOutDescription(code, descRegex) {
256+
var lines = code.split('\n');
257+
var desStartLine = null;
258+
var desEndLine = null;
259+
var desInsideDivCnt = 0;
260+
for (var i = 0; i < lines.length; i++) {
261+
var curLine = lines[i];
262+
if (desStartLine !== null) {
263+
if (/<div/g.test(curLine)) {
264+
desInsideDivCnt = desInsideDivCnt + 1;
265+
}
266+
if (desInsideDivCnt && /<\/div>/g.test(curLine)) {
267+
desInsideDivCnt = desInsideDivCnt - 1;
268+
} else if (!desEndLine && /<\/div>/g.test(curLine)) {
269+
desEndLine = i + 1;
270+
}
271+
}
272+
if (descRegex.test(curLine)) {
273+
desStartLine = i;
274+
275+
}
276+
}
277+
if (desEndLine && (desStartLine !== null)) {
278+
lines.splice(desStartLine, desEndLine - desStartLine);
279+
}
280+
return lines.join('\n');
281+
}
282+
gulp.task('serve', ['build'], function (done) {
283+
var browserSync = require('browser-sync');
284+
var bs = browserSync.create('Essential JS 2 react');
285+
var options = {
286+
server: {
287+
baseDir: './'
288+
},
289+
ui: false
290+
};
291+
bs.init(options, done);
36292
});

0 commit comments

Comments
 (0)