-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
77 lines (67 loc) · 2.21 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
const gulp = require('gulp');
const connect = require('gulp-connect');
const copy = require('gulp-copy');
const del = require('del');
const ghPages = require('gh-pages');
const path = require('path');
const swPrecache = require('sw-precache');
const runSequence = require('run-sequence');
const DEV_DIR = 'app';
const DIST_DIR = 'dist';
function getAssets(rootDir) {
return [
rootDir + '/manifest.json',
rootDir + '/**.html',
rootDir + '/assets/**.css',
rootDir + '/assets/**.js',
rootDir + '/assets/images/**',
rootDir + '/assets/lib/dialog-polyfill/dialog-polyfill.css',
rootDir + '/assets/lib/dialog-polyfill/dialog-polyfill.js',
rootDir + '/assets/lib/material-design-lite/material.min.css',
rootDir + '/assets/lib/material-design-lite/material.min.js',
rootDir + '/assets/lib/clipboard/dist/clipboard.min.js',
rootDir + '/assets/lib/jsqrcode/src/**.js'
];
}
function serve(rootDir) {
connect.server({
root: rootDir
});
}
function writeServiceWorkerFile(rootDir, handleFetch) {
swPrecache.write(path.join(rootDir, 'service-worker.js'), {
handleFetch: handleFetch,
staticFileGlobs: getAssets(rootDir),
stripPrefix: rootDir + '/'
});
}
gulp.task('default', ['dev']);
gulp.task('dev', ['serve-dev']);
gulp.task('serve-dev', ['build-dev'], function() {
serve(DEV_DIR);
});
gulp.task('build-dev', ['generate-service-worker-dev']);
gulp.task('prod', ['clean', 'serve-dist']);
gulp.task('clean', function() {
del.sync([DIST_DIR]);
});
gulp.task('serve-dist', ['build-dist'], function() {
serve(DIST_DIR);
});
gulp.task('build-dist', function() {
runSequence('copy-dev-to-dist', 'generate-service-worker-dist');
});
gulp.task('copy-dev-to-dist', function() {
return gulp.src(getAssets(DEV_DIR))
.pipe(copy(DIST_DIR, {prefix: 1}))
.pipe(gulp.dest(DIST_DIR));
});
gulp.task('generate-service-worker-dev', function() {
writeServiceWorkerFile(DEV_DIR, false);
});
gulp.task('generate-service-worker-dist', function() {
writeServiceWorkerFile(DIST_DIR, true);
});
gulp.task('gh-pages', ['build-dist'], function() {
ghPages.publish(path.join(__dirname, DIST_DIR));
});