forked from ampproject/amp.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
76 lines (66 loc) · 1.86 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
var autoprefixer = require('gulp-autoprefixer');
var exec = require('child_process').exec;
var plumber = require('gulp-plumber');
var gulp = require('gulp');
var sass = require('gulp-sass');
var livereload = require('gulp-livereload');
var swPrecache = require('sw-precache');
var gutil = require('gulp-util');
var Path = {
CSS_SOURCES: './assets/sass/**/*.scss',
CSS_OUT_DIR: './assets/css/'
};
gulp.task('import-docs', function () {
return exec('cd ./scripts && ./import_docs.js', function (err, stdout, stderr) {
if (err instanceof Error) {
throw err;
}
console.log(stdout);
});
});
gulp.task('update-blog-links', function () {
return exec('cd ./scripts && ./update_blog_links.js', function (err, stdout, stderr) {
if (err instanceof Error) {
throw err;
}
console.log(stdout);
});
});
gulp.task('write-service-worker', function (callback) {
swPrecache.write('build/service-worker.js', {
staticFileGlobs: [
'build/**/*.{png,jpg,gif,svg,json}',
'build/*.html',
'build/docs/**/*.html',
'build/who/*.html',
'build/roadmap/*.html',
'build/metrics/*.html',
'build/how-it-works/*.html',
'build/case-studies/*.html'
],
runtimeCaching: [{
urlPattern: /^https:\/\/cdn\.ampproject\.org/,
handler: 'fastest'
}],
stripPrefixMulti: {
'build/': ''
},
logger: gutil.log
}, callback);
});
gulp.task('sass', function() {
return gulp.src(Path.CSS_SOURCES)
.pipe(plumber())
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest(Path.CSS_OUT_DIR))
.pipe(livereload());
});
gulp.task('watch', function() {
livereload.listen();
gulp.watch([Path.CSS_SOURCES], ['sass']);
});
gulp.task('build', ['update-blog-links', 'import-docs', 'sass']);
gulp.task('default', ['sass', 'watch']);