-
Notifications
You must be signed in to change notification settings - Fork 385
/
gulpfile.js
178 lines (156 loc) · 5.24 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
import gulp from 'gulp';
import clean from 'gulp-clean';
import rename from 'gulp-rename';
import intercept from 'gulp-intercept';
var distPath = 'site/';
var versionTag = process.env.VERSION_TAG;
var splitNameToPath = function(pathPrefix, path) {
// {prefix}dx-react-grid-bs3/... ==> {prefix}{../../}?react/grid/bs3/...
const dxPartEnd = path.indexOf('/');
const dxPart = path.slice(0, dxPartEnd).replace(/dx-/, '');
return pathPrefix
+ (pathPrefix ? '../'.repeat(dxPart.split('-').length - 1) : '')
+ dxPart.replace(/-/g, '/')
+ path.slice(dxPartEnd);
};
var extractMDTitle = function(content) {
var matches = /^\s*#\s*([^#]+?)\s*$/m.exec(content);
return matches ? matches[1] : undefined;
};
var formatFrontMatter = function(title) {
return `---${title ? '\ntitle: ' + title: ''}\n---\n\n`;
};
var addFrontMatter = function(content) {
var title = extractMDTitle(content),
frontMatter = formatFrontMatter(title);
return frontMatter + content;
};
var patchMDLinks = function(content) {
return content
.replace(/((?:(?:\.\.)\/)+)(dx-.+?\.md)/g, function(match, pathPrefix, path) {
return splitNameToPath(pathPrefix, path);
});
};
var patchMDTables = function(content) {
var lines = content.split('\n');
var withinTable = false;
var index = 0;
while(index < lines.length) {
if (!withinTable && lines[index].indexOf('-|-') > -1) withinTable = true;
if (withinTable && lines[index].indexOf('|') === -1) {
withinTable = false;
lines.splice(index, 0, '{: .table.table-bordered.table-striped }');
}
index = index + 1;
}
return lines.join('\n');
};
var applyInterceptors = function(content, ...interceptors) {
return interceptors.reduce((result, interceptor) => {
return interceptor(result);
}, content);
};
var injectNpmTag = function(content) {
const tag = versionTag && versionTag !== 'latest' ? `@${versionTag}` : '';
return content.replace(/\.npm\-tag\(\)/g, tag);
};
var injectLiveDemos = function(content) {
return content
.replace(
/\.embedded\-demo\(([^\(\)]*)\)/g,
function(match, p1) {
const data = JSON.parse(p1);
const options = {
...data,
path: `/demo/${data.path}`,
scriptPath: `{{site.baseurl}}/{{page.demos_script_link}}/dist/index.js?v={{ site.time | date: '%s' }}`,
firstPart: `{{site.baseurl}}//react/`,
lastPart: `/demos/dist/index.js?v={{ site.time | date: '%s' }}`
};
return `<div
class="embedded-demo"
data-options='${JSON.stringify(options)}'
>
<div class="loading-shading">
<span class="glyphicon glyphicon-refresh loading-icon"></span>
</div>
</div>`
});
};
gulp.task('site:clean', function() {
return gulp.src([
'site/react/**/*.md',
'site/vue/**/*.md',
], { read: false }).pipe(clean());
});
gulp.task('site:docs:img', function() {
return gulp.src(['packages/dx-react-scheduler/docs/*/*.png'], { base: 'packages' })
.pipe(rename(function(path) {
path.dirname = splitNameToPath('', path.dirname);
}))
.pipe(gulp.dest(distPath));
});
gulp.task('site:docs', function() {
return gulp.src([
'packages/dx-react-common/docs/*/*.md',
'packages/dx-react-core/docs/*/*.md',
'packages/dx-react-grid/demos/*/*.md',
'packages/dx-react-grid/docs/*/*.md',
'packages/dx-react-chart/demos/*/*.md',
'packages/dx-react-chart/docs/*/*.md',
'packages/dx-react-scheduler/demos/*/*.md',
'packages/dx-react-scheduler/docs/*/*.md',
'packages/dx-vue-grid/demos/*/*.md',
'packages/dx-vue-grid/docs/*/*.md',
'!packages/**/LICENSE.md',
'!packages/**/README.md',
], { base: 'packages' })
.pipe(rename(function(path) {
path.dirname = splitNameToPath('', path.dirname);
}))
.pipe(intercept(function(file){
if(file.contents) {
var content = applyInterceptors(
file.contents.toString(),
patchMDLinks,
patchMDTables,
injectNpmTag,
injectLiveDemos,
addFrontMatter
);
file.contents = new Buffer(content);
}
return file;
}))
.pipe(gulp.dest(distPath));
});
gulp.task('site:demos:react:grid', function() {
return gulp.src(['packages/dx-react-grid-demos/dist/*'])
.pipe(gulp.dest(distPath + 'react/grid/demos/dist/'));
});
gulp.task('site:demos:react:chart', function() {
return gulp.src(['packages/dx-react-chart-demos/dist/*'])
.pipe(gulp.dest(distPath + 'react/chart/demos/dist/'));
});
gulp.task('site:demos:react:scheduler', function() {
return gulp.src(['packages/dx-react-scheduler-demos/dist/*'])
.pipe(gulp.dest(distPath + 'react/scheduler/demos/dist/'));
});
gulp.task('site:demos:react:common', function() {
return gulp.src(['packages/dx-react-common/dist/*'])
.pipe(gulp.dest(distPath + 'react/common/dist/'));
});
gulp.task('site:demos:vue:grid', function() {
return gulp.src(['packages/dx-vue-grid-demos/dist/*'])
.pipe(gulp.dest(distPath + 'vue/grid/demos/dist/'));
});
gulp.task('site', gulp.series(
'site:clean',
'site:docs',
'site:docs:img',
'site:demos:react:grid',
'site:demos:vue:grid',
'site:demos:react:chart',
'site:demos:react:scheduler',
'site:demos:react:common',
));