forked from framework7io/framework7-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
65 lines (55 loc) · 1.91 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
const gulp = require('gulp');
const connect = require('gulp-connect');
const open = require('gulp-open');
const path = require('path');
const buildStyles = require('./build/build-styles');
const buildPages = require('./build/build-pages');
const buildScript = require('./build/build-script');
/* ==================================================================
Build Styles
================================================================== */
gulp.task('less', buildStyles);
gulp.task('pug', buildPages);
gulp.task('js', buildScript);
gulp.task('build', gulp.series(['pug', 'less', 'js']));
/* =================================
Watch
================================= */
gulp.task('watch', () => {
gulp.watch('./src/js/**/*.*', gulp.series(['js']));
gulp.watch('./src/less/**/*.*', gulp.series(['less']));
gulp.watch('./src/pug/**/*.pug', { events: ['change'] }).on('change', (changedPath) => {
const filePath = changedPath.split('src/pug/')[1];
if (filePath.indexOf('_') === 0 || filePath.indexOf('_layout.pug') >= 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);
}
buildPages(null, {
src,
dest: filePath.split('/')[0] === filePath ? './' : path.parse(filePath).dir,
});
});
});
/* =================================
Server
================================= */
gulp.task('connect', () => {
return connect.server({
root: ['./'],
livereload: true,
port: '3001',
});
});
gulp.task('open', () => {
return gulp.src('./index.html').pipe(open({ uri: 'http://localhost:3001/index.html' }));
});
gulp.task('server', gulp.parallel(['watch', 'connect', 'open']));
gulp.task('default', gulp.series(['server']));
gulp.task('test', gulp.series(['build']));