-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
120 lines (98 loc) · 2.88 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
const {series, watch, src, dest, parallel} = require('gulp');
const pump = require('pump');
// gulp plugins and utils
const livereload = require('gulp-livereload');
const stylus = require('gulp-stylus');
const pug = require('gulp-pug');
const autoprefixer = require('gulp-autoprefixer');
const zip = require('gulp-zip');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const gap = require('gulp-append-prepend');
const ampify = require('gulp-ampify');
const beeper = require('beeper');
function serve(done) {
livereload.listen();
done();
}
const handleError = (done) => {
return function (err) {
if (err) beeper();
return done(err);
};
};
var hbs_src = ['src/hbs/*.hbs', 'src/hbs/partials/*.hbs'];
function hbs(done) {
pump([src(hbs_src), livereload()], handleError(done));
}
function css(done) {
pump([
src(['style.styl', 'amp.styl', 'cart.styl', 'logo.styl', 'header.styl',
'footer.styl'],
{cwd: 'src/stylus'}),
stylus({compress: true}),
autoprefixer(),
gap.prependText('{{{{raw}}}}'),
gap.appendText('{{{{/raw}}}}'),
rename({extname: '.css.hbs'}),
dest('build/root/partials/assets/'),
livereload()
], handleError(done));
}
function fonts(done) {
pump([
src(['src/css/*.css']),
rename({extname: '.css.hbs'}),
gap.prependText('{{{{raw}}}}'),
gap.appendText('{{{{/raw}}}}'),
dest('build/root/partials/assets/'),
], handleError(done));
}
function js(done) {
pump([
src('src/js/*.js'),
uglify(),
gap.prependText('{{{{raw}}}}'),
gap.appendText('{{{{/raw}}}}'),
rename({extname: '.js.hbs'}),
dest('build/root/partials/assets/'),
livereload()
], handleError(done));
}
function _pug(done) {
pump([
src(['cart-tmpl.pug', 'header.pug', 'footer.pug'],
{cwd: 'src/pug/partials'}),
pug(),
gap.prependText('{{{{raw}}}}'),
gap.appendText('{{{{/raw}}}}'),
rename({extname: '.html.hbs'}),
dest('build/root/partials/assets/')
], handleError(done));
}
function amp_pug(done) {
pump([
src(['header.pug', 'footer.pug'], {cwd: 'src/pug/partials'}),
pug(),
ampify('build'),
gap.prependText('{{{{raw}}}}'),
gap.appendText('{{{{/raw}}}}'),
rename({extname: '.amp.hbs'}),
dest('build/root/partials/assets/')
], handleError(done));
}
function zipper(done) {
pump([
src(['src/hbs/**', 'build/root/**', 'package.json', 'gulpfile.js']),
zip(require('./package.json').name + '.zip'),
dest('build/')
], handleError(done));
}
const cssWatcher = () => watch('src/stylus/**', css);
const hbsWatcher = () => watch(hbs_src, hbs);
const watcher = parallel(cssWatcher, hbsWatcher);
const build = series(css, fonts, js, _pug, amp_pug);
const dev = series(build, serve, watcher);
exports.build = build;
exports.zip = series(build, zipper);
exports.default = dev;