forked from framework7io/framework7-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
209 lines (193 loc) · 5.75 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
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
(function(){
'use strict';
var gulp = require('gulp');
var gulpData = require('gulp-data');
var connect = require('gulp-connect');
var open = require('gulp-open');
var less = require('gulp-less');
var gulpPug = require('gulp-pug');
var pug = require('pug');
var path = require('path');
var fs = require('fs');
var del = require('del');
var yaml = require('js-yaml');
var iconsManifest = require('./icons/manifest-icons.json');
var useCDN = true;
var cdnPath = '//cdn.framework7.io';
var processVuePugFiles = require('./src/react-doc-generation/vue-pug-file-processing').processVuePugFiles;
var processReactHtmlFiles = require('./src/react-doc-generation/react-html-file-processing').processReactHtmlFiles;
var pkg = require('./package.json');
// Get src file url
function getSrcFileUrl(file) {
const srcFileUrl = `${pkg.repository.url}/edit/master/src/pug/${file.path.split('/src/pug/')[1]}`;
return {
srcFileUrl: srcFileUrl,
};
}
// Pug Filter
pug.filters['code'] = function (text) {
return text
.replace( /</g, '<' )
.replace( />/g, '>' )
}
// Pug YAML Data
function getYamlData(ymlPath) {
var doc = yaml.safeLoad(fs.readFileSync(`./src/pug/${ymlPath}`, 'utf8'));
return doc;
}
/* ==================================================================
Check CDN
================================================================== */
function checkIsLocal(local) {
if (local) local = local.toString().replace('-', '');
if (local === 'local') {
useCDN = false;
}
}
/* ==================================================================
Build
================================================================== */
// Styles
gulp.task('less', function (cb) {
var cbs = 0;
gulp.src(['./src/less/main.less'])
.pipe(less({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(gulp.dest('./css/'))
.pipe(connect.reload())
.on('end', function () {
if (cb) cb();
});
});
function buildReactPages(cb) {
checkIsLocal(process.argv.slice(3));
processVuePugFiles();
var time = Date.now();
console.log(`Starting react pug: all`);
gulp.src(['./react-pug-temp/*.pug'])
.pipe(gulpData(getSrcFileUrl))
.pipe(gulpPug({
pug,
pretty: true,
locals: {
cdn: useCDN ? cdnPath : '',
icons: iconsManifest.icons,
getYamlData,
}
}))
.on('error', (err) => {
console.log(err);
})
.pipe(gulp.dest('./react/'))
.on('end', () => {
console.log(`Finished react pug in ${Date.now() - time}ms`);
processReactHtmlFiles(cb);
});
}
// All Pug Pages
function buildPages(cb) {
checkIsLocal(process.argv.slice(3));
var cbs = 0;
var time = Date.now();
console.log(`Starting pug: all`);
gulp.src(['**/*.pug', '!**/_*.pug', '!react/*.pug', '!_*.pug'], { cwd: 'src/pug' })
.pipe(gulpData(getSrcFileUrl))
.pipe(gulpPug({
pug,
pretty: true,
locals: {
cdn: useCDN ? cdnPath : '',
icons: iconsManifest.icons,
getYamlData,
}
}))
.on('error', (err) => {
console.log(err);
})
.pipe(gulp.dest('./'))
.on('end', () => {
buildReactPages(() => {
console.log(`Finished pug all in ${Date.now() - time}ms`);
if(cb) cb();
});
});
}
gulp.task('pug', function (cb) {
buildPages(cb);
});
gulp.task('process-react-html', function (cb) {
processReactHtmlFiles(cb);
});
gulp.task('process-react-pug', function (cb) {
buildReactPages(cb);
});
// Build All
gulp.task('build', ['pug', 'less'], function (cb) {
cb();
});
gulp.task('build-local', function (cb) {
local = true;
});
/* =================================
Watch
================================= */
gulp.task('watch', function () {
checkIsLocal(process.argv.slice(3));
gulp.watch('./src/less/**/*.*', [ 'less' ]);
gulp.watch('./src/pug/**/*.pug', (data) => {
checkIsLocal(process.argv.slice(3));
if (data.type !== 'changed') return;
const filePath = data.path.split('/src/pug/')[1];
if (filePath.indexOf('react') === 0) return;
if (filePath.indexOf('_') === 0) {
buildPages();
return;
}
const src = [];
if (filePath.split('/')[1] && filePath.split('/')[1].indexOf('_') === 0) {
src.push(`${filePath.split('/')[0]}/*.pug`);
src.push(`!${filePath.split('/')[0]}/_*.pug`);
} else {
src.push(filePath);
}
var time = Date.now();
console.log(`Starting pug "${src}"`);
gulp.src(src, { cwd: 'src/pug' })
.pipe(gulpData(getSrcFileUrl))
.pipe(gulpPug({
pug,
pretty: true,
locals: {
cdn: useCDN ? cdnPath : '',
icons: iconsManifest.icons,
getYamlData,
}
}))
.on('error', (err) => {
console.log(err);
})
.pipe(gulp.dest(filePath.split('/')[0] === filePath ? './' : filePath.split('/')[0]))
.on('end', () => {
console.log(`Finished pug "${src}" in ${Date.now() - time}ms`);
connect.reload();
});
});
});
/* =================================
Server
================================= */
gulp.task('connect', function () {
return connect.server({
root: [ './' ],
livereload: true,
port:'3000'
});
});
gulp.task('open', function () {
return gulp.src('./index.html').pipe(open({ uri: 'http://localhost:3000/index.html'}));
});
gulp.task('server', [ 'watch', 'connect', 'open' ]);
gulp.task('default', [ 'server' ]);
gulp.task('test', [ 'build' ]);
})();