-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
141 lines (122 loc) · 4.32 KB
/
Copy pathgulpfile.js
File metadata and controls
141 lines (122 loc) · 4.32 KB
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
let browser_sync = require('browser-sync').create();
let del = require('del');
let gh_pages = require('gh-pages');
let gulp = require('gulp');
let gulp_amphtml_validator = require('gulp-amphtml-validator');
let htmlmin = require('gulp-htmlmin');
let imagemin = require('gulp-imagemin');
let json_minify = require('gulp-json-minify');
let less = require('gulp-less');
let util = require('gulp-util');
let path = require('path');
let sw_precache = require ('sw-precache');
let minify_embedded_json = require('./tasks/gulp_minify_embedded_json');
let HoganBuilder = require('./tasks/HoganBuilder');
gulp.task('clean', () => {
return del([
'html/**/*',
'public/**/*',
'styles/**/*'
]);
});
gulp.task('less', () => {
return gulp.src('less/*.less')
.pipe(less({ paths: [path.join(__dirname, 'less')] }))
.pipe(gulp.dest('styles'));
});
function hogan(injected_context = {}) {
return new HoganBuilder(injected_context)
.addTemplates('styles', ['.css'])
.addTemplates('schema', ['.json'])
.addTemplates('templates/partials', ['.mustache'])
.renderPages('templates', 'html');
}
gulp.task('hogan_dev', gulp.series('less', function _hogan_dev(done) {
hogan({ release: false });
done();
}));
gulp.task('hogan', gulp.series('less', function _hogan(done) {
hogan({ release: true });
done();
}));
gulp.task('minify_html_dev', gulp.series('hogan_dev', function _minify_html_dev() {
return gulp.src('html/*.html')
.pipe(gulp.dest('public'));
}));
gulp.task('minify_html', gulp.series('hogan', function _minify_html() {
return gulp.src('html/*.html')
.pipe(htmlmin({
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true
}))
.pipe(minify_embedded_json())
.pipe(gulp.dest('public'));
}));
gulp.task('minify_images', () => {
return gulp.src('images/*.{jpg,png,svg}')
.pipe(imagemin())
.pipe(gulp.dest('public'));
});
gulp.task('minify_json', () => {
return gulp.src('static/*.json')
.pipe(json_minify())
.pipe(gulp.dest('public'));
});
gulp.task('minify_dev', gulp.parallel('minify_html_dev', 'minify_images', 'minify_json'));
gulp.task('minify', gulp.parallel('minify_html', 'minify_images', 'minify_json'));
function precache(handleFetch = true) {
return sw_precache.write(path.join(__dirname, 'public', 'service_worker.js'), {
cacheId: 'spaces',
handleFetch: handleFetch,
staticFileGlobs: ['public/**/*'],
stripPrefix: 'public/'
}, (error) => {
if (error) throw new util.PluginError(error);
});
}
gulp.task('precache_dev', () => {
return precache(false);
});
gulp.task('precache', () => {
return precache(true);
});
gulp.task('copy_no_precache', () => {
return gulp.src('static/web.config')
.pipe(gulp.dest('public'));
});
function browsersync_reload(done) {
browser_sync.reload();
done();
}
gulp.task('watch', gulp.series('minify_dev', 'precache_dev', 'copy_no_precache', function _watch(done) {
gulp.watch('less/*.less', gulp.series('minify_html_dev', 'precache_dev', browsersync_reload));
gulp.watch(['templates/**/*.mustache', 'templates/contexts.json'], gulp.series('minify_html_dev', 'precache_dev', browsersync_reload));
gulp.watch('images/*.{jpg,png,svg}', gulp.series('minify_images', 'precache_dev', browsersync_reload));
gulp.watch('static/*.json', gulp.series('minify_json', 'precache_dev', browsersync_reload));
done();
}));
gulp.task('browsersync', gulp.series('watch', function _browsersync(done) {
browser_sync.init({ server: { baseDir: 'public' }}, done);
}));
gulp.task('validate', () => {
return gulp.src('public/*.html')
.pipe(gulp_amphtml_validator.validate())
.pipe(gulp_amphtml_validator.format())
.pipe(gulp_amphtml_validator.failAfterError());
});
gulp.task('dev', gulp.series('clean', 'browsersync'));
gulp.task('rel', gulp.series('clean', 'minify', 'precache', 'copy_no_precache', 'validate'));
gulp.task('publish_github', gulp.series('rel', function _publish_github() {
return gh_pages.publish('public', (error) => {
if (error) throw new util.PluginError(error);
});
}));
gulp.task('publish_azure', gulp.series('rel', function _publish_azure() {
return gh_pages.publish('public', { branch: 'azure' }, (error) => {
if (error) throw new util.PluginError(error);
});
}));
gulp.task('publish', gulp.series('publish_github'));
gulp.task('default', gulp.series('rel'));