forked from romannurik/SlidesCodeHighlighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
134 lines (105 loc) · 3.18 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
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const browserSync = require('browser-sync');
const del = require('del');
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const workbox = require('workbox-build');
const ghpages = require('gh-pages');
const path = require('path');
let DEV_MODE = false;
function errorHandler(error) {
console.error(error.stack);
this.emit('end'); // http://stackoverflow.com/questions/23971388
}
gulp.task('service-worker', () => {
if (DEV_MODE) {
return gulp.src('sw-dev.js')
.pipe($.rename('sw.js'))
.pipe(gulp.dest('dist'));
}
return workbox.generateSW({
globDirectory: 'dist',
globPatterns: [
'**/*.{html,js,css}'
],
globIgnores: ['**/sw-dev.js'],
swDest: 'dist/sw.js',
clientsClaim: true,
skipWaiting: true
}).then(({warnings}) => {
// In case there are any warnings from workbox-build, log them.
for (const warning of warnings) {
console.warn(warning);
}
console.info('Service worker generation completed.');
}).catch((error) => {
console.warn('Service worker generation failed:', error);
});
});
gulp.task('copy', () => {
return gulp.src([
'index.html',
'favicon.ico',
'manifest.json',
// code
'material-colors.js',
'themes.js',
'index.js',
// libs
'prism.js',
'node_modules/jquery/dist/jquery.min.js',
'node_modules/ace-builds/src-min-noconflict/ace.js',
'node_modules/ace-builds/src-min-noconflict/mode-text.js',
'node_modules/ace-builds/src-min-noconflict/theme-chrome.js',
'node_modules/webfontloader/webfontloader.js',
// icons
'images/**/*.png'
])
.pipe(gulp.dest('dist'));
});
gulp.task('styles', () => {
return gulp.src('index.scss')
.pipe($.changed('styles', {extension: '.scss'}))
.pipe($.sass({
style: 'expanded',
precision: 10,
quiet: true
}).on('error', errorHandler))
.pipe(gulp.dest('dist'));
});
gulp.task('clean', cb => {
del.sync(['dist']);
$.cache.clearAll();
cb();
});
gulp.task('build', gulp.series('styles', 'copy', 'service-worker'));
gulp.task('__serve__', gulp.series('build', () => {
browserSync({
notify: false,
server: {
baseDir: ['dist']
}
});
let reload = cb => { browserSync.reload(); cb(); };
gulp.watch(['*.{html,js}'], gulp.series('copy', reload));
gulp.watch(['*.scss'], gulp.series('styles', reload));
}));
gulp.task('serve', gulp.series(cb => { DEV_MODE = true; cb(); }, '__serve__'));
gulp.task('deploy', cb => {
ghpages.publish(path.join(process.cwd(), 'dist'), cb);
});
gulp.task('default', gulp.series('clean', 'build'));