-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
146 lines (124 loc) · 2.99 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
135
136
137
138
139
140
141
142
143
144
145
146
'use strict';
let gulp = require('gulp');
let $ = require('gulp-load-plugins')();
let del = require('del');
let runSequence = require('run-sequence');
let browserify = require('browserify');
let source = require('vinyl-source-stream');
let buffer = require('vinyl-buffer');
let browserSync = require('browser-sync').create();
let reload = browserSync.reload;
let secret = require('./secret');
function replaceSecret(stream) {
return stream
.pipe($.replace(/@@clientId/g, secret.clientId))
.pipe($.replace(/@@clientSecret/g, secret.clientSecret))
.pipe($.replace(/@@basePath/g, secret.basePath));
}
gulp.task('vulcanize', () => {
let stream = gulp.src('dist/elements/elements.html')
.pipe($.vulcanize({
stripComments: true,
inlineCss: true,
inlineScripts: true
}));
return replaceSecret(stream)
.pipe($.crisper())
.pipe($.size())
.pipe(gulp.dest('dist/elements'));
});
gulp.task('html', () => {
return replaceSecret(gulp.src('app/index.html'))
.pipe($.size())
.pipe(gulp.dest('.tmp/'));
});
gulp.task('html:dist', ['html'], () => {
return gulp.src('.tmp/index.html')
.pipe($.htmlmin({
removeComments: true,
collapseWhitespace: true,
conservativeCollapse: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeIgnored: true,
minifyJS: true,
minifyCSS: true
}))
.pipe($.size())
.pipe(gulp.dest('dist'));
})
gulp.task('clean', () => {
return del(['dist', '.tmp']);
});
gulp.task('copy:bower', () => {
return gulp.src([
'app/bower_components/**/*'
])
.pipe($.size())
.pipe(gulp.dest('dist/bower_components'));
});
gulp.task('copy:elements', () => {
return replaceSecret(gulp.src([
'app/elements/**/*',
'!app/elements/app.js'
]))
.pipe($.size())
.pipe(gulp.dest('dist/elements'));
});
gulp.task('copy:tmp', () => {
return gulp.src(['.tmp/**/*'])
.pipe($.size())
.pipe(gulp.dest('dist/'));
});
gulp.task('browserify', () => {
let b = browserify({
entries: 'app/elements/app.js'
});
let stream = b.bundle()
.pipe(source('app.js'))
.pipe(buffer());
return replaceSecret(stream)
.pipe($.size())
.pipe(gulp.dest('.tmp/elements'));
});
gulp.task('serve', ['html', 'browserify'], () => {
browserSync.init({
server: {
baseDir: ['.tmp', 'app'],
routes: {
'/bower_components': 'app/bower_components'
}
},
port: 3000
});
gulp.watch('app/index.html', ['html', reload]);
gulp.watch('app/elements/**/*.js', ['browserify', reload]);
});
gulp.task('serve:dist', ['default'], () => {
browserSync.init({
server: {
baseDir: ['dist']
}
});
});
gulp.task('default', cb => {
return runSequence(
'clean',
['browserify'],
['copy:bower', 'copy:elements', 'copy:tmp', 'html:dist'],
['vulcanize'],
cb
);
});
gulp.task('push', () => {
return gulp.src('./dist/**/*')
.pipe($.ghPages());
});
gulp.task('deploy', cb => {
secret.basePath = '/lunar-event';
return runSequence(
'default',
'push',
cb
);
});