-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
122 lines (104 loc) · 3.67 KB
/
gulpfile.js
File metadata and controls
122 lines (104 loc) · 3.67 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
const gulp = require("gulp");
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const replace = require("gulp-replace");
const minifycss = require('gulp-minify-css');
const livereload = require('gulp-livereload');
const raster = require('gulp-raster');
const workbox = require("workbox-build");
const autoprefix = require("gulp-autoprefixer");
const stagingDirectory = "dist";
const appName = "CiC";
gulp.task("js", () => {
return gulp.src("./app/**/*.js")
.pipe(gulp.dest(stagingDirectory))
.pipe(livereload(server));
});
gulp.task("images-144", () => {
return gulp.src("./app/images/**/*.svg")
.pipe(replace("%text%", appName))
.pipe(raster({scale: 3}))
.pipe(rename({extname: '.png', suffix: "-144"}))
.pipe(gulp.dest(stagingDirectory));
});
gulp.task("images-528", gulp.series("images-144", () => {
return gulp.src("./app/images/**/*.svg")
.pipe(replace("%text%", appName))
.pipe(raster({scale: 11}))
.pipe(rename({extname: '.png', suffix: "-528"}))
.pipe(gulp.dest(stagingDirectory));
}));
gulp.task("images", gulp.series("images-528", () => {
return gulp.src("./app/images/**/*.svg")
.pipe(replace("%text%", appName))
.pipe(raster({scale: 1}))
.pipe(rename({extname: '.png'}))
.pipe(gulp.dest(stagingDirectory));
}));
gulp.task("sass", () => {
return gulp.src("./app/**/*.scss")
.pipe(sass({errLogToConsole: true}))
.pipe(minifycss())
.pipe(autoprefix())
.pipe(gulp.dest(stagingDirectory))
.pipe(livereload(server));
});
gulp.task("index", () => {
return gulp.src("./app/index.html")
.pipe(gulp.dest(stagingDirectory))
.pipe(livereload(server));
});
gulp.task("html", () => {
return gulp.src("./app/**/*.html")
.pipe(gulp.dest(stagingDirectory))
.pipe(livereload(server));
});
gulp.task("copyPackageJson", () => {
return gulp.src("package.json")
.pipe(gulp.dest(stagingDirectory));
});
const run = require("gulp-run");
gulp.task("runNpmInstall", gulp.series("copyPackageJson", () => {
return run("npm install --production", { cwd: stagingDirectory}).exec();
}));
gulp.task("manifest", () => {
return gulp.src("./app/manifest.json")
.pipe(gulp.dest(stagingDirectory));
});
gulp.task("code", ["js", "sass", "index", "html", "runNpmInstall", "images", "manifest"])
gulp.task('generate-service-worker', gulp.series("code", () => {
return workbox.generateSW({
globDirectory: stagingDirectory,
globPatterns: ["**\/*.{html,js,css,jpg}"],
swDest: `${stagingDirectory}/sw.js`,
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: new RegExp('https://fonts.googleapis.com'),
handler: 'staleWhileRevalidate'
}, {
urlPattern: new RegExp("https://fonts.gstatic.com"),
handler: 'staleWhileRevalidate'
},
{
urlPattern: new RegExp("\/"),
handler: 'staleWhileRevalidate'
}
]
}).then(() => {
console.info('Service worker generation completed.');
}).catch((error) => {
console.warn('Service worker generation failed: ' + error);
});
}));
gulp.task("noJekyll", gulp.series("generate-service-worker", async () => {
const path = require("path");
const fs = require("fs");
new Promise(res =>
fs.writeFile(path.join(stagingDirectory, ".nojekyll"), "",
() => res()));
}));
gulp.task("default", gulp.series("noJekyll"));