-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
gulpfile.js
86 lines (72 loc) · 3.43 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
'use strict';
var gulp = require('gulp');
var lint = require('gulp-eslint');
var merge = require('merge-stream');
var merge_json = require('gulp-merge-json');
var webpack = require('webpack-stream');
var zip = require('gulp-zip');
function assets(browser) {
return function() {
var bootstrap = gulp.src('node_modules/chrome-bootstrap/chrome-bootstrap.css')
.pipe(gulp.dest('./build/' + browser + '/css'));
var assets = gulp.src(['*.html', 'icons/**/*', 'css/**/*', '_locales/**/*'], {base:"."})
.pipe(gulp.dest('./build/' + browser));
return merge(assets, bootstrap);
}
}
function manifest(browser) {
return function() {
return gulp.src(['./vendor/common/manifest.json', './vendor/' + browser + '/manifest.json'])
.pipe(merge_json('manifest.json'))
.pipe(gulp.dest('./build/' + browser));
}
}
function build(browser, watch) {
return function() {
var streams = ['option', 'extension', 'popin'].map(function(file) {
return gulp.src('js/' + file + '.js')
.pipe(webpack({
watch: watch,
output: { filename: file + '.js' }
}))
.on('error', function handleError() {
this.emit('end'); // Recover from errors
})
.pipe(gulp.dest('./build/' + browser + '/js'));
});
return merge(streams[0], streams[1], streams[2]);
}
}
function dist(browser) {
return function() {
var m = require('./build/' + browser + '/manifest');
var ext = browser == 'firefox' ? 'xpi' : 'zip';
return gulp.src('./build/' + browser + '/**/*')
.pipe(zip(browser + '-multipass-' + m.version + '.' + ext))
.pipe(gulp.dest('./dist'));
}
}
gulp.task('lint', function() {
return gulp.src(['js/**.js', 'vendor/**.js'])
.pipe(lint())
.pipe(lint.format())
.pipe(lint.failAfterError());
});
gulp.task('assets-firefox', gulp.series(assets('firefox')));
gulp.task('assets-chrome', gulp.series(assets('chrome')));
gulp.task('assets-opera', gulp.series(assets('opera')));
gulp.task('manifest-firefox', gulp.series(manifest('firefox')));
gulp.task('manifest-chrome', gulp.series(manifest('chrome')));
gulp.task('manifest-opera', gulp.series(manifest('opera')));
gulp.task('build-firefox', gulp.series('lint', 'assets-firefox', 'manifest-firefox', build('firefox', false)));
gulp.task('build-chrome', gulp.series('lint', 'assets-chrome', 'manifest-chrome', build('chrome', false)));
gulp.task('build-opera', gulp.series('lint', 'assets-opera', 'manifest-opera', build('opera', false)));
gulp.task('build', gulp.series('build-firefox', 'build-chrome', 'build-opera'));
gulp.task('watch-firefox', gulp.series('assets-firefox', 'manifest-firefox', build('firefox', true)));
gulp.task('watch-chrome', gulp.series('assets-chrome', 'manifest-chrome', build('chrome', true)));
gulp.task('watch-opera', gulp.series('assets-opera', 'manifest-opera', build('opera', true)));
gulp.task('watch', gulp.series('watch-firefox', 'watch-chrome', 'watch-opera'));
gulp.task('dist-firefox', gulp.series('build-firefox', dist('firefox')));
gulp.task('dist-chrome', gulp.series('build-chrome', dist('chrome')));
gulp.task('dist-opera', gulp.series('build-opera', dist('opera')));
gulp.task('dist', gulp.series('dist-firefox', 'dist-chrome', 'dist-opera'));