-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
222 lines (196 loc) · 5.4 KB
/
Copy pathgulpfile.babel.js
File metadata and controls
222 lines (196 loc) · 5.4 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// generated on 2017-03-05 using generator-chrome-extension 0.6.1
import gulp from 'gulp';
import gutil from 'gulp-util';
import gulpLoadPlugins from 'gulp-load-plugins';
import del from 'del';
import runSequence from 'run-sequence';
import {stream as wiredep} from 'wiredep';
import webpack from 'webpack';
import gulpWebpack from 'webpack-stream';
import WebpackDevServer from 'webpack-dev-server';
import webpackProdConfig from './webpack/webpack.prod';
import webpackDevConfig from './webpack/webpack.dev';
const $ = gulpLoadPlugins();
/**
* Moves extras to dest
* @param {string} dest destination directory
* @return {object} a gulp pipable object
*/
function extras(dest) {
return gulp.src([
'app/*.*',
'app/_locales/**',
'!app/scripts.babel',
'!app/*.json',
'!app/*.html',
], {
base: 'app',
dot: true,
}).pipe(gulp.dest(dest));
}
gulp.task('extras', () => extras('dist'));
gulp.task('extras:dev', () => extras('temp'));
/**
* Moves extras to dest
* @param {string} files files to lint
* @param {string} options lint options
* @return {object} a gulp pipable object
*/
function lint(files, options) {
return () => {
return gulp.src(files)
.pipe($.eslint(options))
.pipe($.eslint.format());
};
}
gulp.task('lint', lint('app/scripts.babel/**/*.js', {
env: {
es6: true,
},
}));
/**
* Processes images
* @param {string} dest destination directory
* @return {object} a gulp pipable object
*/
function images(dest) {
{
return gulp.src('app/images/**/*')
.pipe($.if($.if.isFile, $.cache($.imagemin({
progressive: true,
interlaced: true,
// don't remove IDs from SVGs, they are often used
// as hooks for embedding and styling
svgoPlugins: [{cleanupIDs: false}],
}))
.on('error', function(err) {
console.log(err);
this.end();
})))
.pipe(gulp.dest(`${dest}/images`));
}
}
gulp.task('images', () => images('dist'));
gulp.task('images:dev', () => images('temp'));
/* Deprecated */
gulp.task('html', () => {
return gulp.src('app/*.html')
.pipe($.useref({searchPath: ['temp', 'app', '.']}))
.pipe($.sourcemaps.init())
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', $.cleanCss({compatibility: '*'})))
.pipe($.sourcemaps.write())
.pipe($.if('*.html',
$.htmlmin({removeComments: true, collapseWhitespace: true})))
.pipe(gulp.dest('dist'));
});
/* Deprecated */
gulp.task('chromeManifest', () => {
return gulp.src('app/manifest.json')
.pipe($.chromeManifest({
buildnumber: true,
background: {
target: 'scripts/background.js',
exclude: [
'scripts/chromereload.js',
],
},
}))
.pipe($.if('*.css', $.cleanCss({compatibility: '*'})))
.pipe($.if('*.js', $.sourcemaps.init()))
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.js', $.sourcemaps.write('.')))
.pipe(gulp.dest('dist'));
});
gulp.task('clean', del.bind(null, ['temp', 'dist']));
/* Deprecated */
gulp.task('size', () => {
return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
});
/* Deprecated */
gulp.task('wiredep', () => {
gulp.src('app/*.html')
.pipe(wiredep({
ignorePath: /^(\.\.\/)*\.\./,
}))
.pipe(gulp.dest('app'));
});
gulp.task('package', function() {
let manifest = require('./dist/manifest.json');
return gulp.src('dist/**')
.pipe($.zip('gitscore-' + manifest.version + '.zip'))
.pipe(gulp.dest('package'));
});
/**
* Webpack tasks
*/
gulp.task('webpack:dist', function() {
return gulp.src(webpackProdConfig.entry.background)
.pipe(gulpWebpack(webpackProdConfig, webpack))
.pipe(gulp.dest(webpackProdConfig.output.path));
});
gulp.task('webpack:dev', function() {
return gulp.src(webpackDevConfig.entry.background)
.pipe(gulpWebpack(webpackDevConfig, webpack))
.pipe(gulp.dest(webpackDevConfig.output.path));
});
gulp.task('build', (cb) => {
runSequence(
'lint', 'clean', 'copy-manifest', 'webpack:dist',
['images', 'extras'],
'size', cb);
});
gulp.task('build:dev', (cb) => {
runSequence(
'lint', 'clean', 'copy-manifest:dev', 'webpack:dev',
['images:dev', 'extras:dev'],
'size', cb);
});
gulp.task('copy-manifest', function() {
return gulp.src('app/manifest.json')
.pipe(gulp.dest('dist'));
});
gulp.task('copy-manifest:dev', function() {
return gulp.src('app/manifest.json')
.pipe(gulp.dest('temp'));
});
gulp.task('webpack-dev-server', function(callback) {
const myConfig = {
hot: true,
quiet: false,
noInfo: false,
stats: {
colors: true,
chunks: false,
},
};
// Start a webpack-dev-server
new WebpackDevServer(webpack(webpackDevConfig), myConfig
).listen(8080, 'localhost', function(err) {
if (err) throw new gutil.PluginError('webpack-dev-server', err);
gutil.log('[webpack-dev-server]', 'http://localhost:8080/webpack-dev-server/index.html');
});
});
gulp.task('watch', () => {
return gulp.watch([
'app/*.html',
'app/scripts.babel/**/*.js',
'app/scripts.babel/**/*.css',
'app/images/**/*',
'app/styles/**/*',
'app/_locales/**/*.json',
], ['build:dev']);
});
gulp.task('serve', (cb) => {
runSequence(
'lint', 'clean', 'copy-manifest:dev',
['images:dev', 'extras:dev'],
'webpack-dev-server', 'watch',
cb);
});
gulp.task('size', () => {
return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
});
gulp.task('default', ['clean'], (cb) => {
runSequence('build', cb);
});