forked from LaAzteca/docs-5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
172 lines (149 loc) · 4.34 KB
/
gulpfile.js
File metadata and controls
172 lines (149 loc) · 4.34 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const autoprefixer = require('gulp-autoprefixer');
const exec = require('child_process').exec;
const plumber = require('gulp-plumber');
const gulp = require('gulp');
const sass = require('gulp-sass');
const svgSprite = require('gulp-svg-sprite');
const swBuild = require('workbox-build');
const fs = require('fs');
const Path = {
CSS_SOURCES: './assets/sass/**/*.scss',
CSS_OUT_DIR: './assets/css/'
};
// build example snippets that are used as sample embeds in docs
gulp.task('build-examples', function () {
const expath = require('path');
const abe = require('amp-by-example');
const config = {
src: expath.join(__dirname, 'examples/src'), // root folder w examples
destRoot: expath.join(__dirname, 'build'), // target dir for generated embeds
destDir: '/examples', // optional sub dir
host: 'https://ampproject-b5f4c.firebaseapp.com' // where embeds are to be served
};
abe.generatePreview(config);
return Promise.all([
gulp.src('./examples/src/images/*')
.pipe(gulp.dest('build/examples/images/')),
gulp.src('./examples/src/data/*')
.pipe(gulp.dest('build/examples/data/')),
gulp.src('./examples/src/videos/*')
.pipe(gulp.dest('build/examples/videos/')),
gulp.src('./examples/src/audio/*')
.pipe(gulp.dest('build/examples/audio/'))
]);
});
gulp.task('import-docs', function (cb) {
exec('cd ./scripts && ./import_docs.js', function (err) {
if (err instanceof Error) {
cb(err);
}
cb();
});
});
gulp.task('optimize-images', function () {
return gulp.src('./assets/img/symbols/*.svg')
.pipe(svgSprite({
mode: {
css: {
sprite: '../sprite.svg',
bust: false,
render: {
scss: {
template: './assets/img/symbols/template.scss',
dest: '../../sass/_sprite_generated.scss'
}
}
}
}
}))
.pipe(gulp.dest('./assets/img/'));
});
gulp.task('update-blog-links', function (cb) {
exec('cd ./scripts && ./update_blog_links.js', function (err) {
if (err instanceof Error) {
cb(err);
}
cb();
});
});
gulp.task('update-tweets', function (cb) {
exec('cd ./scripts && ./update_tweets.js', function (err) {
if (err instanceof Error) {
cb(err);
}
cb();
});
});
gulp.task('update-platforms-page', function (cb) {
return exec('cd ./scripts && ./update_platforms_page.js', function (err) {
if (err instanceof Error) {
cb(err);
}
cb();
});
});
gulp.task('generate-asset-manifest', function (cb) {
swBuild.getManifest({
globDirectory: './assets',
globPatterns: [
'img/*.{svg,png,jpg}',
'img/nav/*.{svg,png,jpg}',
'img/footer/*.{svg,png,jpg}'
]
}).then((entries) => {
// Add "static" to the path
entries['manifestEntries'].forEach(entry => {
entry.url = '/static/' + entry.url;
});
fs.readFile('./pwa/service-worker.js', 'utf8', (err, data) => {
if (err) throw err;
// Inline precache manifest directly into the Service Worker
data = data.replace(/\/\* START_PRECACHE_MANIFEST \*\/.*\/\* END_PRECACHE_MANIFEST \*\//, "/* START_PRECACHE_MANIFEST */" + JSON.stringify(entries) + "/* END_PRECACHE_MANIFEST */");
fs.writeFile('./pwa/service-worker.js', data, (err) => {
if (err) throw err;
cb();
});
});
});
});
gulp.task('sass', function() {
return gulp.src(Path.CSS_SOURCES)
.pipe(plumber())
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['> 10%']
}))
.pipe(gulp.dest(Path.CSS_OUT_DIR));
});
gulp.task('watch', function() {
gulp.watch(Path.CSS_SOURCES, gulp.series('sass'));
gulp.watch([
'./assets\/img\/*.{svg,png,jpg}',
'./assets\/img\/nav/*.{svg,png,jpg}',
'./assets\/img\/footer/*.{svg,png,jpg}'
], gulp.series('generate-asset-manifest'));
});
gulp.task('build',
gulp.parallel(
'update-blog-links',
/*'update-tweets',*/ //TODO: endpoint is broken, fix with proper Twitter API
gulp.series('import-docs', 'update-platforms-page'),
'optimize-images',
'sass',
'build-examples',
'generate-asset-manifest'
)
);
gulp.task('default',
gulp.series(
gulp.parallel(
gulp.series(
'import-docs', 'update-platforms-page'),
'sass',
'generate-asset-manifest'
),
'watch'
)
);