forked from DevExpress/devextreme-reactive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
142 lines (125 loc) · 3.62 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
var gulp = require('gulp'),
runSequence = require("run-sequence"),
clean = require('gulp-clean'),
rename = require('gulp-rename'),
intercept = require('gulp-intercept');
var distPath = 'site/';
var versionTag = process.env.VERSION_TAG;
var splitNameToPath = function(path) {
// dx-react-grid-bs3\... ==> react\grid\bs3\...
return path
.replace(/dx-/, '')
.replace(/-/g, '/');
};
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(/http\:\/\/devexpress\.github\.io/g, '')
.replace(/(?:(?:\.\.)\/)+(dx-.+?\.md)/g, function(match, path) {
return '{{site.baseurl}}/'+
splitNameToPath(path)
.replace(/readme\.md/i, '');
})
.replace(/readme\.md/i, '../');
};
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 injectLiveDemos = function(content) {
return content
.replace(
/\.embedded\-demo\(([^\(\)]*)\)/g,
function(match, p1) {
var data = { path: p1 };
try {
data = JSON.parse(p1);
} catch (e) {}
const options = {
...data,
path: `/demo/${data.path}`,
scriptPath: `/devextreme-reactive/react/grid/demos/dist/index.js?v=${new Date().getTime()}`,
};
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(
['react'].map(function(dir) { return distPath + dir; }),
{ read: false }
)
.pipe(clean());
});
gulp.task('site:docs', function() {
return gulp.src([
'packages/**/*.md',
'!packages/**/LICENSE.md',
'!packages/dx-react-demos/**/*',
'!packages/dx-testing/**/*',
'!/**/node_modules/**/*'
])
.pipe(rename(function(path) {
path.dirname = splitNameToPath(path.dirname);
path.basename = path.basename
.replace(/readme/i, 'index');
}))
.pipe(intercept(function(file){
if(file.contents) {
var content = applyInterceptors(
file.contents.toString(),
patchMDLinks,
patchMDTables,
injectLiveDemos,
addFrontMatter
);
file.contents = new Buffer(content);
}
return file;
}))
.pipe(gulp.dest(distPath));
});
gulp.task('site:demos', function() {
return gulp.src(['packages/dx-react-demos/dist/*'])
.pipe(gulp.dest(distPath + 'react/grid/demos/dist/'));
});
gulp.task('site', function(done) {
runSequence(
'site:clean',
'site:docs',
'site:demos',
done
);
});